* {
  box-sizing: border-box;
}

@font-face {
  font-family: "SfArabic";
  src: url("/assests/sf-arabic-regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --background: #f8fbf8;
  --surface: #ffffff;
  --surface-alt: #f1f6f2;
  --text: #18221b;
  --muted: #617062;
  --border: #d8e1d9;
  --accent: #13795b;
  --accent-strong: #0c5f49;
  --accent-soft: #e5f4ed;
  --gold: #b87913;
  --gold-soft: #fff1ce;
  --danger: #b42318;
  --shadow: rgba(24, 34, 27, 0.12);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: "SfArabic", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  padding: 20px;
}

.game {
  width: min(100%, 900px);
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: clamp(18px, 4vw, 36px);
  box-shadow: 0 20px 50px var(--shadow);
}

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

.kicker {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.9rem;
  /* font-weight: 700; */
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 4.5rem;
  line-height: 1.05;
  letter-spacing: 0;
}

.icon-button,
button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.icon-button {
  width: 48px;
  flex: 0 0 48px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 1.7rem;
  line-height: 1;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 26px;
}

.summary > div,
.score-board {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  padding: 16px;
}

.metric-label,
.score-topline span,
.input-label,
.section-head span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
}

.metric-value {
  display: block;
  margin-top: 10px;
  font-size: 2.5rem;
  line-height: 1;
}

.word-value {
  overflow-wrap: anywhere;
  font-size: 1.8rem;
  line-height: 1.2;
}

.guess-form {
  margin-top: 26px;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  margin-top: 10px;
}

input {
  width: 100%;
  min-height: 56px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1.3rem;
  padding: 10px 16px;
  outline: 0;
}

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

.input-row button {
  background: var(--accent);
  color: #ffffff;
  /* font-weight: 700; */
  padding: 0 24px;
}

.voice-button {
  border: 1px solid var(--border);
  background: var(--accent-soft) !important;
  color: var(--accent-strong) !important;
  touch-action: none;
  user-select: none;
}

.voice-button.is-recording {
  background: var(--gold-soft) !important;
  color: var(--gold) !important;
}

.result-line {
  min-height: 32px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 1.1rem;
}

.score-board {
  margin-top: 16px;
}

.score-topline {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.latest-guess {
  min-width: 0;
}

.latest-guess b {
  display: block;
  margin-top: 8px;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1.2;
}

.score-topline strong {
  direction: ltr;
  font-size: 3.2rem;
  line-height: 1;
}

.score-track {
  height: 12px;
  margin-top: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe7e1;
}

.score-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 220ms ease;
}

.actions {
  display: flex;
  justify-content: flex-start;
  margin-top: 18px;
}

.secondary-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0 18px;
}

.history {
  margin-top: 28px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

h2 {
  margin: 0;
  font-size: 1.25rem;
}

ol {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--surface);
}

.guess-word {
  overflow-wrap: anywhere;
  font-size: 1.2rem;
  /* font-weight: 700; */
}

.guess-score,
.guess-trend {
  direction: ltr;
  color: var(--muted);
  /* font-weight: 700; */
}

.guess-score.best {
  color: var(--accent);
}

.guess-trend.up {
  color: var(--accent);
}

.guess-trend.down {
  color: var(--danger);
}

.guess-trend.same {
  color: var(--gold);
}

.celebration {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: hidden;
}

.celebration span {
  position: absolute;
  top: -18px;
  left: var(--left);
  width: 10px;
  height: 16px;
  border-radius: 3px;
  background: hsl(var(--hue), 82%, 54%);
  animation: confetti 1100ms cubic-bezier(0.2, 0.65, 0.25, 1) forwards;
  animation-delay: var(--delay);
  transform: translate3d(0, 0, 0) rotate(0deg);
}

.win-message {
  pointer-events: none;
  position: fixed;
  inset-inline: 20px;
  bottom: 20px;
  z-index: 11;
  display: grid;
  place-items: center;
  transform: translateY(150%);
  transition: transform 220ms ease;
}

.win-message.is-visible {
  transform: translateY(0);
}

.win-message div {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(100%, 520px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px 18px;
  box-shadow: 0 16px 40px var(--shadow);
}

.win-message strong {
  color: var(--accent);
  font-size: 1.3rem;
}

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

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

.is-revealed {
  color: var(--gold);
}

@keyframes confetti {
  100% {
    transform: translate3d(var(--x), 105vh, 0) rotate(720deg);
    opacity: 0;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 8px;
  }

  .game {
    min-height: calc(100vh - 16px);
    padding: 12px;
  }

  .game-header {
    align-items: center;
    gap: 10px;
  }

  .kicker {
    margin-bottom: 4px;
    font-size: 0.78rem;
  }

  h1 {
    font-size: 2.35rem;
  }

  .icon-button {
    width: 42px;
    min-height: 42px;
    flex-basis: 42px;
    font-size: 1.45rem;
  }

  .summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 14px;
  }

  .summary > div {
    min-height: 88px;
    padding: 10px;
  }

  .metric-label,
  .score-topline span,
  .input-label,
  .section-head span {
    font-size: 0.78rem;
    line-height: 1.35;
  }

  .metric-value {
    margin-top: 8px;
    font-size: 1.75rem;
  }

  .word-value {
    font-size: 1.3rem;
    line-height: 1.25;
  }

  .guess-form {
    margin-top: 16px;
  }

  input {
    min-height: 48px;
    font-size: 1.1rem;
    padding: 8px 12px;
  }

  .input-row {
    gap: 8px;
    margin-top: 8px;
  }

  .input-row button,
  .secondary-button {
    min-height: 46px;
  }

  .result-line {
    min-height: 26px;
    margin-top: 10px;
    font-size: 0.95rem;
  }

  .score-board {
    margin-top: 10px;
    padding: 12px;
  }

  .score-topline {
    gap: 10px;
  }

  .latest-guess b {
    margin-top: 6px;
    font-size: 1.25rem;
  }

  .score-topline strong {
    font-size: 2.2rem;
  }

  .score-track {
    height: 10px;
    margin-top: 10px;
  }

  .actions {
    margin-top: 10px;
  }

  .history {
    margin-top: 18px;
  }

  .section-head {
    padding-top: 14px;
  }

  ol {
    gap: 8px;
    margin-top: 10px;
  }

  .input-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .input-row input {
    grid-column: 1 / -1;
  }

  .input-row button {
    width: 100%;
    padding: 0 12px;
  }

  li {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .guess-trend {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #111612;
    --surface: #19211b;
    --surface-alt: #131a15;
    --text: #edf3ee;
    --muted: #a9b5aa;
    --border: #334036;
    --accent: #7dd8a2;
    --accent-strong: #a4edc1;
    --accent-soft: #173323;
    --gold: #f0c36a;
    --gold-soft: #3a2b0d;
    --danger: #ffb4ab;
    --shadow: rgba(0, 0, 0, 0.3);
  }

  .score-track {
    background: #2c372f;
  }
}
