:root { --accent:#2563eb; --accent-light:#dbeafe; }
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: #eef1f5;
  color: #1f2937;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
header { background: #111827; color: #fff; padding: 12px 18px; display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
header h1 { font-size: 18px; margin: 0; font-weight: 600; }
header .sub { font-size: 12px; color: #9ca3af; }
header .version { background: #2563eb; color: #fff; font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 999px; letter-spacing: .4px; }
header .header-btn { margin-left: auto; background: #2563eb; color: #fff; border: 1px solid #2563eb; border-radius: 8px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
header .header-btn:hover { background: #1d4ed8; border-color: #1d4ed8; }
main { flex: 1; display: flex; min-height: 0; }
#toolbar {
  width: 252px; flex: 0 0 252px;
  background: #fff; border-right: 1px solid #e5e7eb;
  overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 12px;
}
.panel { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px; padding: 12px; }
.panel h2 { font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: #64748b; margin: 0 0 8px; font-weight: 700; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
button {
  background: #fff; border: 1px solid #cbd5e1; border-radius: 8px;
  padding: 7px 10px; font-size: 13px; cursor: pointer; color: #1f2937;
  transition: background .15s, border-color .15s;
}
button:hover { background: #f1f5f9; border-color: #94a3b8; }
button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
button.active:hover { background: #1d4ed8; }
#palette { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.palette-item { border: 2px solid #e2e8f0; border-radius: 8px; padding: 6px; text-align: center; cursor: pointer; background: #fff; }
.palette-item canvas { display: block; margin: 0 auto 4px; width: 52px; height: 52px; }
.palette-item span { font-size: 11px; color: #475569; }
.palette-item.active { border-color: var(--accent); background: var(--accent-light); }
#preview { display: block; margin: 8px auto 0; width: 60px; height: 60px; background: #fff; border: 1px solid #e2e8f0; border-radius: 6px; }
#rotLabel { font-size: 12px; color: #64748b; min-width: 32px; text-align: center; }
.hint { font-size: 11px; color: #94a3b8; margin: 8px 0 0; line-height: 1.5; }
.chk { font-size: 12px; color: #475569; display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.chk input { width: auto; margin: 0; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid-3 button, .grid-2 button { padding: 7px 4px; font-size: 12px; }
label { font-size: 12px; color: #475569; display: flex; align-items: center; gap: 6px; }
input[type=number] { width: 64px; padding: 6px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 13px; }
select { flex: 1; min-width: 0; padding: 6px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 12px; background: #fff; }
.help ul { list-style: none; padding: 0; margin: 0; font-size: 12px; color: #475569; }
.counter { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.cnt { display: flex; align-items: center; gap: 8px; color: #475569; }
.cnt b { margin-left: auto; font-size: 13px; color: #1f2937; min-width: 22px; text-align: right; font-variant-numeric: tabular-nums; }
.sw { width: 14px; height: 14px; border-radius: 3px; flex: 0 0 14px; display: inline-block; }
.sw-centro { background: #000000; border: 1px solid #BFBFBF; }
.sw-lateral { background: #808080; }
.sw-terminal { background: #dc2626; }
.sw-curva { background: #f43f5e; }
.cnt.total { border-top: 1px solid #e2e8f0; padding-top: 5px; font-weight: 600; }
.help li { padding: 2px 0; }
.help b { display: inline-block; min-width: 54px; color: #1f2937; }
#boardWrap {
  flex: 1; overflow: auto; padding: 24px;
  background-image: radial-gradient(circle, #dfe4ea 1px, transparent 1px);
  background-size: 20px 20px;
}
#board { display: block; background: #fff; box-shadow: 0 4px 16px rgba(15,23,42,.18); }
footer { flex: 0 0 auto; background: #111827; color: #9ca3af; font-size: 12px; padding: 8px 18px; }

#board { user-select: none; -webkit-user-select: none; touch-action: none; cursor: crosshair; }
#previewOverlay { position: fixed; inset: 0; background: rgba(15,23,42,.78); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 24px; }
#previewOverlay[hidden] { display: none; }
.preview-box { position: relative; background: #fff; border-radius: 10px; padding: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.5); display: flex; flex-direction: column; align-items: center; gap: 8px; max-width: 94vw; max-height: 92vh; }
#previewCanvas { display: block; background: #fff; border-radius: 4px; }
.preview-caption { font-size: 12px; color: #475569; }
#previewClose { position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; padding: 0; border-radius: 999px; font-size: 14px; line-height: 1; }
