/* ============================================================
   Crossword Maker — ink & paper, one amber highlighter accent
   ============================================================ */

:root {
  --paper:      #faf9f6;
  --panel:      #ffffff;
  --ink:        #17171b;
  --graphite:   #5a5a62;
  --faint:      #8f8f97;
  --line:       #e4e2da;
  --line-strong:#c9c7bd;

  --amber:      #f2b705;   /* active-entry highlighter */
  --amber-wash: #fdeeba;   /* soft wash over the active word */
  --amber-deep: #b9860a;
  --pen:        #d64545;   /* wrong cell — the solver's red pen */
  --good:       #2f9e6b;

  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-body:    "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono:    "JetBrains Mono", "SFMono-Regular", Consolas, monospace;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(23,23,27,.05), 0 8px 24px -12px rgba(23,23,27,.18);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 100% 0%, #fffdf6 0%, var(--paper) 55%) fixed;
  line-height: 1.5;
  min-height: 100vh;
}

/* -------------------------------------------------- header */
.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding: 26px clamp(18px, 4vw, 48px) 18px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.5rem, 3.4vw, 2.1rem);
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1;
}
.brand-sub {
  font-weight: 600;
  color: var(--amber-deep);
  margin-left: .35em;
  font-size: .62em;
  letter-spacing: .02em;
  vertical-align: baseline;
}
/* tiny 2x2 grid mark that echoes the puzzle */
.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 11px);
  grid-template-rows: repeat(2, 11px);
  gap: 2px;
}
.brand-mark .sq { border-radius: 2px; }
.sq-1 { background: var(--ink); }
.sq-2 { background: var(--amber); }
.sq-3 { background: var(--line-strong); }
.sq-4 { background: var(--ink); }
.tagline {
  margin: 0;
  color: var(--graphite);
  font-size: .92rem;
  font-style: italic;
}

/* -------------------------------------------------- layout */
.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  gap: clamp(20px, 3vw, 40px);
  align-items: start;
  padding: clamp(20px, 3vw, 40px) clamp(18px, 4vw, 48px) 64px;
  max-width: 1240px;
  margin: 0 auto;
}

/* -------------------------------------------------- desk (input) */
.desk {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  position: sticky;
  top: 20px;
}
.field-label {
  display: block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.field-help {
  margin: 4px 0 12px;
  color: var(--graphite);
  font-size: .84rem;
}
.field-help code {
  font-family: var(--font-mono);
  font-size: .8em;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}
#wordInput {
  width: 100%;
  min-height: 240px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: .9rem;
  line-height: 1.65;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 12px 14px;
}
#wordInput:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-wash);
}
#wordInput::placeholder { color: var(--faint); }

.desk-actions { display: flex; gap: 10px; margin-top: 14px; }
.desk-meta { margin-top: 14px; }
.meta-line { margin: 2px 0; font-size: .84rem; color: var(--graphite); }
.meta-line:empty { display: none; }
.meta-warn { color: var(--amber-deep); font-weight: 500; }

/* -------------------------------------------------- buttons */
.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: .9rem;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--ink);
  padding: 10px 16px;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.btn:hover { border-color: var(--faint); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--amber-wash);
  border-color: var(--amber);
}
.btn-primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
  flex: 1;
}
.btn-primary:hover { background: #000; border-color: #000; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 7px 12px; font-size: .82rem; }

.board-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.divider {
  width: 1px;
  height: 22px;
  background: var(--line);
  margin: 0 2px;
}
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .82rem;
  color: var(--graphite);
  cursor: pointer;
  user-select: none;
}
.toggle input { accent-color: var(--amber-deep); }
.file-btn { display: inline-flex; align-items: center; }

/* -------------------------------------------------- board */
.board {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px clamp(18px, 2.5vw, 28px) 26px;
  min-width: 0;
}
.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}

/* signature: live proportion glyph + squareness readout */
.shape { display: flex; align-items: center; gap: 10px; }
.shape-glyph {
  display: inline-block;
  width: 22px;
  height: 22px;
  background: var(--amber-wash);
  border: 1.5px solid var(--amber-deep);
  border-radius: 3px;
  transition: width .3s ease, height .3s ease;
}
.shape-readout {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: .92rem;
  letter-spacing: .01em;
  color: var(--ink);
}

/* -------------------------------------------------- grid */
.grid-wrap {
  display: flex;
  justify-content: center;
  padding: 4px 0 6px;
}
.grid {
  display: grid;
  gap: 2px;
  background: var(--line-strong);
  padding: 2px;
  border-radius: 6px;
  width: min(90vw, 540px);
}
.grid.empty { display: none; }

.empty-state {
  color: var(--faint);
  font-size: .95rem;
  padding: 60px 0;
  text-align: center;
}
.empty-state.hidden { display: none; }

.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--panel);
  border-radius: 2px;
}
.cell.black {
  background: var(--ink);
}
.cell .num {
  position: absolute;
  top: 1px;
  left: 2px;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: clamp(7px, 1.4vw, 10px);
  line-height: 1;
  color: var(--graphite);
  pointer-events: none;
  z-index: 2;
}
.cell input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  text-align: center;
  text-transform: uppercase;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: clamp(13px, 2.6vw, 22px);
  color: var(--ink);
  caret-color: var(--amber-deep);
  padding: 0;
}
.cell input:focus { outline: none; }

.cell.active-word { background: var(--amber-wash); }
.cell.active-cell {
  background: var(--amber);
  box-shadow: inset 0 0 0 2px var(--amber-deep);
}
.cell.wrong input { color: var(--pen); }
.cell.wrong { background: #fbe4e4; }
.cell.correct input { color: var(--good); }

/* -------------------------------------------------- messages */
.message {
  min-height: 1.2em;
  margin: 14px 2px 0;
  font-size: .9rem;
  font-weight: 500;
}
.message.ok { color: var(--good); }
.message.warn { color: var(--amber-deep); }
.message:empty { display: none; }

/* -------------------------------------------------- clues */
.clues {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.clue-head {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  margin: 0 0 10px;
  color: var(--ink);
}
.clue-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.clue {
  display: flex;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: .88rem;
  color: var(--graphite);
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.clue:hover { background: var(--paper); color: var(--ink); }
.clue .clue-num {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--ink);
  min-width: 1.4em;
  text-align: right;
  flex-shrink: 0;
}
.clue.active {
  background: var(--amber-wash);
  color: var(--ink);
}
.clue.active .clue-num { color: var(--amber-deep); }

/* -------------------------------------------------- responsive */
@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; }
  .desk { position: static; }
}
@media (max-width: 520px) {
  .clues { grid-template-columns: 1fr; gap: 18px; }
  .board-actions { gap: 6px; }
}

/* -------------------------------------------------- motion */
.cell.animate-in {
  animation: cellIn .32s ease both;
}
@keyframes cellIn {
  from { opacity: 0; transform: scale(.82); }
  to   { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* -------------------------------------------------- print */
@media print {
  :root { --shadow: none; }
  html, body { background: #fff; }
  .site-header .tagline,
  .brand-mark,
  .no-print,
  .desk,
  .empty-state,
  .message { display: none !important; }
  .workspace {
    display: block;
    padding: 0;
    max-width: none;
  }
  .board {
    border: none;
    box-shadow: none;
    padding: 0;
  }
  .board-head { border: none; margin-bottom: 12px; justify-content: flex-start; }
  .grid-wrap { justify-content: flex-start; padding: 0; }
  .grid {
    width: min(6.5in, 100%);
    gap: 0;
    padding: 0;
    background: #fff;
    border-radius: 0;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  /* borders always print (unlike backgrounds) — every cell gets a real box */
  .cell {
    border: 1px solid #000;
    background: #fff !important;
    border-radius: 0;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  /* blocked cells: leave blank on paper — only answer cells get boxes */
  .cell.black { background: transparent !important; border: none; }
  .cell.active-word,
  .cell.active-cell { background: #fff !important; box-shadow: none; }
  .cell .num { color: #000; }
  .cell input { color: #000 !important; }   /* answers print in black, not green */
  /* "Blank": hide typed answers on paper without touching the screen */
  body.print-blank .cell input { color: transparent !important; }
  .clues { break-inside: avoid; }
  .clue { color: #000; break-inside: avoid; }
  .clue .clue-num { color: #000; }
  .clue.active { background: transparent; }
}
