*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root { --cell: 80px; }

html, body { width: 100%; height: 100%; overflow: hidden; background: #1a1210; color: #d4c5a9; font-family: serif; }

/* ── Zone layout ─────────────────────────────────────────────────────────── */

#app {
  display: flex;
  flex-direction: row;
  height: 100vh;
  padding: 6px;
  gap: 6px;
  overflow: hidden;
}

/* Right panel: clue area + option bar */
#right-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
}

/* Panel title */
#panel-header {
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc((var(--cell) * 0.44 + 8px) * 0.75);
  flex-shrink: 0;
  font-family: serif;
  font-size: 1.5rem;
  font-variant: small-caps;
  letter-spacing: 0.18em;
  color: #c8a84b;
  text-shadow: 0 1px 4px #000a;
  border-bottom: 1px solid #4a3728;
}

/* Message area */
#message-area {
  min-height: calc(var(--cell) * 0.44 + 8px);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 10px;
  border-top: 1px solid #3a2c1e;
  font-family: serif;
  font-size: 1.3rem;
  color: #c8a84b;
  font-style: italic;
}

#message-area.timer-active {
  font-size: 1.3rem;
  font-style: normal;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  color: #c8a84b;
}

/* Clue area: tab bar + tab panes */
#clue-area {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Manila folder tabs ──────────────────────────────────────────────────── */

#tab-bar {
  display: flex;
  gap: 3px;
  padding: 0 4px;
  flex-shrink: 0;
}

.tab {
  padding: 4px 20px 6px;
  border: 1px solid #4a3728;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  cursor: pointer;
  font-family: serif;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  color: #6a5a40;
  background: #1e150d;
  position: relative;
  top: 1px;
  user-select: none;
}

.tab--active {
  background: #2a1f1a;
  color: #d4b870;
  border-color: #6a5228;
  border-bottom: 1px solid #2a1f1a;
  z-index: 2;
}

.tab:not(.tab--active):hover { color: #a08860; }

.tab--has-hint::after {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4caf50;
  margin-left: 6px;
  vertical-align: middle;
  position: relative;
  top: -1px;
  box-shadow: 0 0 4px #4caf5099;
}

/* Tab panes */
.tab-pane {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #4a3728;
  border-top-color: #6a5228;
}

.tab-pane--active {
  display: flex;
}

/* Vertical clues — single scrolling row inside clues pane */
#vertical-clues {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
  padding: 4px 4px 4px;
  border-top: 1px solid #3a2c1e;
  margin-top: 2px;
}
#vertical-clues::-webkit-scrollbar { height: 4px; }
#vertical-clues::-webkit-scrollbar-thumb { background: #4a3728; border-radius: 2px; }

/* Option bar */
#option-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

/* ── Zone 1: Game Board ──────────────────────────────────────────────────── */

#grid {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex-shrink: 0;
  align-self: flex-start;
  background: #c8a84b;
}

.grid-row {
  display: flex;
  gap: 1px;
  background: #c8a84b;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  background: #2a1f1a;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 0;
  padding: 0;
  flex-shrink: 0;
}

.cell--solved {
  background: #1a2a1a;
  box-shadow: inset 0 0 0 2px #4a7a4a;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell--solved .candidate { display: none; }
.cell--solved .candidate:not(.candidate--eliminated) {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.cell--highlighted { box-shadow: inset 0 0 0 2px #4ae0e0 !important; }
.cell--wrong { box-shadow: inset 0 0 0 3px #c0392b !important; }

.candidate { width: 100%; height: 100%; object-fit: contain; cursor: pointer; opacity: 0.85; }
.candidate--eliminated { opacity: 0.1; cursor: default; }
.candidate--confirmed { outline: 2px solid #c8a84b; }
.candidate--hint { outline: 2px solid #c84a4a; animation: hint-pulse 0.7s ease-in-out infinite alternate; }
@keyframes hint-pulse { from { outline-color: #c84a4a; opacity: 1; } to { outline-color: #ff8888; opacity: 0.6; } }

/* ── Zone 2: Horizontal Clues ───────────────────────────────────────────── */

#horizontal-clues {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  align-content: start;
  overflow-y: auto;
  min-height: 0;
  min-width: 0;
  padding: 4px;
}
#horizontal-clues::-webkit-scrollbar { width: 4px; }
#horizontal-clues::-webkit-scrollbar-thumb { background: #4a3728; border-radius: 2px; }

/* Solved clues pane — flex-wrap for mixed h/v cards */
#solved-clues {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-content: start;
  overflow-y: auto;
  padding: 4px;
}
#solved-clues::-webkit-scrollbar { width: 4px; }
#solved-clues::-webkit-scrollbar-thumb { background: #4a3728; border-radius: 2px; }

/* ── Clue cards (shared) ────────────────────────────────────────────────── */

.clue-card {
  background: #2a1f1a;
  border: 1px solid #4a3728;
  cursor: grab;
  padding: 0;
  user-select: none;
  overflow: hidden;
}

.clue-card--vertical {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
}

.clue-card--horizontal {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0;
}

.clue-icon { width: calc(var(--cell) * 0.44); height: calc(var(--cell) * 0.44); object-fit: contain; }
.clue-icon--negated { opacity: 0.5; }


.clue-glyph { font-size: calc(var(--cell) * 0.12); color: #8a9aba; min-width: calc(var(--cell) * 0.34); text-align: center; }
.clue-glyph-tile {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.clue-glyph-label {
  position: absolute;
  color: #c8a84b;
  font-size: calc(var(--cell) * 0.25);
  font-weight: bold;
  letter-spacing: -0.05em;
  text-shadow: 1px 1px 2px #000, -1px -1px 2px #000;
  pointer-events: none;
}
.clue-glyph-label--fill { font-size: calc(var(--cell) * 0.40); }

.clue-icon-neg {
  position: relative;
  display: inline-flex;
}
.clue-icon-neg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom left,
    transparent calc(50% - 1px),
    #c84a4a calc(50% - 1px),
    #c84a4a calc(50% + 1px),
    transparent calc(50% + 1px)
  );
  pointer-events: none;
}

.clue--highlighted { border-color: #4ae0e0 !important; box-shadow: 0 0 4px #4ae0e066; }
.clue--hint-source { border-color: #c84a4a !important; box-shadow: 0 0 6px #c84a4a88; }
.clue-card--dragging { opacity: 0.25; }
.clue-card--over { outline: 2px solid #4ae0e0; outline-offset: -2px; }

.clue-card--blank {
  background: #2a1f1a;
  border: 1px solid #4a3728;
  cursor: default;
  pointer-events: auto;
}
.clue-card--blank.clue-card--horizontal {
  width: calc(var(--cell) * 1.32);
  min-height: calc(var(--cell) * 0.44);
}
.clue-card--blank.clue-card--vertical {
  width: calc(var(--cell) * 0.44);
  height: calc(var(--cell) * 0.88);
  flex-shrink: 0;
}

/* ── Instructions pane ──────────────────────────────────────────────────── */

#inst-content {
  flex: 1;
  overflow: hidden;
  padding: 10px 14px;
  min-height: 0;
}

.inst-page { display: none; }
.inst-page--active { display: block; }

.inst-page h3 {
  color: #d4b870;
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 10px 0 4px;
  border-bottom: 1px solid #3a2c1e;
  padding-bottom: 3px;
}
.inst-page h3:first-child { margin-top: 0; }

.inst-page p {
  font-size: calc(0.9rem * var(--reading-scale, 1));
  line-height: 1.5;
  color: #b8a888;
  margin-bottom: 6px;
}

.inst-green { color: #4a7a4a; }
.inst-cyan  { color: #4ae0e0; }
.inst-muted { color: #6a5a40; font-size: calc(0.78rem * var(--reading-scale, 1)); }
.inst-tip   { color: #6a5a40; font-style: italic; margin-top: 8px; }

.inst-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  font-size: calc(0.80rem * var(--reading-scale, 1));
  margin-bottom: 6px;
}
.inst-dl dt { color: #d4c5a9; font-weight: bold; white-space: nowrap; }
.inst-dl dd { color: #b8a888; margin: 0; }

/* Clue type examples */
.inst-dl--clues { gap: 8px 10px; align-items: center; }
.inst-dl--clues dt { display: flex; align-items: center; }

.inst-card {
  display: inline-flex;
  align-items: center;
  background: #2a1f1a;
  border: 1px solid #4a3728;
  gap: 1px;
  padding: 2px;
}
.inst-card--v { flex-direction: column; }
.inst-card--h { flex-direction: row; }

.inst-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: #3a2c20;
  color: #d4b870;
  font-size: 0.70rem;
  font-weight: bold;
  font-style: normal;
  letter-spacing: -0.02em;
  position: relative;
}
.inst-icon.inst-neg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom left,
    transparent calc(50% - 1px),
    #c84a4a calc(50% - 1px),
    #c84a4a calc(50% + 1px),
    transparent calc(50% + 1px)
  );
  pointer-events: none;
}
.inst-glyph {
  font-size: 0.65rem;
  color: #8a9aba;
  padding: 0 2px;
  display: flex;
  align-items: center;
}
.inst-mid {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}
.inst-mid.inst-neg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom left,
    transparent calc(50% - 1px),
    #c84a4a calc(50% - 1px),
    #c84a4a calc(50% + 1px),
    transparent calc(50% + 1px)
  );
  pointer-events: none;
}

#inst-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 6px;
  border-top: 1px solid #3a2c1e;
  flex-shrink: 0;
}

#inst-prev, #inst-next {
  background: #3a2a1a;
  color: #d4c5a9;
  border: 1px solid #6a5a3a;
  padding: 3px 12px;
  cursor: pointer;
  font-family: serif;
  font-size: 0.8rem;
}
#inst-prev:hover:not(:disabled), #inst-next:hover:not(:disabled) { background: #4a3a2a; }
#inst-prev:disabled, #inst-next:disabled { opacity: 0.35; cursor: default; }

#inst-page-num {
  font-size: 0.78rem;
  color: #6a5a40;
  font-family: serif;
  letter-spacing: 0.05em;
  min-width: 36px;
  text-align: center;
}

/* ── The Tiles pane ─────────────────────────────────────────────────────── */

#tiles-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 6px 6px 4px;
  flex-shrink: 0;
  border-bottom: 1px solid #3a2c1e;
}

.tile-cat-btn {
  background: #2a1f1a;
  color: #6a5a40;
  border: 1px solid #4a3728;
  padding: 3px 10px;
  cursor: pointer;
  font-family: serif;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
}
.tile-cat-btn--active {
  background: #3a2a1a;
  color: #d4b870;
  border-color: #6a5228;
}
.tile-cat-btn:not(.tile-cat-btn--active):hover { color: #a08860; }

#tiles-content {
  flex: 1;
  overflow-y: auto;
  padding: 4px 6px;
  min-height: 0;
}
#tiles-content::-webkit-scrollbar { width: 4px; }
#tiles-content::-webkit-scrollbar-thumb { background: #4a3728; border-radius: 2px; }

.tiles-section { display: none; flex-direction: column; gap: 4px; }
.tiles-section--active { display: flex; }

.tile-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 4px;
  border-bottom: 1px solid #2e2018;
}
.tile-entry:last-child { border-bottom: none; }

.tile-entry img {
  width: calc(var(--cell) * 0.5);
  height: calc(var(--cell) * 0.5);
  object-fit: contain;
  flex-shrink: 0;
}

.tile-name {
  color: #d4b870;
  font-size: calc(0.85rem * var(--reading-scale, 1));
  font-weight: bold;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.tile-bio {
  color: #7a6a50;
  font-size: calc(0.80rem * var(--reading-scale, 1));
  line-height: 1.5;
  font-style: italic;
}

/* ── Zone 4: Option Bar ─────────────────────────────────────────────────── */

#new-game {
  background: #3a2a1a;
  color: #d4c5a9;
  border: 1px solid #6a5a3a;
  padding: 0.35rem 1.5rem;
  cursor: pointer;
  font-family: serif;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
}
#new-game:hover { background: #4a3a2a; }

#undo {
  background: #3a2a1a;
  color: #d4c5a9;
  border: 1px solid #6a5a3a;
  padding: 0.35rem 1.5rem;
  cursor: pointer;
  font-family: serif;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
}
#undo:hover:not(:disabled) { background: #4a3a2a; }
#undo:disabled { opacity: 0.35; cursor: default; }

#hint {
  background: #3a2a1a;
  color: #d4c5a9;
  border: 1px solid #6a5a3a;
  padding: 0.35rem 1.5rem;
  cursor: pointer;
  font-family: serif;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
}
#hint:hover { background: #4a3a2a; }

#reveal {
  background: #3a1a1a;
  color: #e8a0a0;
  border: 1px solid #8a3a3a;
  padding: 0.35rem 1.5rem;
  cursor: pointer;
  font-family: serif;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
}
#reveal:hover { background: #5a2020; }

#font-ctrl {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 2px;
}

#font-dec, #font-inc {
  background: #3a2a1a;
  color: #d4c5a9;
  border: 1px solid #6a5a3a;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font-family: serif;
  font-size: 0.95rem;
  line-height: 1;
}
#font-dec:hover:not(:disabled), #font-inc:hover:not(:disabled) { background: #4a3a2a; }
#font-dec:disabled, #font-inc:disabled { opacity: 0.35; cursor: default; }

#font-label {
  background: #2a1f1a;
  color: #c8a84b;
  border: 1px solid #6a5a3a;
  border-left: none;
  border-right: none;
  padding: 0.35rem 0.5rem;
  font-family: serif;
  font-size: 0.85rem;
  font-weight: bold;
  letter-spacing: 0.05em;
  user-select: none;
}
