:root {
  --bg: #0b0b0d;
  --panel: rgba(18, 18, 21, 0.88);
  --text: #e6e0d6;
  --muted: #8f887e;
  --line: rgba(230, 224, 214, 0.12);
  --accent: #b89a61;
  --error: #9f8060;
  --success: #d2b97f;
  --shadow: rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, #1b1b1f 0%, #0b0b0d 58%, #060607 100%);
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
}

body {
  min-height: 100vh;
}

.page-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 18px;
}

.puzzle-panel {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 28px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 24px 70px var(--shadow);
}

.image-wrap {
  margin: 0;
}

.clue-area { min-width: 0; }

.puzzle-panel.crossword-mode {
  width: min(1280px, 100%);
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  align-items: start;
}

.crossword-mode .content-wrap { min-width: 0; }

.grid-scroll { overflow-x: auto; padding-bottom: 6px; }

.crossword-grid {
  display: grid;
  grid-template-columns: repeat(25, minmax(24px, 1fr));
  min-width: 600px;
  gap: 1px;
  background: #08080a;
  border: 1px solid var(--line);
}

.crossword-cell {
  position: relative;
  aspect-ratio: 1;
  background: #29282a;
}

.crossword-cell.active-entry { background: #373127; }

.cell-number {
  position: absolute;
  top: 1px;
  left: 2px;
  z-index: 1;
  color: var(--muted);
  font: 8px/1 Arial, sans-serif;
  pointer-events: none;
}

.cell-input {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  padding: 6px 0 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-align: center;
  text-transform: uppercase;
  font: 15px/1 Arial, sans-serif;
}

.cell-input:focus { outline: 1px solid var(--accent); outline-offset: -1px; }
.crossword-controls { display: flex; gap: 12px; margin: 14px 0; }
.submit-button:disabled { opacity: 0.45; cursor: default; }
.clue-lists { display: none; }
.crossword-mode .clue-lists { display: block; margin-bottom: 12px; }
.clue-lists h2 { margin: 0 0 6px; color: var(--muted); font-size: 1rem; font-weight: normal; }
.clue-lists section + section { margin-top: 10px; }
.clue-lists ol { padding: 0; margin: 0; list-style: none; }
.clue-lists li {
  display: grid;
  grid-template-columns: 1.6em minmax(0, 1fr);
  align-items: start;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.3;
}
.clue-number { text-align: left; }
.clue-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: inherit;
  text-align: left;
  cursor: pointer;
}
.clue-button:focus-visible { outline: 1px solid var(--accent); outline-offset: 3px; }
.clue-button[aria-current="true"] { color: var(--success); }

.puzzle-image {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  filter: saturate(0.92) contrast(1.04);
}

.content-wrap {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.phase-label {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.22em;
}

.meta-marker {
  margin-left: 8px;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  opacity: 0.65;
}

.riddle {
  margin: 0 0 26px;
  font-size: clamp(1.9rem, 3vw, 2.8rem);
  line-height: 1.15;
  font-weight: 400;
}

.answer-form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.answer-input {
  flex: 1 1 250px;
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  outline: none;
}

.answer-input::placeholder {
  color: #716b63;
}

.answer-input:focus {
  border-color: rgba(184, 154, 97, 0.6);
  box-shadow: 0 0 0 1px rgba(184, 154, 97, 0.18);
}

.submit-button {
  padding: 14px 20px;
  border: 1px solid rgba(184, 154, 97, 0.38);
  background: rgba(184, 154, 97, 0.08);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    transform 0.2s ease;
}

.submit-button:hover {
  background: rgba(184, 154, 97, 0.14);
  border-color: rgba(184, 154, 97, 0.6);
}

.submit-button:active {
  transform: translateY(1px);
}

.response-message {
  min-height: 1.5em;
  margin: 0 0 18px;
  color: var(--error);
  font-size: 0.96rem;
}

.success-panel {
  padding: 16px 18px;
  border-left: 2px solid rgba(210, 185, 127, 0.5);
  background: rgba(210, 185, 127, 0.05);
  color: var(--success);
}

.success-panel p {
  margin: 0 0 10px;
}

.success-panel p:last-child {
  margin-bottom: 0;
}

.proceed-control {
  display: block;
  width: fit-content;
  margin: 16px 0 0 auto;
  padding: 7px 0;
  color: var(--success);
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.proceed-control:hover,
.proceed-control:focus-visible {
  border-bottom-color: transparent;
}

.hidden {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 820px) {
  .puzzle-panel,
  .puzzle-panel.crossword-mode {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 821px) {
  .puzzle-image {
    max-height: calc(100dvh - 106px);
    object-fit: contain;
  }

  .crossword-mode .content-wrap {
    justify-content: flex-start;
  }

  .crossword-mode .content-wrap > * { flex-shrink: 0; }

  .crossword-mode .riddle {
    font-size: clamp(1.5rem, 2.4vw, 2rem);
    margin-bottom: 10px;
  }

  #crossword {
    max-height: calc(100dvh - 106px);
    overflow: auto;
  }

  .crossword-grid {
    width: min(100%, calc((100dvh - 240px) * 25 / 16));
    min-width: 626px;
  }
}

@media (min-width: 1200px) {
  .page-shell:has(.crossword-mode) { padding-top: 16px; padding-bottom: 16px; }
  .puzzle-panel.crossword-mode {
    width: min(1480px, 100%);
    grid-template-columns: minmax(626px, 1.05fr) minmax(0, 1fr);
    gap: 24px;
    padding: 16px;
  }
  .clue-lists ol {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 16px;
    row-gap: 8px;
  }
  .clue-lists li { margin-bottom: 0; }
  .crossword-mode .phase-label { margin-bottom: 8px; }
  .crossword-mode .answer-form { margin-bottom: 8px; }
  .crossword-mode .answer-input { flex-basis: 180px; padding: 10px 12px; }
  .crossword-mode .content-wrap .submit-button { padding: 10px 16px; }
  .crossword-mode .content-wrap .response-message { margin-bottom: 8px; }
  .crossword-mode .success-panel { padding: 10px 14px; }
  .crossword-mode .success-panel p { margin-bottom: 4px; }
  .crossword-mode .proceed-control { margin-top: 8px; padding: 5px 0; }
}

.proceed-control:focus:not(:focus-visible) { outline: none; }
