:root {
  color-scheme: dark;
  --bg: #111316;
  --panel: #191d22;
  --panel-alpha: rgba(25, 29, 34, 0.92);
  --panel-2: #20262d;
  --field: #0f1215;
  --surface: #12171a;
  --text: #f4f7fb;
  --muted: #9aa5b1;
  --line: #303842;
  --exact: #238957;
  --partial: #b88922;
  --miss: #353d47;
  --cell-border: rgba(255, 255, 255, 0.07);
  --hint-text: rgba(255, 255, 255, 0.82);
  --danger: #d35a5a;
  --accent: #66d9c3;
  --accent-text: #07100e;
  --bg-glow-a: rgba(102, 217, 195, 0.12);
  --bg-glow-b: rgba(218, 95, 95, 0.12);
  --focus-ring: rgba(102, 217, 195, 0.16);
  --shadow: 0 20px 70px rgba(0, 0, 0, 0.34);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-alpha: rgba(255, 255, 255, 0.94);
  --panel-2: #edf2f7;
  --field: #ffffff;
  --surface: #f8fafc;
  --text: #151a21;
  --muted: #5c6875;
  --line: #d7e0ea;
  --exact: #2fa36c;
  --partial: #d4a12d;
  --miss: #d8e0e8;
  --cell-border: rgba(16, 24, 40, 0.08);
  --hint-text: rgba(17, 24, 39, 0.72);
  --danger: #c24141;
  --accent: #18b39a;
  --accent-text: #061412;
  --bg-glow-a: rgba(24, 179, 154, 0.16);
  --bg-glow-b: rgba(219, 91, 91, 0.12);
  --focus-ring: rgba(24, 179, 154, 0.18);
  --shadow: 0 18px 56px rgba(41, 52, 65, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, var(--bg-glow-a), transparent 34%),
    linear-gradient(225deg, var(--bg-glow-b), transparent 32%),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  font-weight: 800;
  min-height: 48px;
  padding: 0 20px;
}

button:hover {
  filter: brightness(1.06);
}

button:disabled {
  cursor: not-allowed;
  filter: grayscale(1);
  opacity: 0.58;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 28px;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin-bottom: 24px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2.35rem, 6vw, 4.8rem);
  line-height: 0.95;
  overflow-wrap: anywhere;
}

h2 {
  font-size: 1.3rem;
  line-height: 1.2;
}

.stats {
  align-items: center;
  display: flex;
  gap: 10px;
  white-space: nowrap;
}

.stats span {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 800;
  padding: 10px 12px;
}

.stats #guessCount {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
}

.streak-stat {
  font-size: 0.86rem;
}

.theme-toggle {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  min-height: 42px;
  padding: 0 14px;
}

.start-screen {
  align-items: center;
  background: var(--panel-alpha);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 22px;
  justify-content: space-between;
  min-height: 280px;
  padding: 24px;
}

.start-screen[hidden] {
  display: none;
}

.start-screen h2 {
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 0.98;
  max-width: 720px;
}

.start-screen p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.5;
  margin-top: 14px;
  max-width: 620px;
}

.start-actions {
  display: grid;
  gap: 10px;
  min-width: 210px;
}

.secondary-action {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
}

.play-area {
  background: var(--panel-alpha);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.play-area[hidden] {
  display: none;
}

.intro {
  align-items: end;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 18px;
}

.intro p {
  color: var(--muted);
  max-width: 560px;
}

.guess-form {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr auto;
}

.guess-form > button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: 800;
}

.input-wrap {
  display: grid;
  gap: 8px;
  position: relative;
}

label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

input {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  min-height: 48px;
  outline: 0;
  padding: 0 14px;
  width: 100%;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

input:-webkit-autofill {
  box-shadow: 0 0 0 1000px var(--field) inset;
  -webkit-text-fill-color: var(--text);
}

.suggestions {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  left: 0;
  margin-top: 4px;
  max-height: 300px;
  overflow-y: auto;
  padding: 6px;
  position: absolute;
  top: 100%;
  width: 100%;
  z-index: 1000;
}

.suggestions[hidden] {
  display: none;
}

.suggestion-item {
  background: transparent;
  border-radius: 6px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 38px;
  overflow: hidden;
  padding: 0 10px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.suggestion-item:hover,
.suggestion-item:focus,
.suggestion-item.active {
  background: var(--panel-2);
  color: var(--text);
  filter: none;
}

.message {
  color: var(--muted);
  min-height: 28px;
  padding: 10px 0 0;
}

.message.error {
  color: var(--danger);
}

.table-frame {
  overflow-x: auto;
  padding-top: 8px;
  perspective: 900px;
}

.guess-grid {
  display: grid;
  gap: 8px;
  grid-template-columns:
    minmax(180px, 1.3fr)
    minmax(180px, 1.1fr)
    minmax(90px, 0.72fr)
    minmax(110px, 0.78fr)
    minmax(120px, 0.85fr)
    minmax(130px, 0.9fr);
  min-width: 930px;
}

.header-row {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.guess-list {
  display: grid;
  gap: 8px;
}

.cell {
  align-items: center;
  background: var(--miss);
  border: 1px solid var(--cell-border);
  border-radius: 8px;
  display: flex;
  font-size: 0.9rem;
  font-weight: 800;
  justify-content: center;
  min-height: 64px;
  padding: 8px;
  text-align: center;
  word-break: break-word;
}

.answer-mark {
  flex: 0 0 auto;
  margin-right: 6px;
}

.revealing .reveal-card {
  animation: flip-reveal var(--flip-duration, 170ms) cubic-bezier(0.2, 0.7, 0.25, 1) both;
  animation-delay: var(--flip-delay, 0ms);
  backface-visibility: hidden;
  transform-origin: center;
}

.revealing .reveal-card:not(.is-revealed) {
  background: var(--panel-2);
  color: transparent;
  opacity: 0;
  transform: rotateX(-90deg);
}

.revealing .reveal-card:not(.is-revealed) * {
  opacity: 0;
}

.cell.name {
  background: var(--panel-2);
  align-items: flex-start;
  flex-direction: column;
  gap: 8px;
  justify-content: flex-start;
  padding: 12px;
  text-align: left;
}

.guess-subtitle {
  color: var(--hint-text);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.guess-title {
  font-size: 1rem;
  font-weight: 900;
}

.guess-name-row {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  width: 100%;
}

.guess-row-toggle {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 0.76rem;
  font-weight: 900;
  gap: 6px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.guess-row-toggle::before {
  color: var(--accent);
  content: "+";
  font-size: 1rem;
  line-height: 1;
}

.cell.exact {
  background: var(--exact);
}

.cell.partial {
  background: var(--partial);
}

.cell.partial[title] {
  cursor: help;
}

.cell.miss {
  background: var(--miss);
}

.guess-row-details {
  background: transparent;
  border: 0;
  margin: 0;
  padding: 0;
}

.guess-row-summary {
  cursor: pointer;
  list-style: none;
}

.guess-row-summary::-webkit-details-marker {
  display: none;
}

.guess-row-details[open] .guess-row-toggle::before {
  content: "-";
}

.guess-row-facts {
  background: var(--panel-2);
  border: 1px solid var(--cell-border);
  border-radius: 8px;
  color: var(--text);
  margin-top: 8px;
  min-height: 0;
  padding: 12px;
}

.guess-row-facts dl {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  margin: 0;
  overflow-x: auto;
}

.more-fact {
  min-width: 0;
}

.more-fact.overview {
  grid-column: 1 / -1;
}

.guess-row-facts dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.guess-row-facts dd {
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.45;
  margin: 0;
  min-width: 0;
  overflow-wrap: break-word;
}

@keyframes flip-reveal {
  0% {
    background: var(--panel-2);
    color: transparent;
    opacity: 0;
    transform: rotateX(-90deg);
  }

  55% {
    opacity: 1;
    transform: rotateX(12deg);
  }

  100% {
    opacity: 1;
    transform: rotateX(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .revealing .reveal-card {
    animation-duration: 1ms;
    animation-delay: 0ms;
  }
}

.hint {
  color: var(--hint-text);
  display: block;
  font-size: 0.78rem;
  font-weight: 900;
  margin-top: 3px;
}

.modal-backdrop {
  align-items: center;
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: fixed;
  z-index: 20;
}

.modal-backdrop::before {
  background: rgba(0, 0, 0, 0.58);
  content: "";
  inset: 0;
  position: absolute;
}

.modal-backdrop[hidden] {
  display: none;
}

.result-modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  max-width: 980px;
  padding: 22px;
  position: relative;
  width: min(100%, 980px);
  z-index: 1;
}

.result-kicker {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.result-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.result-title {
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
}

.answer-line {
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 900;
}

.result-meta {
  color: var(--muted);
  line-height: 1.45;
  margin-top: 6px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.result-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1.1fr) 300px;
}

.result-side {
  display: grid;
  gap: 16px;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.result-section-label {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  margin: 0;
  text-transform: uppercase;
}

.share-pre {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  line-height: 1.6;
  margin-top: 12px;
  min-height: 160px;
  overflow: auto;
  padding: 14px;
  white-space: pre-wrap;
}

.share-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.share-action-button,
.result-close-button,
.result-review-button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
}

.share-action-button {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  justify-content: center;
  min-width: 112px;
}

.share-action-icon {
  align-items: center;
  border-radius: 4px;
  display: inline-flex;
  height: 1rem;
  justify-content: center;
  width: 1rem;
}

.share-action-icon-x {
  background: #000;
  padding: 2px;
}

.share-action-icon-image {
  display: block;
  height: 100%;
  width: 100%;
}

.result-big {
  font-size: 2.2rem;
  font-weight: 900;
  margin-top: 8px;
}

.result-lines {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.result-line {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 1.05rem;
  letter-spacing: 0.22em;
  padding: 10px 12px;
}

.result-stat-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 12px;
}

.result-stat-box {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  padding: 10px 12px;
}

.result-stat-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.result-stat-value {
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 900;
}

.distribution-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.distribution-row {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: 20px minmax(0, 1fr) 28px;
}

.distribution-row-label,
.distribution-row-count {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.distribution-row-count {
  text-align: right;
}

.distribution-bar {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  min-height: 12px;
  overflow: hidden;
}

.distribution-fill {
  background: var(--accent);
  border-radius: inherit;
  height: 100%;
  min-width: 8px;
}

.distribution-fill.loss-fill {
  background: #d96a6a;
}

.legend {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin: 18px 0 0;
}

.chip {
  border-radius: 4px;
  display: inline-block;
  height: 12px;
  margin-right: 6px;
  vertical-align: -1px;
  width: 18px;
}

.chip.exact {
  background: var(--exact);
}

.chip.partial {
  background: var(--partial);
}

.chip.miss {
  background: var(--miss);
}

.arrow {
  color: var(--accent);
  margin-right: 4px;
}

footer {
  color: var(--muted);
  font-size: 0.86rem;
  margin-top: 24px;
}

@media (max-width: 720px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .topbar,
  .start-screen,
  .intro,
  .result-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .start-actions {
    width: 100%;
  }

  .start-actions button {
    width: 100%;
  }

  .stats {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .stats span {
    align-items: center;
    display: flex;
    min-height: 46px;
  }

  .stats #guessCount {
    font-size: 1rem;
    justify-content: center;
  }

  .theme-toggle {
    grid-column: 1 / -1;
    width: 100%;
  }

  .guess-form {
    grid-template-columns: 1fr;
  }

  .guess-form button,
  .share-actions,
  .share-action-button,
  .result-close-button,
  .result-review-button {
    width: 100%;
  }

  .result-grid {
    grid-template-columns: 1fr;
  }
}
