:root {
  --primary: #e7508f;
  --primary-dark: #b43e70;
  --primary-soft: #fdeef4;
  --secondary: #04758c;
  --secondary-soft: #e6fafe;
  --bg: #fdf6f8;
  --surface: #ffffff;
  --surface-soft: #fdf1f5;
  --ink: #2b1f28;
  --muted: #75656e;
  --line: #f0dde4;
  --warning: #846901;
  --warning-bg: #fff8e0;
  --danger: #dc3f4f;
  --danger-bg: #fdedef;
  --success: #168f63;

  --radius-card: 16px;
  --radius-control: 10px;
  --radius-pill: 999px;

  --shadow-card: 0 14px 40px rgba(180, 62, 112, 0.10);

  --font-heading: "Baloo 2", ui-rounded, "SF Pro Rounded", sans-serif;
  --font-body: "Nunito", ui-sans-serif, system-ui, sans-serif;
  --font-arabic: "Amiri", serif;
}

* {
  box-sizing: border-box;
}

html {
  scrollbar-gutter: stable;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 {
  font-family: var(--font-heading);
  font-weight: 800;
  margin: 0;
  color: var(--ink);
}

p {
  margin: 0;
}

/* consistent keyboard-focus ring across all interactive elements (buttons,
   pills, links) — brand-tinted instead of leaving the browser default */
.btn:focus-visible,
.pill:focus-visible,
.mcq-btn:focus-visible,
.link-card:focus-visible,
.back-link:focus-visible,
.exit-game-btn:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

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

a {
  color: var(--primary-dark);
  text-decoration: none;
}

#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px;
}

/* ---- buttons ---- */

.btn {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 15px;
  border-radius: var(--radius-control);
  border: 2px solid transparent;
  padding: 12px 18px;
  min-height: 44px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--primary-dark);
  color: #ffffff;
}

.btn-primary:hover {
  box-shadow: 0 8px 20px rgba(180, 62, 112, 0.25);
}

.btn-primary:disabled {
  background: var(--line);
  color: var(--muted);
  cursor: not-allowed;
  box-shadow: none;
}

.btn-outline {
  background: var(--surface);
  color: var(--primary-dark);
  border-color: var(--line);
}

.btn-outline:hover {
  border-color: var(--primary-dark);
}

.btn-large {
  width: 100%;
  font-size: 16px;
  padding: 14px 20px;
}

.back-link {
  display: inline-block;
  color: var(--primary-dark);
  font-weight: 700;
  margin-bottom: 14px;
}

/* ---- pill selector ---- */

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.pill {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 14px;
  border-radius: var(--radius-pill);
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 12px 14px;
  min-height: 44px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.pill:hover {
  border-color: var(--primary);
}

.pill-active {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  color: #ffffff;
}

/* ---- hub view ---- */

.hub-header {
  text-align: center;
  margin-bottom: 22px;
}

.hub-title {
  font-size: 32px;
  margin-bottom: 8px;
}

.hub-subtitle {
  color: var(--muted);
  font-weight: 600;
  font-size: 16px;
}

.offline-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--secondary-soft);
  border: 1px solid #c9edf5;
  border-radius: var(--radius-card);
  padding: 16px 18px;
  margin-bottom: 22px;
}

.offline-banner-text {
  flex: 1;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.offline-banner-text strong {
  font-family: var(--font-heading);
  font-size: 15px;
  color: var(--ink);
}

.offline-banner-text span {
  font-size: 13px;
  color: var(--muted);
}

.offline-banner .btn {
  flex: none;
}

.offline-banner-ready {
  background: #e9f9f0;
  border-color: #bdebd2;
}

.offline-banner-error {
  background: var(--danger-bg);
  border-color: #f5c2c8;
}

.offline-banner-stale {
  background: var(--warning-bg);
  border-color: #f0e0a8;
}

.offline-progress-bar {
  width: 100%;
  flex-basis: 100%;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  overflow: hidden;
}

.offline-progress-fill {
  width: 100%;
  height: 100%;
  background: var(--secondary);
  border-radius: var(--radius-pill);
  transform-origin: left;
  transition: transform 0.2s ease;
}

.hub-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.link-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 18px;
  box-shadow: var(--shadow-card);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.link-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 44px rgba(180, 62, 112, 0.16);
}

.link-card-special {
  border: 2px solid var(--secondary);
  background: var(--secondary-soft);
}

.link-card-icon {
  flex: none;
  width: 50px;
  height: 50px;
  border-radius: 14px;
  background: var(--primary-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
}

.link-card-special .link-card-icon {
  background: var(--surface);
}

.link-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.link-card-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
}

.link-card-subtitle {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-card-arrow {
  flex: none;
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 18px;
}

/* ---- setup view ---- */

.setup-view {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.setup-title {
  font-size: 26px;
}

.setup-subtitle {
  color: var(--muted);
  font-weight: 600;
}

.setup-controls {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

.setup-names {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.name-input {
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  padding: 12px 14px;
  min-height: 44px;
  border-radius: var(--radius-control);
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.name-input:focus {
  outline: none;
  border-color: var(--primary);
}

.name-input::placeholder {
  color: var(--muted);
}

/* ---- cheatsheet view ---- */

.cheatsheet-title {
  font-size: 24px;
  margin-bottom: 18px;
}

.cheatsheet-section {
  margin-bottom: 22px;
}

.cheatsheet-section-title {
  font-size: 18px;
  margin-bottom: 10px;
}

.cheatsheet-table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.cheatsheet-table {
  width: 100%;
  border-collapse: collapse;
}

.cheatsheet-table th {
  text-align: left;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 13px;
  color: var(--primary-dark);
  background: var(--surface-soft);
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.cheatsheet-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  font-size: 14px;
}

.cheatsheet-table tr:last-child td {
  border-bottom: none;
}

.cheat-visual-emoji {
  font-size: 22px;
}

.cheat-visual-arabic {
  font-family: var(--font-arabic);
  font-size: 22px;
}

.cheat-visual-photo {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-control);
  object-fit: cover;
  display: block;
}

/* card-stack collapse below 640px */
@media (max-width: 640px) {
  .cheatsheet-table thead {
    display: none;
  }

  .cheatsheet-table, .cheatsheet-table tbody, .cheatsheet-table tr, .cheatsheet-table td {
    display: block;
    width: 100%;
  }

  .cheatsheet-table tr {
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
  }

  .cheatsheet-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 6px 0;
    border-bottom: none;
    text-align: right;
  }

  .cheatsheet-table td::before {
    content: attr(data-label);
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 12px;
    color: var(--primary-dark);
    text-align: left;
  }
}

/* ---- game view ---- */

.error-msg {
  background: var(--danger-bg);
  color: var(--danger);
  font-weight: 700;
  padding: 16px;
  border-radius: var(--radius-control);
  margin-bottom: 14px;
}

.game-view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.game-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.progress-label {
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 14px;
}

.exit-game-btn {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: none;
  padding: 8px 10px;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-control);
}

.exit-game-btn:hover {
  color: var(--danger);
  background: var(--danger-bg);
}

.progress-bar {
  width: 100%;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-soft);
  overflow: hidden;
}

.progress-bar-fill {
  width: 100%;
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-pill);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.25s ease;
}

.score-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.score-chip {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
}

.turn-indicator {
  background: var(--secondary-soft);
  color: var(--secondary);
  font-weight: 700;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: var(--radius-control);
}

.turn-indicator strong {
  color: var(--secondary);
}

.question-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
}

.question-visual {
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.visual-emoji {
  font-size: 88px;
  line-height: 1;
}

.visual-arabic {
  font-family: var(--font-arabic);
  font-size: 72px;
  line-height: 1.6;
  max-width: 100%;
  word-spacing: 4px;
}

.visual-photo-main {
  width: 100%;
  max-width: 280px;
  height: 190px;
  border-radius: var(--radius-card);
  object-fit: cover;
  box-shadow: var(--shadow-card);
}

.visual-photo-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.visual-photo-currency {
  width: 100%;
  max-width: 260px;
  height: 130px;
  border-radius: var(--radius-card);
  object-fit: cover;
  box-shadow: var(--shadow-card);
}

.currency-chips {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.currency-chip {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 18px;
  padding: 12px 18px;
  border-radius: var(--radius-control);
  color: #ffffff;
}

.currency-chip-0 {
  background: var(--primary-dark);
}

.currency-chip-1 {
  background: var(--secondary);
}

.currency-chip-2 {
  background: var(--success);
}

.question-prompt {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 19px;
  color: var(--ink);
}

.mcq-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  width: 100%;
}

.mcq-btn {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 15px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 12px 16px;
  min-height: 44px;
  cursor: pointer;
  color: var(--ink);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.mcq-btn:hover:not(:disabled) {
  border-color: var(--primary);
}

.mcq-btn:disabled {
  cursor: default;
}

.mcq-correct {
  background: var(--success);
  border-color: var(--success);
  color: #ffffff;
}

.mcq-wrong {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

.typing-boxes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 14px;
}

.typing-box {
  width: 40px;
  height: 48px;
  border-radius: var(--radius-control);
  border: 2px solid var(--line);
  text-align: center;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 18px;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

input.typing-box:focus {
  outline: none;
  border-color: var(--primary);
}

.typing-box-fixed {
  background: var(--surface-soft);
  color: var(--muted);
  border-style: dashed;
}

.typing-box-full {
  width: 100%;
  height: auto;
  min-height: 52px;
  padding: 12px 14px;
  font-size: 16px;
  text-align: left;
  margin-bottom: 14px;
}

.typing-box-full::placeholder {
  color: var(--muted);
  font-weight: 400;
}

.typing-feedback {
  font-weight: 700;
  padding: 12px 14px;
  border-radius: var(--radius-control);
  margin-bottom: 10px;
}

.feedback-correct {
  background: var(--success);
  color: #ffffff;
}

.feedback-wrong {
  background: var(--danger-bg);
  color: var(--danger);
}

#feedback-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---- result view ---- */

.result-view {
  display: flex;
  flex-direction: column;
  gap: 22px;
  align-items: center;
  text-align: center;
  padding-top: 12px;
}

.result-callout {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 28px 20px;
  width: 100%;
}

.result-score {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 48px;
  color: var(--primary-dark);
  margin-bottom: 10px;
}

.result-scoreboard {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.result-message {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 18px;
  color: var(--ink);
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
}

/* ---- responsive ---- */

@media (max-width: 720px) {
  .hub-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 480px) {
  #app {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  .mcq-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .hub-title {
    font-size: 26px;
  }
}
