/* Dark is the jimbot.cc default; html.light is the parchment theme.
   The board itself stays wooden in both — it is a wooden puzzle. */
:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #ece3d3;
  --muted: #a79c8a;
  --eyebrow: #e2a851;
  --status: #f0e5d2;
  --legend-ink: #c7bdac;
  --page-bg: radial-gradient(circle at 15% 10%, rgba(120, 92, 56, .34), transparent 30rem),
             linear-gradient(140deg, #1b1a18, #262320);
  --chrome-bg: rgba(255, 255, 255, .07);
  --chrome-border: rgba(255, 255, 255, .16);
  --chrome-hover: rgba(255, 255, 255, .14);
  --field-bg: rgba(255, 255, 255, .09);
  --field-border: rgba(255, 255, 255, .2);
  --secondary-ink: #f2e7d4;
  --secondary-bg: rgba(255, 255, 255, .08);
  --secondary-border: rgba(255, 255, 255, .18);
  --cell: clamp(42px, 8.5vw, 78px);
  --gap: 0px;
}

html.light {
  color-scheme: light;
  --ink: #29251f;
  --muted: #71695d;
  --eyebrow: #76552f;
  --status: #4e402f;
  --legend-ink: #5f5548;
  --page-bg: radial-gradient(circle at 15% 10%, rgba(255, 255, 255, .9), transparent 28rem),
             linear-gradient(135deg, #e7dcc9, #cdbb9e);
  --chrome-bg: rgba(255, 255, 255, .55);
  --chrome-border: rgba(73, 55, 34, .22);
  --chrome-hover: rgba(255, 255, 255, .85);
  --field-bg: rgba(255, 255, 255, .7);
  --field-border: rgba(50, 40, 25, .25);
  --secondary-ink: #493722;
  --secondary-bg: rgba(255, 255, 255, .48);
  --secondary-border: rgba(73, 55, 34, .22);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--page-bg) fixed;
}

button, select, input { font: inherit; }

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: clamp(18px, 3vw, 34px) 0 clamp(28px, 5vw, 64px);
}

.app-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: clamp(14px, 2.5vw, 24px);
}
.app-bar #theme-toggle { margin-left: auto; }

.chrome-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--chrome-border);
  border-radius: 10px;
  background: var(--chrome-bg);
  color: var(--ink);
  font-size: 18px;
  text-decoration: none;
  box-shadow: none;
  cursor: pointer;
}
.chrome-button:hover { background: var(--chrome-hover); transform: none; }

.intro { max-width: 860px; }
.bottom-controls { margin-top: clamp(28px, 5vw, 54px); }
.top-status { display: flex; align-items: center; gap: 10px 18px; flex-wrap: wrap; margin-bottom: 14px; }
.top-status .status { flex: 1 1 auto; }
.top-status .actions { margin-top: 0; }
.eyebrow { margin: 0 0 6px; color: var(--eyebrow); font-weight: 800; letter-spacing: .18em; font-size: .8rem; }
h1 { margin: 0; font-family: Georgia, serif; font-size: clamp(2.2rem, 7vw, 4.8rem); line-height: .98; }
.lede { max-width: 680px; color: var(--muted); font-size: 1.08rem; line-height: 1.6; }

.date-controls { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; }
label { display: grid; gap: 6px; color: var(--muted); font-size: .82rem; font-weight: 750; text-transform: uppercase; letter-spacing: .08em; }
select, input {
  min-width: 112px;
  height: 46px;
  padding: 0 12px;
  border: 1px solid var(--field-border);
  border-radius: 10px;
  color: var(--ink);
  background: var(--field-bg);
}
button {
  height: 46px;
  padding: 0 19px;
  border: 0;
  border-radius: 10px;
  color: #fffaf0;
  background: #493722;
  font-weight: 750;
  cursor: pointer;
  box-shadow: 0 5px 14px rgba(66,45,24,.18);
}
button:hover { transform: translateY(-1px); }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid #f1a839; outline-offset: 2px; }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.secondary { height: 38px; color: var(--secondary-ink); background: var(--secondary-bg); box-shadow: none; border: 1px solid var(--secondary-border); }
.secondary:hover { background: var(--chrome-hover); }
.secondary:disabled { opacity: .4; cursor: default; transform: none; }
.status { min-height: 1.5em; margin: 0; color: var(--status); font-weight: 800; font-size: 1.05rem; }

.puzzle-area { display: flex; align-items: flex-start; gap: clamp(20px, 4vw, 52px); flex-wrap: wrap; }
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, var(--cell));
  grid-template-rows: repeat(7, var(--cell));
  gap: var(--gap);
  padding: clamp(12px, 2vw, 20px);
  border: 9px solid #a67c48;
  border-radius: 22px;
  background: #ead0a0;
  box-shadow: 0 22px 50px rgba(20,12,4,.45), inset 0 0 0 2px rgba(255,255,255,.32);
}
html.light .board { box-shadow: 0 22px 50px rgba(61,43,23,.26), inset 0 0 0 2px rgba(255,255,255,.32); }
.cell {
  position: relative;
  display: grid;
  place-items: center;
  border: 1px solid rgba(91,61,28,.28);
  border-radius: 0;
  overflow: hidden;
  background: #efd6a7;
  color: #6d4e2c;
  font-family: Georgia, serif;
  font-size: clamp(.82rem, 2.7vw, 1.32rem);
}
.cell.covered { border: 2px solid #35291d; color: transparent; }
.cell.covered::after {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 5px;
  pointer-events: none;
}
.cell.open { z-index: 0; }
.cell.target {
  z-index: 1;
  background: #fff5d8;
  color: #3d2b18;
  font-weight: 800;
  box-shadow: inset 0 0 0 3px #f6b83e, 0 0 18px rgba(246,184,62,.45);
}
.void { visibility: hidden; }

.legend { width: min(320px, 100%); padding-top: 6px; }
.legend h2 { margin: 0 0 14px; font-family: Georgia, serif; }
.legend-items { display: grid; grid-template-columns: repeat(2, minmax(112px, 1fr)); gap: 12px; }
.legend-item { display: flex; align-items: center; gap: 10px; min-height: 68px; color: var(--legend-ink); font-weight: 700; white-space: nowrap; }
.piece-preview { display: grid; place-items: center; width: 66px; height: 66px; flex: 0 0 66px; }
.piece-preview svg { display: block; width: 58px; height: 58px; overflow: visible; filter: drop-shadow(1.5px 0 #35291d) drop-shadow(-1.5px 0 #35291d) drop-shadow(0 1.5px #35291d) drop-shadow(0 -1.5px #35291d); }
.legend p { color: var(--muted); line-height: 1.5; font-size: .9rem; }

@media (max-width: 700px) {
  :root { --cell: calc((100vw - 66px) / 7); --gap: 0px; }
  .app-shell { width: min(100% - 16px, 620px); padding-top: 16px; }
  .board { border-width: 6px; padding: 8px; border-radius: 15px; }
  .date-controls label { flex: 1 1 100px; }
  .date-controls select, .date-controls input { width: 100%; min-width: 0; }
  .date-controls > button { flex: 1 0 100%; }
  .legend { width: 100%; }
}

@media (prefers-reduced-motion: no-preference) {
  .cell { transition: background-color .22s ease, transform .22s ease; }
  .cell.covered { animation: settle .28s both; animation-delay: calc(var(--order) * 18ms); }
  @keyframes settle { from { opacity: .2; transform: scale(.88); } }
}


/* ---------------------------------------------------------------------------
   Play mode
   --------------------------------------------------------------------------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

body[data-mode="play"] .solve-only { display: none !important; }
body[data-mode="solve"] .play-only { display: none !important; }

.mode-switch { display: inline-flex; border: 1px solid var(--chrome-border); border-radius: 10px; overflow: hidden; background: var(--chrome-bg); }
.mode-button {
  height: 38px; padding: 0 14px; border: 0; border-radius: 0; box-shadow: none;
  background: transparent; color: var(--ink); font-weight: 750; display: inline-flex; align-items: center; gap: 6px;
}
.mode-button:hover { background: var(--chrome-hover); transform: none; }
.mode-button[aria-pressed="true"] { background: #493722; color: #fffaf0; }
.set-picker select { height: 38px; min-width: 0; padding: 0 10px; border-radius: 10px; font-weight: 700; }
.app-bar .set-picker { margin-left: auto; }
.app-bar #theme-toggle { margin-left: 0; }

.board { touch-action: none; user-select: none; -webkit-user-select: none; }
.board .cell.covered { cursor: grab; }
.board .cell.covered.selected { z-index: 2; box-shadow: inset 0 0 0 3px #f6b83e, 0 0 16px rgba(246,184,62,.55); }
.board .cell.covered.selected::after { border-color: rgba(255,255,255,.7); }
body[data-mode="play"] .cell.covered { color: rgba(53,41,29,.28); font-size: clamp(.7rem, 2.2vw, 1rem); }

.ghost {
  z-index: 3; pointer-events: none;
  background: color-mix(in srgb, var(--piece-color) 55%, transparent);
  outline: 2px dashed rgba(255,255,255,.85); outline-offset: -3px;
}
.ghost.invalid { background: rgba(220, 50, 40, .55); outline-color: #ffd6d0; }
@supports not (background: color-mix(in srgb, red 50%, transparent)) {
  .ghost { background: var(--piece-color); opacity: .6; }
  .ghost.invalid { background: #dc3228; }
}

.board.solved { animation: solved-glow 1.2s ease-in-out 3; }
@keyframes solved-glow {
  50% { box-shadow: 0 0 0 6px rgba(246,184,62,.55), 0 22px 60px rgba(246,184,62,.35); }
}

/* Key / tray */
.legend h2 { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.set-subtitle { font-family: inherit; font-size: .8rem; font-weight: 700; color: var(--muted); letter-spacing: .04em; }
body[data-mode="play"] .legend-item {
  cursor: grab; border: 2px solid transparent; border-radius: 12px; padding: 4px 6px;
  touch-action: none; user-select: none; -webkit-user-select: none; min-height: 60px;
}
body[data-mode="play"] .legend-item:hover { background: var(--chrome-bg); }
body[data-mode="play"] .legend-item:focus-visible { outline: 3px solid #f1a839; outline-offset: 1px; }
body[data-mode="play"] .legend-item.selected { border-color: #f6b83e; background: var(--chrome-bg); }
body[data-mode="play"] .legend-item.placed { opacity: .45; }
body[data-mode="play"] .legend-item.placed .piece-label::after { content: " ✓"; }
.legend-item .piece-preview { flex: 0 0 52px; width: 52px; height: 52px; }
.legend-item .piece-preview svg { width: 48px; height: 48px; }

.orient-controls { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.orient-controls .secondary { height: 36px; padding: 0 12px; display: inline-flex; align-items: center; gap: 4px; }
.legend-note { color: var(--muted); line-height: 1.5; font-size: .9rem; }

.help { margin-top: 18px; max-width: 680px; color: var(--muted); font-size: .92rem; line-height: 1.55; }
.help summary { cursor: pointer; color: var(--ink); font-weight: 700; }
.help ul { padding-left: 1.2em; margin: 8px 0 0; }
.help li + li { margin-top: 4px; }

.top-status .actions .secondary { display: inline-flex; align-items: center; gap: 5px; }

@media (max-width: 700px) {
  .app-bar { gap: 6px; }
  .app-bar .set-picker { margin-left: auto; flex: 0 1 auto; min-width: 0; }
  .set-picker select { width: 100%; padding: 0 4px; font-size: .85rem; }
  .mode-button { padding: 0 8px; font-size: .9rem; }
  .top-status .actions { width: 100%; }
  .top-status .actions .secondary { flex: 1 1 auto; justify-content: center; padding: 0 8px; }
  /* Phone: the key collapses to a scrolling strip of unplaced pieces. */
  body[data-mode="play"] .legend h2, body[data-mode="play"] .legend-note { display: none; }
  body[data-mode="play"] .legend-items {
    display: flex; gap: 6px; overflow-x: auto; padding: 6px 2px; scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }
  body[data-mode="play"] .legend-item { flex: 0 0 auto; flex-direction: column; gap: 2px; min-height: 0; padding: 4px; }
  body[data-mode="play"] .legend-item.placed { display: none; }
  body[data-mode="play"] .legend-item .piece-preview { flex-basis: 46px; width: 46px; height: 46px; }
  body[data-mode="play"] .legend-item .piece-preview svg { width: 42px; height: 42px; }
  body[data-mode="play"] .legend-item .piece-label { font-size: .72rem; }
  .orient-controls { justify-content: space-between; }
  .orient-controls .secondary { flex: 1 1 0; padding: 0 6px; }
  .orient-controls .label { display: none; }
}
