:root {
  color-scheme: light;
  --ink: #12202d;
  --muted: #52606d;
  --paper: #f7f3ea;
  --card: #fffdf8;
  --line: #d9d1c1;
  --accent: #f5b642;
  --accent-dark: #8f4e0c;
  --error: #a43d35;
  --input: #fff;
  --on-ink: #fff;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #edf3f8;
  --muted: #b8c3cf;
  --paper: #101820;
  --card: #172431;
  --line: #3b4c5d;
  --accent-dark: #ffd36c;
  --error: #ff9086;
  --input: #0d1720;
  --on-ink: #12202d;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--accent-dark);
  outline-offset: 3px;
}

.game-shell {
  width: min(100% - 2rem, 42rem);
  margin: 0 auto;
  padding: 3rem 0;
}

.game-header {
  position: relative;
  margin-bottom: 1.5rem;
}

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

.primary-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.primary-nav[hidden] {
  display: none !important;
}

.primary-nav[hidden] + .account-actions {
  margin-left: auto;
}

.account-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.primary-nav a,
.profile-action {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--card);
  color: var(--ink);
  font-size: 0.85rem;
  text-decoration: none;
}

.primary-nav a[aria-current="page"],
.profile-action[aria-current="page"] {
  border-color: var(--accent-dark);
  background: var(--accent);
}

.profile-action {
  white-space: nowrap;
}

.theme-toggle {
  display: grid;
  width: 2.5rem;
  height: 2.5rem;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--ink);
}

.theme-toggle:hover {
  background: var(--accent);
}

.profile-action:hover {
  background: var(--accent);
}

.profile-action:disabled {
  cursor: default;
  opacity: 0.8;
}

.theme-toggle svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.theme-toggle .sun-icon {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .moon-icon {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .sun-icon {
  display: block;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent-dark);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  margin-bottom: 0.5rem;
  line-height: 1.1;
}

h1 {
  font-size: clamp(2.35rem, 10vw, 4.5rem);
  letter-spacing: -0.06em;
}

h2 {
  font-size: clamp(1.35rem, 4vw, 1.8rem);
}

.intro {
  max-width: 36rem;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.game-card {
  position: relative;
  padding: clamp(1rem, 4vw, 2rem);
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--card);
  box-shadow: 0 1rem 2.5rem rgb(18 32 45 / 0.08);
}

.card-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card-heading h2 {
  margin-bottom: 0;
}

.card-heading-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.attempts {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: right;
}

.canvas-frame {
  display: grid;
  min-height: 7rem;
  place-items: center;
  overflow: hidden;
  padding: 1rem;
  border: 1px solid #3b4c5d;
  background: #172431;
}

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

.status {
  min-height: 1.5rem;
  margin: 1rem 0 0.25rem;
  color: var(--muted);
}

.status.is-correct {
  color: #00ff00;
  font-weight: 800;
}

.settings-button {
  display: grid;
  width: 2.5rem;
  height: 2.5rem;
  place-items: center;
  padding: 0.55rem;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
}

.settings-button:hover {
  background: var(--accent);
  color: var(--ink);
}

.settings-button svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.settings-dialog {
  width: min(calc(100% - 2rem), 26rem);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 1rem 3rem rgb(18 32 45 / 0.2);
}

.settings-dialog::backdrop {
  background: rgb(18 32 45 / 0.45);
}

.settings-dialog form {
  padding: 1.5rem;
}

.settings-dialog h2 {
  margin-bottom: 0.25rem;
}

.settings-note {
  margin-bottom: 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.settings-dialog fieldset {
  display: grid;
  gap: 0.65rem;
  margin: 0 0 1.25rem;
  padding: 0;
  border: 0;
}

.settings-dialog legend {
  margin-bottom: 0.55rem;
  font-weight: 800;
}

.settings-dialog label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.settings-dialog input[type="radio"] {
  flex: 0 0 auto;
  accent-color: var(--accent-dark);
}

.profile-label {
  display: block;
  margin-bottom: 0.45rem;
  font-weight: 750;
}

.profile-dialog input {
  width: 100%;
}

.profile-status {
  min-height: 1.5rem;
  margin: 0.5rem 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.leaderboard-list,
.profile-stats {
  margin: 1.5rem 0 0;
  padding: 0;
}

.leaderboard-list {
  display: grid;
  gap: 0.5rem;
  list-style: none;
}

.leaderboard-list li,
.profile-stats > div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  background: var(--canvas);
}

.leaderboard-player {
  display: flex;
  align-items: baseline;
  min-width: 0;
  gap: 0.75rem;
}

.leaderboard-rank {
  min-width: 2rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.leaderboard-xp,
.profile-stats dd {
  margin: 0;
  color: var(--muted);
  font-weight: 750;
}

.profile-stats {
  display: grid;
  gap: 0.5rem;
}

.profile-stats dt {
  font-weight: 800;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
}

.settings-cancel {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
}

.settings-cancel:hover {
  background: var(--paper);
}

.guess-form label {
  display: block;
  margin-bottom: 0.45rem;
  font-weight: 750;
}

.guess-controls {
  display: flex;
  gap: 0.65rem;
}

input {
  min-width: 0;
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.75rem 0.85rem;
  background: var(--input);
  color: var(--ink);
}

button {
  border: 0;
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--ink);
  color: var(--on-ink);
  font-weight: 750;
}

button:hover {
  background: var(--accent-dark);
}

.new-round {
  width: 100%;
  margin-top: 0.75rem;
  background: var(--accent);
  color: var(--ink);
}

.new-round:hover {
  background: #e6a42f;
}

@media (max-width: 480px) {
  .game-shell {
    padding: 2rem 0;
  }

  .game-header {
    padding-right: 0;
  }

  .header-actions {
    align-items: flex-start;
  }

  .primary-nav {
    flex-wrap: wrap;
  }

  .card-heading {
    align-items: start;
    flex-direction: column;
    gap: 0.4rem;
  }

  .attempts {
    text-align: left;
  }

  .guess-controls {
    flex-direction: column;
  }
}
