:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --text: #22201d;
  --muted: #716d67;
  --border: #dedad2;
  --accent: #2e6b4e;
  --accent-dark: #24553f;
  --wrong: #b75c4d;
  --success: #2e6b4e;
  --partial: #9a741c;
  --empty: #ebe8e1;
  --shadow: 0 12px 35px rgba(35, 31, 25, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  background: var(--bg);
  color: var(--text);
  font-family:
    ui-rounded,
    "SF Pro Rounded",
    "Segoe UI",
    system-ui,
    sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.game-shell {
  width: min(100% - 28px, 760px);
  margin: 0 auto;
  padding: 20px 0 max(24px, env(safe-area-inset-bottom));
}


/* -------------------------------------------------------------------------- */
/* Header                                                                     */
/* -------------------------------------------------------------------------- */

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 2px 12px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.7rem, 5vw, 2.25rem);
  line-height: 1;
  letter-spacing: -0.04em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.icon-button,
.dialog-close {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font-weight: 750;
}

.icon-button:hover,
.dialog-close:hover {
  color: var(--text);
}

.report-icon-button {
  color: var(--wrong);
}

.report-icon-button:hover {
  border-color: var(--wrong);
  color: #934638;
  background: #fdf3f1;
}


/* -------------------------------------------------------------------------- */
/* Game modes                                                                 */
/* -------------------------------------------------------------------------- */

.game-modes {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  padding: 0 2px 12px;
}

.mode-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
}

.mode-button {
  min-height: 32px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 750;
}

.mode-button:hover {
  border-color: var(--accent);
  background: #f0f5f1;
}


/* -------------------------------------------------------------------------- */
/* Main card                                                                  */
/* -------------------------------------------------------------------------- */

.game-card {
  position: relative;
  padding: clamp(12px, 2.5vw, 20px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.image-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 12px;
  background: #171614;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.image-placeholder {
  position: absolute;
  color: #aaa59d;
  font-size: 0.9rem;
}

.image-placeholder[hidden] {
  display: none;
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 2px 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}


/* -------------------------------------------------------------------------- */
/* Guess form                                                                 */
/* -------------------------------------------------------------------------- */

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

.guess-input-wrap {
  position: relative;
  min-width: 0;
}

.guess-form input {
  width: 100%;
  min-width: 0;
  height: 50px;
  padding: 0 15px;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  background: #fff;
  color: var(--text);
  font-size: 1rem;
}

.guess-form input:focus {
  border-color: var(--accent);
  box-shadow:
    0 0 0 3px
    rgba(46, 107, 78, 0.12);
}

.guess-form input:disabled {
  background: #f0eee9;
}

/*
 * Only style the actual Guess submit button.
 *
 * The autocomplete buttons live inside .guess-input-wrap, so using
 * ".guess-form button" here would also style every suggestion button.
 */
.guess-form > button,
.secondary-button {
  min-height: 50px;
  padding: 0 20px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  font-weight: 750;
}

.guess-form > button:hover,
.secondary-button:hover {
  background: var(--accent-dark);
}

.guess-form > button:disabled {
  opacity: 0.5;
  cursor: default;
}


/* -------------------------------------------------------------------------- */
/* Autocomplete                                                               */
/* -------------------------------------------------------------------------- */

.suggestions {
  position: absolute;
  z-index: 50;
  top: calc(100% + 4px);
  left: 0;
  right: 0;

  display: grid;

  max-height: 280px;
  overflow-y: auto;

  padding: 4px 0;

  border: 1px solid var(--border);
  border-radius: 10px;

  background: var(--surface);
  box-shadow: 0 8px 24px rgba(35, 31, 25, 0.12);

  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.suggestions[hidden] {
  display: none;
}

.suggestion {
  width: 100%;
  min-height: 40px;
  padding: 9px 13px;

  border: 0;
  border-radius: 0;

  background: transparent;
  color: var(--text);

  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.25;

  text-align: left;

  cursor: pointer;

  -webkit-tap-highlight-color: transparent;
}

.suggestion + .suggestion {
  border-top: 1px solid #f0ede8;
}

.suggestion:hover,
.suggestion:focus-visible {
  background: #f5f3ef;
  color: var(--text);
  outline: none;
}

.suggestion:active {
  background: #eeebe5;
}

@media (hover: none) {
  .suggestion {
    min-height: 44px;
  }
}


/* -------------------------------------------------------------------------- */
/* Message                                                                    */
/* -------------------------------------------------------------------------- */

.message {
  min-height: 24px;
  margin: 8px 2px 2px;
  color: var(--muted);
  font-size: 0.85rem;
}

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


/* -------------------------------------------------------------------------- */
/* Guess history                                                              */
/* -------------------------------------------------------------------------- */

.guesses {
  display: grid;
  gap: 6px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}

.guess-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 6px 12px;
  border-radius: 9px;
  background: #f3f1ec;
  font-size: 0.88rem;
}

.guess-row.empty {
  background: var(--empty);
  color: #a19c94;
}

.guess-row.wrong {
  color: #55514b;
}

.guess-row.partial {
  background: #f3ead0;
  color: #604d1d;
}

.guess-row.correct {
  background: #dcecdf;
  color: #24553f;
}

.guess-number {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  text-align: center;
}

.guess-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.guess-status {
  min-width: 72px;
  text-align: center;
  font-size: 0.67rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.guess-status small {
  display: block;
  margin-top: 2px;
  color: inherit;
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0;
  opacity: 0.72;
  text-transform: none;
}

.guess-row.wrong .guess-status {
  color: var(--wrong);
}

.guess-row.partial .guess-status {
  color: var(--partial);
}

.guess-row.correct .guess-status {
  color: var(--success);
}

.guess-row.empty .guess-status {
  color: #aaa59d;
}

.guess-row .attempt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
}


/* -------------------------------------------------------------------------- */
/* Result                                                                     */
/* -------------------------------------------------------------------------- */

.result {
  margin-top: 14px;
  padding: 16px;
  border-radius: 12px;
  background: #eef4ef;
  text-align: center;
}

.result-kicker {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.result h2 {
  margin: 0;
  font-size: clamp(1.3rem, 5vw, 1.75rem);
  letter-spacing: -0.03em;
}

.result p:not(.result-kicker) {
  margin: 5px 0 14px;
  color: var(--muted);
  font-size: 0.88rem;
}

.secondary-button {
  min-height: 42px;
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(46, 107, 78, 0.35);
}

.secondary-button:hover {
  background: rgba(46, 107, 78, 0.08);
}


/* -------------------------------------------------------------------------- */
/* Footer                                                                     */
/* -------------------------------------------------------------------------- */

.game-footer {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.game-footer a:hover {
  color: var(--text);
}


/* -------------------------------------------------------------------------- */
/* Dialogs                                                                    */
/* -------------------------------------------------------------------------- */

dialog {
  width: min(92vw, 430px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  box-shadow:
    0 25px 70px
    rgba(0, 0, 0, 0.2);
}

dialog::backdrop {
  background: rgba(20, 18, 15, 0.45);
  backdrop-filter: blur(2px);
}

.dialog-inner {
  position: relative;
  padding: 28px;
}

.dialog-inner h2 {
  margin: 5px 0 12px;
  font-size: 1.5rem;
}

.dialog-inner p {
  color: #55514b;
  line-height: 1.55;
}

.dialog-small {
  font-size: 0.82rem;
}

.dialog-close {
  position: absolute;
  top: 18px;
  right: 18px;
}


/* -------------------------------------------------------------------------- */
/* Report dialog                                                              */
/* -------------------------------------------------------------------------- */

.report-puzzle-id {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f3f1ec;
}

.report-puzzle-id-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.report-puzzle-id code {
  color: var(--text);
  font-family:
    ui-monospace,
    SFMono-Regular,
    Menlo,
    Consolas,
    monospace;
  font-size: 0.82rem;
  font-weight: 700;
}

.report-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  margin-top: 18px;
  padding: 0 16px;
  border-radius: 11px;
  background: var(--accent);
  color: white;
  font-size: 0.9rem;
  font-weight: 750;
  text-decoration: none;
}

.report-link:hover {
  background: var(--accent-dark);
}


/* -------------------------------------------------------------------------- */
/* Statistics                                                                 */
/* -------------------------------------------------------------------------- */

.stats-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 18px 0 24px;
}

.stats-stat {
  padding: 10px 6px;
  border-radius: 10px;
  background: #f3f1ec;
  text-align: center;
}

.stats-stat strong {
  display: block;
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1.1;
}

.stats-stat span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stats-distribution {
  display: grid;
  gap: 6px;
}

.stats-distribution h3 {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stats-distribution-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  min-height: 22px;
}

.stats-distribution-number {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 750;
  text-align: right;
}

.stats-bar-track {
  position: relative;
  height: 20px;
  overflow: hidden;
  border-radius: 4px;
  background: #f0eee9;
}

.stats-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
  height: 100%;
  padding: 0 7px;
  border-radius: 4px;
  background: var(--accent);
  color: white;
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 1;
  transition: width 250ms ease;
}

.stats-bar span {
  white-space: nowrap;
}

@media (max-width: 520px) {
  .stats-summary {
    gap: 5px;
  }

  .stats-stat {
    padding: 9px 3px;
  }

  .stats-stat strong {
    font-size: 1.1rem;
  }

  .stats-stat span {
    font-size: 0.56rem;
  }
}


/* -------------------------------------------------------------------------- */
/* Accessibility                                                              */
/* -------------------------------------------------------------------------- */

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


/* -------------------------------------------------------------------------- */
/* Animation                                                                  */
/* -------------------------------------------------------------------------- */

.shake {
  animation: shake 260ms ease-in-out;
}

.pop {
  animation: pop 220ms ease-out;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  75% {
    transform: translateX(5px);
  }
}

@keyframes pop {
  0% {
    transform: scale(0.98);
    opacity: 0.4;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}


/* -------------------------------------------------------------------------- */
/* Mobile                                                                     */
/* -------------------------------------------------------------------------- */

@media (max-width: 520px) {
  .game-shell {
    width: min(100% - 16px, 760px);
    padding-top: 10px;
  }

  .game-header {
    padding-bottom: 8px;
  }

  .game-modes {
    padding-bottom: 10px;
  }

  .game-card {
    padding: 10px;
    border-radius: 14px;
  }

  .image-frame {
    aspect-ratio: 4 / 3;
    border-radius: 9px;
  }

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

  .guess-form > button {
    width: 100%;
  }

  .suggestions {
    max-height: 240px;
  }

  .suggestion {
    min-height: 44px;
    padding: 9px 11px;
  }

  .guess-row {
    grid-template-columns: 24px minmax(0, 1fr) auto;
    gap: 6px;
    padding: 6px 10px;
  }

  .guess-status {
    min-width: auto;
  }

  .guess-status small {
    display: none;
  }

  .guess-row .attempt {
    display: none;
  }

  .game-footer {
    padding-bottom: 8px;
  }
}

.game-source-link,
.result-source-link {
  color: inherit;
  text-decoration: none;
}

.game-source-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.game-source-link:hover,
.result-source-link:hover {
  text-decoration: underline;
}

.external-link-icon {
  width: 0.78em;
  height: 0.78em;
  flex: 0 0 auto;
}

.result-source-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.result-source-link .external-link-icon {
  width: 0.7em;
  height: 0.7em;
}
