:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #657186;
  --panel: #ffffff;
  --line: #d8dee9;
  --field: #f4f7fb;
  --blue: #2b6cb0;
  --teal: #0f766e;
  --coral: #c2410c;
  --gold: #b7791f;
  --green: #2f855a;
  --shadow: 0 16px 42px rgba(24, 38, 64, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(43, 108, 176, 0.14), transparent 34%),
    linear-gradient(315deg, rgba(194, 65, 12, 0.12), transparent 38%),
    #eef3f8;
  color: var(--ink);
}

button,
select,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

.top-band {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 0 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--coral);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.6rem);
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

.stats {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stats span,
#mysteryBadge {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 6px 18px rgba(24, 38, 64, 0.08);
  font-weight: 800;
}

.controls {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
}

.controls label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

select,
input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

select:focus,
input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.16);
}

.controls button,
.twist-panel button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}

#hintBtn {
  background: var(--teal);
}

#clearBtn {
  background: var(--coral);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) 380px;
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

.puzzle-area,
.word-panel,
.twist-panel,
.draw-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.puzzle-area {
  padding: clamp(12px, 2vw, 20px);
}

.grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 6px;
  width: min(100%, 680px);
  aspect-ratio: 1;
  margin: 0 auto;
  touch-action: none;
  user-select: none;
}

.cell {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 1px solid #c8d1de;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--ink);
  font-size: clamp(1rem, 3vw, 1.7rem);
  font-weight: 900;
  line-height: 1;
  transition: transform 140ms ease, background 140ms ease, color 140ms ease;
}

.cell.selected {
  background: #facc15;
  border-color: #d69e2e;
  transform: scale(0.96);
}

.cell.found {
  background: #c6f6d5;
  border-color: var(--green);
  color: #14532d;
}

.cell.mystery-found {
  background: #fed7aa;
  border-color: var(--coral);
  color: #7c2d12;
}

.hint-text {
  min-height: 24px;
  margin: 14px 2px 0;
  color: var(--muted);
  font-weight: 700;
}

.side-panel {
  display: grid;
  gap: 14px;
}

.word-panel,
.twist-panel,
.draw-panel {
  padding: 16px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

#mysteryBadge {
  min-height: 30px;
  color: var(--coral);
  font-size: 0.78rem;
}

.word-list,
.sentence-list {
  list-style: none;
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
}

.word-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  font-weight: 900;
}

.word-list li.found {
  border-color: #9ae6b4;
  background: #ecfdf5;
  color: #166534;
  text-decoration: line-through;
}

.sentence-list li {
  padding: 10px;
  border-left: 4px solid var(--gold);
  border-radius: 6px;
  background: #fff8e6;
  color: #4a3520;
}

.twist-panel p {
  min-height: 42px;
  margin-bottom: 10px;
  color: var(--muted);
  font-weight: 700;
}

#sentenceForm {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.swatches {
  display: flex;
  gap: 8px;
}

.swatch {
  width: 30px;
  height: 30px;
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--swatch);
}

.swatch.active {
  border-color: #111827;
  box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.13);
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 31 / 17;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  touch-action: none;
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .draw-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100vw - 18px, 1180px);
    padding-top: 10px;
  }

  .top-band {
    align-items: start;
    flex-direction: column;
  }

  .stats {
    justify-content: start;
  }

  .controls {
    align-items: stretch;
  }

  .controls label,
  .controls button {
    flex: 1 1 135px;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .grid {
    gap: 4px;
  }

  .cell {
    border-radius: 6px;
  }

  #sentenceForm {
    grid-template-columns: 1fr;
  }
}
