: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: 18px;
}

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

h1,
h2,
p,
pre {
  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;
}

.topbar h1 {
  font-size: clamp(2rem, 5vw, 3.9rem);
}

.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;
}

.theme-toggle,
.secondary-action,
.more-cell summary,
.share-action-button,
.result-close-button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
}

.theme-toggle {
  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;
}

.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: 620px;
}

.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: 52px;
  outline: none;
  padding: 0 14px;
}

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

.suggestions {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 4px;
  left: 0;
  max-height: 260px;
  overflow-y: auto;
  padding: 6px;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 10;
}

.suggestions[hidden] {
  display: none;
}

.suggestion-item {
  align-items: center;
  background: transparent;
  border-radius: 6px;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  min-height: 42px;
  padding: 10px;
  text-align: left;
  width: 100%;
}

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

.suggestion-meta {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 4px;
}

.session-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.session-pill {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  padding: 10px 12px;
}

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

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

.message.success-message {
  color: var(--accent);
}

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

.guess-grid {
  display: grid;
  gap: 8px;
  grid-template-columns:
    minmax(180px, 1.2fr)
    minmax(130px, 0.9fr)
    minmax(130px, 1fr)
    minmax(120px, 0.9fr)
    minmax(120px, 0.9fr)
    minmax(130px, 1fr);
  min-width: 850px;
}

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

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

.empty-state {
  color: var(--muted);
  font-size: 0.92rem;
  padding: 16px 0 4px;
}

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

.cell.name {
  background: var(--panel-2);
}

.cell.name {
  align-items: flex-start;
  justify-content: center;
  text-align: left;
}

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

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

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

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

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

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

.country-guess-toggle {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 0.72rem;
  font-weight: 900;
  justify-content: center;
  min-height: 30px;
  padding: 0 12px;
  text-transform: uppercase;
}

.country-guess-toggle:hover,
.country-guess-toggle:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
  outline: none;
}

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

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

.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 {
  align-items: flex-start;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.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;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.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 {
  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;
}

.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;
}

.country-guess-entry {
  border: 0;
  display: grid;
  gap: 8px;
  overflow: hidden;
}

.country-guess-entry > summary {
  cursor: default;
  list-style: none;
}

.country-guess-entry > summary::-webkit-details-marker {
  display: none;
}

.country-guess-entry:not([open]) .country-guess-facts {
  display: none;
}

.country-guess-expand {
  min-height: 38px;
  padding: 0 14px;
}

.country-guess-status {
  white-space: nowrap;
}

.country-guess-clues {
  align-items: stretch;
}

.country-guess-summary {
  align-items: stretch;
}

.country-guess-clue,
.country-guess-fact-row {
  overflow-wrap: normal;
  word-break: normal;
}

.country-guess-revealing {
  perspective: 1200px;
}

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

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

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

.country-guess-revealing .country-guess-facts {
  animation: country-facts-fade 320ms ease both;
  animation-delay: calc(var(--country-flip-duration, 480ms) + 220ms);
  opacity: 0;
}

.country-guess-value {
  overflow-x: auto;
  white-space: nowrap;
}

.country-guess-facts {
  display: grid;
  gap: 10px;
  margin-top: 0;
}

.country-guess-fact-row {
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: grid;
  gap: 6px;
  padding: 12px 14px;
}

.country-guess-fact-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.country-guess-fact-text {
  color: var(--text);
  line-height: 1.5;
  overflow-x: auto;
  white-space: nowrap;
}

@keyframes country-flip-reveal {
  0% {
    opacity: 0;
    transform: rotateX(-90deg) translateY(10px);
  }

  55% {
    opacity: 1;
    transform: rotateX(18deg) translateY(0);
  }

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

@keyframes country-facts-fade {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@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,
  .guess-form,
  .guess-form > button {
    width: 100%;
  }

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

  .stats {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .stats span,
  .theme-toggle {
    width: 100%;
  }

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

  .country-guess-summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .country-guess-actions {
    width: 100%;
    justify-content: space-between;
  }

  .country-guess-expand {
    min-width: 88px;
  }

  .country-guess-clues {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .country-guess-clue {
    min-height: 96px;
  }

  .country-guess-fact-text {
    font-size: 0.92rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .country-guess-revealing .reveal-card,
  .country-guess-revealing .country-guess-facts {
    animation: none;
    opacity: 1;
    transform: none;
  }
}
