* {
  box-sizing: border-box;
}

:root {
  --bg: #f6efe4;
  --bg-2: #f2e2cc;
  --card: #fffdf8;
  --line: #e7d7bc;
  --text: #352515;
  --muted: #7b6145;
  --cta: #ef7c39;
  --cta-2: #d95c2f;
  --ok: #2f9e44;
  --err: #c92a2a;
}

body {
  margin: 0;
  color: var(--text);
  font-family: Inter, Segoe UI, Arial, sans-serif;
  line-height: 1.35;
  background: linear-gradient(180deg, var(--bg-2) 0, var(--bg) 45%, #fbf6ee 100%);
}

body.theme-dark {
  --bg: #101621;
  --bg-2: #0b111a;
  --card: #182231;
  --line: #2a3a4f;
  --text: #eaf1ff;
  --muted: #a9b7d0;
  --cta: #ff8a49;
  --cta-2: #ea6734;
  --ok: #4fcf74;
  --err: #ff6f6f;
  background: linear-gradient(180deg, #0a1018 0, #101621 45%, #121a26 100%);
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 0.9rem 0.8rem 5rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0.9rem;
  margin-bottom: 0.85rem;
  box-shadow: 0 10px 24px rgba(120, 76, 34, 0.08);
}

.card h2 {
  margin: 0 0 0.75rem;
}

.hero h1 {
  margin: 0;
  font-size: 1.75rem;
}

.hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.icon-actions {
  display: flex;
  gap: 0.4rem;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  padding: 0;
  background: #f7e7d5;
  border: 1px solid #e6bf95;
  color: #6d4729;
  font-size: 1rem;
  font-weight: 700;
}

.icon-btn.active {
  background: linear-gradient(135deg, var(--cta), var(--cta-2));
  border-color: #d56a34;
  color: #fff;
}

.subtitle {
  margin: 0.2rem 0 0.55rem;
  color: var(--muted);
  font-size: 0.95rem;
}

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

.stat {
  border: 1px solid #f3ceb2;
  border-radius: 14px;
  padding: 0.38rem 0.62rem;
  background: #fff4e7;
  min-width: 5.8rem;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

.settings-row {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.2rem;
}

.theme-toggle {
  display: flex;
  gap: 0.35rem;
  padding: 0.2rem;
  border: 1px solid #dfc7aa;
  border-radius: 12px;
  background: #fff8f0;
}

.theme-option {
  flex: 1 1 0;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  padding: 0.55rem 0.7rem;
}

.theme-option.active {
  background: linear-gradient(135deg, var(--cta), var(--cta-2));
  color: #fff;
  border-color: #d56a34;
}

select {
  width: 100%;
  border: 1px solid #dfc7aa;
  border-radius: 12px;
  background-color: #fff8f0;
  background-image:
    linear-gradient(45deg, transparent 50%, #8e6a45 50%),
    linear-gradient(135deg, #8e6a45 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% + 1px),
    calc(100% - 12px) calc(50% + 1px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  appearance: none;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.62rem 2rem 0.62rem 0.7rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

option {
  font-family: inherit;
  color: var(--text);
  background: #fff9f1;
}

.stat strong {
  font-size: 0.95rem;
  display: block;
  line-height: 1.1;
}

.words {
  display: grid;
  gap: 0.65rem;
  grid-template-columns: 1fr 1fr;
}

.words strong,
#currentWord {
  font-size: 1.35rem;
}

.status-line {
  margin-bottom: 0.55rem;
}

.progress-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.status-line.compact {
  margin-bottom: 0.2rem;
}

#guessForm {
  margin: 0.6rem 0;
}

input {
  width: 100%;
  border: 1px solid #dfc7aa;
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font-size: 1rem;
  padding: 0.78rem 0.85rem;
}

input::placeholder {
  color: #9b7b5b;
  opacity: 1;
  font-style: italic;
}

button {
  border: none;
  border-radius: 12px;
  padding: 0.78rem 0.95rem;
  color: #fff;
  background: #93775a;
  font-weight: 600;
  cursor: pointer;
}

input,
select,
button {
  font-family: inherit;
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid rgba(239, 124, 57, 0.45);
  outline-offset: 2px;
}

button.cta {
  background: linear-gradient(135deg, var(--cta), var(--cta-2));
}

button.ghost {
  background: #f7e7d5;
  border: 1px solid #e6bf95;
  color: #6d4729;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.primary-actions button {
  flex: 1 1 0;
}

#playAgainBtn[hidden] {
  display: none;
}

#shareResultsBtn[hidden] {
  display: none;
}

#playAgainBtn {
  width: 100%;
}

#shareResultsBtn {
  width: 100%;
}

#setupRetryBtn[hidden],
#setupEnableBtn[hidden] {
  display: none;
}

#message {
  min-height: 1.3rem;
  margin: 0.75rem 0 0.55rem;
  font-weight: 600;
}

#message[data-tone="error"] {
  color: var(--err);
}

#message[data-tone="ok"] {
  color: var(--ok);
}

details {
  margin-top: 0.75rem;
}

summary {
  cursor: pointer;
  color: var(--muted);
}

#diagnostics {
  margin-top: 0.5rem;
  padding: 0.6rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff8ee;
  color: #6d4a28;
  min-height: 2rem;
  max-height: 9rem;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 0.77rem;
}

#trailList {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

#trailList li {
  background: #ffe9d3;
  border: 1px solid #f2c79a;
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  color: #6d4729;
  font-weight: 600;
  letter-spacing: 0.01em;
}

#dailyResultCard[hidden] {
  display: none;
}

.daily-scale {
  display: flex;
  align-items: flex-end;
  gap: 0.35rem;
  min-height: 4.2rem;
}

.daily-scale-box {
  padding: 0.45rem;
  border-radius: 12px;
  border: 1px solid #f1d3b3;
  background: #fffcf8;
  display: grid;
  gap: 0.28rem;
}

.scale-bucket {
  flex: 1 1 0;
  display: grid;
  gap: 0.2rem;
  align-items: end;
}

.scale-bar {
  width: 100%;
  min-height: 8px;
  border-radius: 6px 6px 0 0;
  background: #f2c79b;
}

.scale-bar.current {
  background: var(--cta);
}

.scale-label {
  display: block;
  text-align: center;
  font-size: 0.64rem;
  color: #9a7a5a;
  line-height: 1.1;
}

.daily-scale-axis {
  margin: 0;
  text-align: center;
  color: #8d7051;
  font-size: 0.76rem;
  line-height: 1.2;
}

.daily-result-modal {
  position: fixed;
  inset: 0;
  background: rgba(33, 20, 9, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1250;
}

.daily-result-modal.hidden {
  display: none;
}

.daily-result-modal-card {
  width: min(92vw, 390px);
  display: grid;
  gap: 0.85rem;
  padding: 1.15rem;
  border: 1px solid #e6bf95;
  background: linear-gradient(180deg, #fffaf3 0%, #fff6ea 100%);
}

#dailyResultModal h2 {
  margin: 0;
  font-size: 1.35rem;
  color: #4f341f;
}

#dailyModalSummary {
  margin: 0;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  border: 1px solid #f1c79f;
  background: #fff0de;
  color: #5f3e22;
  font-weight: 700;
  line-height: 1.45;
}

#dailyModalLeaderboard {
  margin: 0;
  color: #6d4a28;
  font-size: 0.96rem;
  line-height: 1.45;
}

#dailyTopSolution,
#dailyModalTopSolution {
  margin: 0;
  color: #6d4a28;
  font-size: 0.92rem;
  line-height: 1.45;
}

.top-solution-box {
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px solid #f2d9bf;
  background: #fff9f2;
  display: grid;
  gap: 0.4rem;
}

.top-solution-trail {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.top-solution-trail li {
  background: #ffe9d3;
  border: 1px solid #f2c79a;
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  color: #6d4729;
  font-weight: 600;
  font-size: 0.83rem;
  letter-spacing: 0.01em;
}

.daily-result-actions {
  margin-top: 0.25rem;
}

.daily-result-actions button {
  flex: 1 1 0;
}

@media (max-width: 480px) {
  .daily-result-actions button {
    flex: 1 1 100%;
  }
}

.thinking-modal {
  position: fixed;
  inset: 0;
  background: rgba(33, 20, 9, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.thinking-modal.hidden {
  display: none;
}

.setup-modal {
  position: fixed;
  inset: 0;
  background: rgba(33, 20, 9, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1100;
}

.setup-modal.hidden {
  display: none;
}

.welcome-modal {
  position: fixed;
  inset: 0;
  background: rgba(33, 20, 9, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1200;
}

.welcome-modal.hidden {
  display: none;
}

.welcome-card {
  width: min(92vw, 390px);
}

.welcome-card h2 {
  margin: 0 0 0.5rem;
}

.welcome-card p {
  margin: 0 0 0.6rem;
  color: #6d4a28;
}

.welcome-points {
  margin: 0 0 0.7rem;
  padding-left: 1.1rem;
  color: #6d4a28;
}

.welcome-points li {
  margin: 0 0 0.28rem;
}

.welcome-card button {
  width: 100%;
}

.setup-card {
  width: min(92vw, 390px);
  display: grid;
  gap: 0.65rem;
}

.modal-card {
  border-radius: 16px;
  border: 1px solid #e9c49f;
  background: #fff9f1;
  padding: 1rem;
  box-shadow: 0 14px 32px rgba(67, 38, 12, 0.18);
}

.setup-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.1rem;
}

.setup-card h2 {
  margin: 0;
  color: #4f341f;
  font-size: 1.2rem;
  letter-spacing: 0.01em;
}

#setupMessage {
  margin: 0;
  color: #6d4a28;
  font-size: 0.95rem;
}

.setup-card .label {
  font-weight: 600;
}

#setupMessage[data-tone="error"] {
  color: var(--err);
}

.thinking-card {
  width: min(90vw, 300px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
}

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid #f5d6b7;
  border-top-color: var(--cta);
  animation: spin 1s linear infinite;
}

.spinner.paused {
  animation-play-state: paused;
  border-top-color: #e6c19c;
}

.setup-head .spinner {
  width: 20px;
  height: 20px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (min-width: 700px) {
  .stats {
    justify-content: flex-start;
  }
}

body.theme-dark .card {
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
}

body.theme-dark .icon-btn,
body.theme-dark button.ghost {
  background: #223146;
  border-color: #334760;
  color: #d3def0;
}

body.theme-dark .stat {
  border-color: #334760;
  background: #1f2d41;
  box-shadow: inset 0 0 0 1px rgba(15, 22, 31, 0.5);
}

body.theme-dark select {
  border-color: #334760;
  background-color: #1b283a;
  background-image:
    linear-gradient(45deg, transparent 50%, #9fb3d7 50%),
    linear-gradient(135deg, #9fb3d7 50%, transparent 50%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

body.theme-dark option {
  background: #1b283a;
}

body.theme-dark .theme-toggle {
  border-color: #334760;
  background: #1b283a;
}

body.theme-dark .theme-option {
  color: #b9c7de;
}

body.theme-dark .theme-option.active {
  color: #fff;
}

body.theme-dark input {
  border-color: #334760;
  background: #1b283a;
}

body.theme-dark input::placeholder {
  color: #8ea1c2;
}

body.theme-dark #diagnostics,
body.theme-dark .daily-scale-box,
body.theme-dark .top-solution-box,
body.theme-dark .modal-card,
body.theme-dark .daily-result-modal-card {
  border-color: #334760;
  background: #172335;
  color: var(--text);
}

body.theme-dark .scale-bar {
  background: #395271;
}

body.theme-dark .scale-label,
body.theme-dark .daily-scale-axis,
body.theme-dark #dailyResultModal h2,
body.theme-dark #dailyModalLeaderboard,
body.theme-dark #dailyTopSolution,
body.theme-dark #dailyModalTopSolution,
body.theme-dark .welcome-card p,
body.theme-dark .welcome-points,
body.theme-dark #setupMessage {
  color: var(--muted);
}

body.theme-dark #dailyModalSummary {
  border-color: #3a5070;
  background: #223146;
  color: var(--text);
}

body.theme-dark #trailList li,
body.theme-dark .top-solution-trail li {
  background: #223146;
  border-color: #3a5070;
  color: #dce6f8;
}

body.theme-dark .daily-result-modal,
body.theme-dark .setup-modal,
body.theme-dark .welcome-modal,
body.theme-dark .thinking-modal {
  background: rgba(4, 8, 14, 0.66);
}

body.theme-dark .spinner {
  border-color: #334760;
  border-top-color: var(--cta);
}
