:root {
  --bg: #efe2b8;
  --panel: rgba(255, 252, 245, 0.98);
  --panel-border: rgba(67, 47, 17, 0.26);
  --text: #1d1408;
  --muted: #4a3927;
  --gold: #8f6416;
  --gold-deep: #5e3f0b;
  --green: #1d6a42;
  --amber: #a96300;
  --red: #8c3527;
  --shadow: 0 18px 42px rgba(72, 49, 15, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(227, 183, 74, 0.34), transparent 24%),
    radial-gradient(circle at bottom right, rgba(159, 101, 25, 0.16), transparent 22%),
    linear-gradient(135deg, #f7edd0 0%, #ead6a2 46%, #dcc184 100%);
}

button,
input {
  font: inherit;
}

.page-shell {
  width: min(1200px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 3rem;
}

.hero {
  padding: 2rem;
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  background: linear-gradient(145deg, rgba(255, 250, 238, 0.98), rgba(239, 223, 179, 0.95));
  box-shadow: var(--shadow);
}

.eyebrow,
.section-label,
.meta-label,
.reveal-kicker,
.locked-title {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.75rem;
  color: var(--gold-deep);
}

.hero h1,
.panel h2,
.reveal-copy h3 {
  margin: 0;
  font-weight: 700;
}

.hero h1 {
  font-size: clamp(2.9rem, 8vw, 5.8rem);
  line-height: 0.95;
}

.hero-copy {
  max-width: 56rem;
  font-size: 1.08rem;
  color: var(--muted);
}

.panel {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(8px);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(320px, 0.95fr);
  gap: 1.25rem;
  margin-top: 1.25rem;
}

.panel {
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
}

.panel-heading-compact {
  justify-content: stretch;
  margin-bottom: 0.35rem;
}

.mode-panel {
  display: grid;
  gap: 0.6rem;
  justify-items: stretch;
  min-width: 0;
  width: 100%;
}

.mode-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
  width: 100%;
}

.mode-secondary-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
  width: 100%;
  min-height: 3.6rem;
}

.mode-panel .panel-subtitle {
  justify-self: center;
  margin-top: 0;
  text-align: center;
}

.panel-heading h2 {
  font-size: 1.65rem;
}

.panel-subtitle {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-weight: 700;
}

.game-panel > .panel-heading,
.game-panel > .tool-strip,
.game-panel > .hint-panel,
.game-panel > .action-row,
.game-panel > .guess-form,
.game-panel > .status-message,
.game-panel > .legend,
.game-panel > .table-scroll {
  position: relative;
  z-index: 1;
}

.game-panel > .tool-strip,
.game-panel > .action-row,
.game-panel > .guess-form,
.game-panel > .hint-panel {
  padding: 1rem;
  border: 1px solid rgba(101, 70, 16, 0.14);
  border-radius: 18px;
  background: rgba(255, 249, 239, 0.76);
}

.game-panel > .guess-form {
  background: rgba(255, 252, 247, 0.96);
}

.game-panel > .table-scroll {
  margin-top: 1rem;
  padding-top: 0.35rem;
  border-top: 1px solid rgba(101, 70, 16, 0.12);
}

.game-panel > .action-row {
  align-items: center;
}


.guess-form {
  margin-top: 1rem;
}

.input-label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--muted);
}

.guess-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.autocomplete-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 0.75rem;
  flex: 1;
  align-items: start;
}

#guess-input {
  width: 100%;
  border: 1px solid rgba(86, 59, 20, 0.34);
  border-radius: 16px;
  padding: 0.95rem 1rem;
  background: #fffdfa;
  color: var(--text);
}

#guess-input:focus {
  outline: 3px solid rgba(143, 100, 22, 0.2);
  border-color: rgba(143, 100, 22, 0.58);
}

.autocomplete-list {
  display: grid;
  gap: 0.25rem;
  padding: 0.35rem;
  max-height: 15.5rem;
  overflow-y: auto;
  border: 1px solid rgba(101, 70, 16, 0.22);
  border-radius: 16px;
  background: #fffdfa;
  box-shadow: 0 16px 30px rgba(72, 49, 15, 0.12);
}

.autocomplete-item {
  border: none;
  text-align: left;
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
}

.autocomplete-item:hover {
  background: rgba(255, 244, 220, 1);
}

.primary-button,
.secondary-button,
.ghost-button {
  border-radius: 16px;
  padding: 0.9rem 1.15rem;
  cursor: pointer;
  transition: transform 180ms ease, opacity 180ms ease, background 180ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.primary-button {
  border: none;
  background: linear-gradient(135deg, var(--gold), #b78322);
  color: #fffdf7;
}

.secondary-button {
  width: 100%;
  margin-top: 1rem;
  border: 1px solid rgba(101, 70, 16, 0.28);
  background: rgba(255, 248, 233, 1);
  color: var(--gold-deep);
}

.ghost-button {
  border: 1px solid rgba(101, 70, 16, 0.24);
  background: rgba(255, 249, 239, 0.94);
  color: var(--text);
}

.mode-actions .ghost-button,
.mode-secondary-actions .ghost-button {
  width: 100%;
}

.active-mode {
  background: linear-gradient(135deg, rgba(143, 100, 22, 0.96), rgba(183, 131, 34, 0.92));
  border-color: rgba(143, 100, 22, 0.95);
  color: #fff9ef;
}

.tool-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  align-items: end;
  margin-top: 1rem;
}

.compact-input {
  width: 100%;
  border: 1px solid rgba(86, 59, 20, 0.34);
  border-radius: 14px;
  padding: 0.8rem 0.9rem;
  background: #fffdfa;
  color: var(--text);
}

.tool-group {
  min-width: 180px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.small-button {
  width: auto;
  margin-top: 0;
}

.status-message {
  min-height: 1.5rem;
  color: var(--text);
  font-weight: 600;
  padding-top: 0.25rem;
}

.hint-panel {
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  border-radius: 16px;
  background: rgba(255, 248, 233, 1);
  border: 1px solid rgba(101, 70, 16, 0.2);
}

.hint-panel p {
  margin: 0.25rem 0;
  font-weight: 700;
  color: var(--gold-deep);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 1rem 0;
  color: var(--muted);
}

.legend span {
  display: inline-flex;
  gap: 0.45rem;
  align-items: center;
}

.legend-chip {
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 999px;
  display: inline-block;
}

.exact {
  background: rgba(29, 106, 66, 0.2);
  color: var(--green);
}

.partial {
  background: rgba(169, 99, 0, 0.2);
  color: var(--amber);
}

.miss {
  background: rgba(140, 53, 39, 0.16);
  color: var(--red);
}

.table-scroll {
  overflow-x: auto;
}

.guess-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.guess-table th,
.guess-table td {
  padding: 0.9rem 0.75rem;
  border-bottom: 1px solid rgba(67, 46, 16, 0.16);
  text-align: left;
  vertical-align: top;
}

.guess-table td:not(:first-child) .cell-stack {
  justify-items: center;
}

.guess-table th {
  color: var(--gold-deep);
  font-size: 0.85rem;
  background: rgba(231, 214, 176, 0.55);
}

.cell-stack {
  display: grid;
  gap: 0.35rem;
  justify-items: start;
}

.cell-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  width: fit-content;
  padding: 0.45rem 0.6rem;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 700;
  border: 1px solid currentColor;
}

.direction {
  font-size: 0.9rem;
}

.hint-note {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
  width: 100%;
}

.guess-table td:not(:first-child) .hint-note {
  text-align: center;
}

.reveal-panel {
  display: flex;
  flex-direction: column;
}

.reveal-panel > .reveal-card,
.reveal-panel > .locked-card,
.reveal-panel > .archive-panel {
  padding: 1rem;
  border-radius: 18px;
  background: rgba(255, 249, 239, 0.72);
  border: 1px solid rgba(101, 70, 16, 0.14);
}

.reveal-card {
  display: grid;
  gap: 1rem;
  animation: fade-in 300ms ease;
}

.study-card {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 18px;
  background: rgba(255, 249, 239, 0.92);
  border: 1px solid rgba(101, 70, 16, 0.16);
}

.study-card h3 {
  margin: 0.25rem 0 0.85rem;
}

.study-content {
  display: grid;
  gap: 0.55rem;
  color: var(--muted);
}

.study-content p {
  margin: 0;
}

.study-guesses {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 18px;
  background: rgba(255, 249, 239, 0.92);
  border: 1px solid rgba(101, 70, 16, 0.16);
}

.study-guesses-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.study-guesses-list {
  display: grid;
  gap: 0.65rem;
}

.study-guess-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 0.8rem 0.9rem;
  border-radius: 14px;
  border: 1px solid rgba(101, 70, 16, 0.14);
}

.study-correct {
  background: rgba(29, 106, 66, 0.12);
  border-color: rgba(29, 106, 66, 0.3);
}

.study-incorrect {
  background: rgba(140, 53, 39, 0.08);
  border-color: rgba(140, 53, 39, 0.2);
}

.hidden {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translate(-50%, 12px);
  z-index: 50;
  padding: 0.7rem 0.95rem;
  border-radius: 999px;
  background: rgba(29, 20, 8, 0.92);
  color: #fffdf7;
  font-size: 0.9rem;
  font-weight: 700;
  box-shadow: 0 14px 28px rgba(29, 20, 8, 0.24);
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.tool-strip.hidden,
.study-guesses.hidden,
.archive-panel.hidden,
.hint-panel.hidden,
.reveal-card.hidden,
.study-card.hidden {
  display: none;
}

.locked-card {
  border: 1px dashed rgba(101, 70, 16, 0.34);
  background: rgba(255, 250, 241, 0.92);
  color: var(--text);
}

.portrait-frame {
  aspect-ratio: 4 / 5;
  overflow: hidden;
  border-radius: 22px;
  background: linear-gradient(160deg, rgba(212, 171, 89, 0.72), rgba(112, 80, 27, 0.24));
}

.portrait-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.reveal-copy p {
  color: var(--muted);
}

.reveal-details {
  margin-bottom: 0;
}

.reveal-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.reveal-links a {
  color: var(--gold-deep);
  font-weight: 700;
}

.archive-panel {
  margin-top: 1rem;
}

.archive-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.65rem;
  align-items: end;
}

.archive-button {
  padding-inline: 1rem;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 920px) {
  .page-shell {
    width: min(100% - 1.25rem, 100%);
    padding: 1rem 0 2rem;
  }

  .hero {
    padding: 1.4rem;
  }

  .hero h1 {
    font-size: clamp(2.4rem, 12vw, 4.1rem);
  }

  .hero-copy {
    margin-top: 0.65rem;
    font-size: 1rem;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

@media (max-width: 640px) {
  .layout {
    display: flex;
    flex-direction: column;
  }

  .game-panel {
    display: flex;
    flex-direction: column;
    order: 1;
  }

  .reveal-panel {
    order: 2;
  }

  body[data-mode="study"] .reveal-panel {
    order: 1;
  }

  body[data-mode="study"] .game-panel {
    order: 2;
  }

  .page-shell {
    width: min(100% - 0.75rem, 100%);
    padding-top: 0.65rem;
  }

  .hero,
  .panel {
    padding: 0.9rem;
    border-radius: 18px;
  }

  .hero {
    text-align: center;
    padding: 0.75rem 0.9rem;
  }

  .hero-copy {
    display: none;
  }

  .hero h1 {
    font-size: clamp(2rem, 10vw, 2.7rem);
  }

  .toast {
    bottom: 0.8rem;
    width: calc(100% - 1.5rem);
    text-align: center;
    font-size: 0.84rem;
  }

  .panel-heading {
    gap: 0.75rem;
  }

  .game-panel > .panel-heading-compact {
    order: 8;
    margin-top: 0.75rem;
    margin-bottom: 0;
  }

  .game-panel > .tool-strip {
    order: 9;
  }

  .game-panel > .hint-panel {
    order: 5;
  }

  .game-panel > .action-row {
    order: 2;
  }

  .game-panel > .guess-form {
    order: 1;
  }

  .game-panel > .study-guesses {
    order: 3;
  }

  .game-panel > .status-message {
    order: 4;
  }

  .game-panel > .legend {
    order: 6;
  }

  .game-panel > .table-scroll {
    order: 7;
  }

  body[data-mode="study"][data-study-finished="true"] .game-panel > .panel-heading-compact {
    order: 3;
    margin-top: 0.4rem;
  }

  body[data-mode="study"][data-study-finished="true"] .game-panel > .tool-strip {
    order: 4;
  }

  body[data-mode="study"][data-study-finished="true"] .game-panel > .study-guesses {
    order: 5;
  }

  body[data-mode="study"][data-study-finished="true"] .game-panel > .status-message {
    order: 2;
  }

  .panel-heading,
  .study-guesses-header,
  .archive-row,
  .guess-row {
    flex-direction: column;
  }

  .mode-panel,
  .mode-actions,
  .mode-secondary-actions {
    width: 100%;
  }

  .mode-actions,
  .mode-secondary-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
  }

  .mode-actions button:last-child,
  .mode-secondary-actions button:last-child {
    grid-column: 1 / -1;
  }

  .autocomplete-shell {
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }

  .tool-strip {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.55rem;
  }

  .tool-group {
    min-width: 0;
  }

  .action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
  }

  .action-row button {
    flex: 0 0 auto;
  }

  .primary-button,
  .ghost-button,
  .secondary-button,
  .small-button {
    width: 100%;
  }

  .ghost-button,
  .secondary-button,
  .primary-button {
    padding: 0.7rem 0.85rem;
    border-radius: 14px;
    font-size: 0.95rem;
  }

  .action-row .small-button {
    width: auto;
    padding: 0.45rem 0.65rem;
    border-radius: 999px;
    font-size: 0.82rem;
    line-height: 1.1;
    margin-top: 0;
  }

  .guess-form,
  .study-guesses,
  .study-card,
  .locked-card,
  .archive-panel,
  .reveal-card,
  .game-panel > .tool-strip,
  .game-panel > .action-row,
  .game-panel > .hint-panel {
    padding: 0.85rem;
    border-radius: 16px;
  }

  .autocomplete-list {
    max-height: 12rem;
  }

  .guess-row {
    gap: 0.55rem;
  }

  #guess-input {
    padding: 0.85rem 0.95rem;
    border-radius: 14px;
    font-size: 0.98rem;
  }

  .status-message {
    min-height: auto;
    padding-top: 0;
    font-size: 0.95rem;
  }

  .legend {
    gap: 0.45rem 0.7rem;
    margin: 0.55rem 0;
    font-size: 0.82rem;
  }

  .table-scroll {
    overflow-x: auto;
    padding-bottom: 0.15rem;
    -webkit-overflow-scrolling: touch;
  }

  .guess-table {
    min-width: 0;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 0.45rem;
  }

  .guess-table thead {
    display: none;
  }

  .guess-table tbody,
  .guess-table tr {
    display: block;
  }

  .guess-table tr {
    white-space: nowrap;
  }

  .guess-table td {
    display: inline-flex;
    flex-direction: column;
    vertical-align: top;
    white-space: normal;
    width: 132px;
    min-height: 106px;
    gap: 0.32rem;
    margin-right: 0.4rem;
    padding: 0.6rem;
    border: 1px solid rgba(101, 70, 16, 0.14);
    border-radius: 14px;
    background: rgba(255, 249, 239, 0.88);
  }

  .guess-table td::before {
    content: attr(data-label);
    color: var(--gold-deep);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .guess-table td:first-child {
    width: 170px;
  }

  .guess-table td:not(:first-child) .cell-stack,
  .guess-table td:not(:first-child) .hint-note {
    justify-items: start;
    text-align: left;
  }

  .cell-chip {
    width: fit-content;
    max-width: 100%;
    font-size: 0.82rem;
    padding: 0.38rem 0.52rem;
  }

  .hint-note {
    font-size: 0.74rem;
  }

  .study-guess-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }

  .study-guesses {
    padding: 0.65rem;
    border-radius: 14px;
  }

  .study-guesses-header {
    margin-bottom: 0.45rem;
  }

  .study-guesses-list {
    gap: 0.4rem;
  }

  .study-guess-item {
    padding: 0.5rem 0.6rem;
    border-radius: 12px;
    gap: 0.2rem;
  }

  .study-guess-item span,
  .study-guess-item strong,
  #study-guess-count {
    font-size: 0.82rem;
  }

  .archive-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.55rem;
  }

  .reveal-links {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }

  .reveal-panel .panel-heading {
    margin-bottom: 0.45rem;
  }

  .reveal-panel h2,
  .study-card h3 {
    font-size: 1.15rem;
  }
}
