/* ============================================================
   Jaweb Web — Saffron Mosaic Palette (matches iOS app)
   ============================================================ */

:root {
  /* Brand palette */
  --teal:           #2A9D8F;
  --teal-dark:      #1F7A6F;
  --teal-deep:      #13524A;
  --teal-light:     #5FBFB1;
  --coral:          #E76F51;
  --coral-dark:     #B85839;
  --coral-light:    #F2A48C;
  --saffron:        #F4A261;
  --indigo:         #264653;

  /* Surfaces (light mode) */
  --bg:             #F7F4EC;
  --bg-top:         #EAF7F3;
  --bg-bottom:      #FFF7EA;
  --surface:        #FFFFFF;
  --surface-elev:   #FFFDF8;
  --surface-alt:    #F2F6F2;

  /* Text */
  --text:           #17231F;
  --text-secondary: #66736D;
  --text-muted:     #8C9891;

  /* Lines */
  --border:         #E1DDD1;
  --separator:      #EEE8DB;

  /* State colors (semantic) */
  --correct:        #2E8B57;
  --wrong:          #C0392B;
  --hint:           #C97B0F;
  --surprise:       #B8860B;

  /* Difficulty */
  --easy:           #16B981;
  --medium:         #F4A52C;
  --hard:           #EF5350;

  /* Shadows */
  --shadow-sm:      0 1px 2px rgba(10, 26, 34, 0.06);
  --shadow-md:      0 4px 12px rgba(10, 26, 34, 0.08);
  --shadow-lg:      0 12px 32px rgba(10, 26, 34, 0.12);

  /* Radii (matches Theme.Radius) */
  --r-chip:         12px;
  --r-button:       18px;
  --r-card:         22px;
  --r-modal:        28px;
  --r-pill:         999px;

  /* Animation */
  --easing-calm:    cubic-bezier(0.22, 1, 0.36, 1);
  --easing-spring:  cubic-bezier(0.34, 1.56, 0.64, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:             #061915;
    --bg-top:         #0A2421;
    --bg-bottom:      #061915;
    --surface:        #0E2E2A;
    --surface-elev:   #143832;
    --surface-alt:    #1F3D38;
    --text:           #F4FBFA;
    --text-secondary: #9ED1C8;
    --text-muted:     #6FA59C;
    --border:         #1F4A42;
    --separator:      #143832;
  }
}

/* ============================================================
   Reset / base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'IBM Plex Sans Arabic', 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg) 50%, var(--bg-bottom) 100%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
html[lang="ar"] body { font-family: 'IBM Plex Sans Arabic', 'Noto Sans Arabic', system-ui, sans-serif; }
html[dir="rtl"] { text-align: right; }

button { font-family: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
img { max-width: 100%; height: auto; display: block; }

/* ============================================================
   Layout primitives
   ============================================================ */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.container  { width: 100%; max-width: 1100px; margin: 0 auto; padding: 0 20px; }

/* ============================================================
   Top app bar
   ============================================================ */
.appbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; gap: 12px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
@media (prefers-color-scheme: dark) {
  .appbar { background: rgba(10, 36, 33, 0.6); }
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text);
  font-weight: 800; font-size: 20px; letter-spacing: -0.01em;
}
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--teal) 0%, var(--coral) 100%);
  display: grid; place-items: center;
  color: white; font-weight: 800; font-size: 20px;
  box-shadow: var(--shadow-md);
}
.appbar-actions { display: flex; gap: 8px; align-items: center; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  border: 0; padding: 12px 22px;
  border-radius: var(--r-button);
  font-weight: 700; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 0.18s var(--easing-spring), box-shadow 0.18s ease, background-color 0.18s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--teal); color: white;
  box-shadow: var(--shadow-md);
}
.btn-primary:hover { background: var(--teal-dark); }
.btn-coral {
  background: var(--coral); color: white;
  box-shadow: var(--shadow-md);
}
.btn-coral:hover { background: var(--coral-dark); }
.btn-ghost {
  background: var(--surface-alt); color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-elev); }
.btn-pill { border-radius: var(--r-pill); padding: 10px 18px; font-size: 14px; }
.btn-large { padding: 16px 32px; font-size: 17px; }
.btn-icon { padding: 10px; min-width: 40px; min-height: 40px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ============================================================
   Card
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.card-elev { box-shadow: var(--shadow-md); }

/* ============================================================
   Landing / Hero
   ============================================================ */
.hero { padding: 60px 0 40px; text-align: center; }
.hero-eyebrow {
  display: inline-block;
  padding: 6px 14px; border-radius: var(--r-pill);
  background: rgba(42, 157, 143, 0.12); color: var(--teal-dark);
  font-size: 13px; font-weight: 700;
  margin-bottom: 16px;
}
.hero-title {
  font-size: clamp(36px, 6vw, 64px);
  font-weight: 800; letter-spacing: -0.02em; line-height: 1.05;
  margin: 0 0 16px;
  background: linear-gradient(135deg, var(--teal-deep) 0%, var(--coral-dark) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub {
  font-size: clamp(16px, 2vw, 19px);
  color: var(--text-secondary);
  max-width: 640px; margin: 0 auto 28px;
}
.hero-actions { display: inline-flex; flex-wrap: wrap; gap: 12px; justify-content: center; }

/* ============================================================
   Feature grid (landing)
   ============================================================ */
.features {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  margin: 40px 0 60px;
}
.feature {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-card); padding: 24px;
}
.feature-icon {
  width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center; font-size: 22px;
  margin-bottom: 14px;
}
.feature-icon.teal   { background: rgba(42, 157, 143, 0.14); color: var(--teal-dark); }
.feature-icon.coral  { background: rgba(231, 111, 81, 0.14); color: var(--coral-dark); }
.feature-icon.saffron{ background: rgba(244, 162, 97, 0.18); color: var(--hint); }
.feature h3 { margin: 0 0 6px; font-size: 18px; font-weight: 700; }
.feature p  { margin: 0; color: var(--text-secondary); font-size: 14px; }

/* ============================================================
   Setup screens (teams / categories)
   ============================================================ */
.screen { padding: 40px 0; }
.screen-title { font-size: 28px; font-weight: 800; margin: 0 0 6px; letter-spacing: -0.01em; }
.screen-sub   { color: var(--text-secondary); margin: 0 0 28px; }

.team-row {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  margin-bottom: 28px;
}
.team-input {
  padding: 24px; background: var(--surface);
  border: 2px solid var(--border); border-radius: var(--r-card);
  transition: border-color 0.2s ease;
}
.team-input.team-a { border-color: var(--teal); }
.team-input.team-b { border-color: var(--coral); }
.team-input label { display: block; font-size: 13px; font-weight: 700; color: var(--text-secondary); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.04em; }
.team-input input {
  width: 100%; padding: 14px 16px; font-size: 18px; font-weight: 700;
  border: 1px solid var(--border); border-radius: var(--r-button);
  background: var(--bg); color: var(--text);
  font-family: inherit;
}
.team-input input:focus { outline: none; border-color: var(--teal); }

/* Category picker grid */
.cat-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  margin-bottom: 24px;
}
.cat-card {
  position: relative; padding: 16px 12px;
  border-radius: var(--r-card); border: 2px solid var(--border);
  background: var(--surface); cursor: pointer;
  transition: transform 0.18s var(--easing-spring), border-color 0.18s ease, box-shadow 0.18s ease;
  text-align: center; min-height: 110px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
}
.cat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.cat-card.selected {
  border-color: var(--teal); background: var(--surface-elev);
  box-shadow: 0 0 0 4px rgba(42, 157, 143, 0.15);
}
.cat-card.disabled { opacity: 0.4; cursor: not-allowed; }
.cat-emoji { font-size: 30px; }
.cat-name { font-size: 13px; font-weight: 700; }
.cat-badge {
  position: absolute; top: 6px; inset-inline-end: 6px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--teal); color: white; font-size: 13px;
  display: grid; place-items: center; font-weight: 800;
}
.cat-card[data-team="a"] .cat-badge { background: var(--teal); }
.cat-card[data-team="b"] .cat-badge { background: var(--coral); }

.cat-count-bar {
  display: flex; gap: 16px; justify-content: center; align-items: center;
  margin-bottom: 16px; flex-wrap: wrap;
}
.cat-count-bar > span { font-weight: 700; }
.cat-count-bar .team-a-text { color: var(--teal-dark); }
.cat-count-bar .team-b-text { color: var(--coral-dark); }

/* ============================================================
   Board (game grid)
   ============================================================ */
.board-bar {
  display: grid; gap: 14px; margin-bottom: 22px;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}
.score-pill {
  background: var(--surface); border: 2px solid var(--border);
  border-radius: var(--r-pill); padding: 12px 22px;
  display: flex; align-items: center; gap: 10px;
  min-height: 56px;
}
.score-pill.team-a { border-color: var(--teal); }
.score-pill.team-b { border-color: var(--coral); }
.score-pill .name { font-weight: 700; font-size: 15px; }
.score-pill .pts { margin-inline-start: auto; font-weight: 800; font-size: 22px; }
.score-pill.team-a .pts { color: var(--teal-dark); }
.score-pill.team-b .pts { color: var(--coral-dark); }
.turn-indicator {
  text-align: center;
  font-size: 13px; font-weight: 700;
  padding: 8px 12px; border-radius: var(--r-pill);
  background: var(--surface-alt); color: var(--text-secondary);
}

.board {
  display: grid; gap: 10px;
  grid-template-columns: repeat(6, 1fr);
  margin-bottom: 24px;
}
.board-cat-head {
  text-align: center; font-weight: 700; font-size: 13px;
  padding: 10px 6px; border-radius: var(--r-button);
  background: var(--surface); border: 1px solid var(--border);
  min-height: 56px; display: grid; place-items: center;
  hyphens: auto;
}
.board-slot {
  height: 64px; border: 0; border-radius: var(--r-button);
  font-weight: 800; font-size: 18px;
  color: white;
  display: grid; place-items: center;
  background: var(--teal);
  cursor: pointer;
  transition: transform 0.18s var(--easing-spring), filter 0.18s ease, opacity 0.18s ease;
  box-shadow: var(--shadow-sm);
}
.board-slot:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.05); box-shadow: var(--shadow-md); }
.board-slot.easy   { background: var(--easy); }
.board-slot.medium { background: var(--medium); }
.board-slot.hard   { background: var(--hard); }
.board-slot.answered {
  background: var(--surface-alt); color: var(--text-muted);
  cursor: not-allowed; transform: none;
  text-decoration: line-through;
}
.board-slot.answered:disabled { opacity: 0.7; }
.board-slot.team-a-claimed { background: var(--teal); color: white; opacity: 0.55; }
.board-slot.team-b-claimed { background: var(--coral); color: white; opacity: 0.55; }

@media (max-width: 700px) {
  .board { grid-template-columns: repeat(3, 1fr); }
  .board-bar { grid-template-columns: 1fr 1fr; }
  .turn-indicator { grid-column: 1 / -1; }
}

/* ============================================================
   Question view
   ============================================================ */
.question-wrap {
  max-width: 760px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 18px;
}
.question-meta {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}
.cat-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: var(--r-pill);
  background: var(--surface-alt); font-weight: 700; font-size: 14px;
}
.points-chip {
  padding: 8px 14px; border-radius: var(--r-pill);
  background: var(--surface-alt); font-weight: 700; font-size: 14px;
}
.points-chip.easy   { background: rgba(22, 185, 129, 0.15); color: var(--correct); }
.points-chip.medium { background: rgba(244, 165, 44, 0.18); color: var(--hint); }
.points-chip.hard   { background: rgba(239, 83, 80, 0.15); color: var(--wrong); }

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-modal);
  padding: 36px 28px;
  text-align: center;
  position: relative;
  box-shadow: var(--shadow-md);
  min-height: 180px;
}
.question-card.critical { box-shadow: 0 0 0 4px rgba(184, 88, 57, 0.35), var(--shadow-md); }
.question-prompt {
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 700; line-height: 1.4;
  margin: 0;
  color: var(--text);
}

/* Timer */
.timer-shell { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.timer-row { display: flex; align-items: center; gap: 14px; }
.timer-display {
  font-size: 48px; font-weight: 800; font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em; color: var(--text);
}
.timer-display.critical { color: var(--coral-dark); }
.timer-display.timeup { color: var(--coral-dark); font-size: 28px; }
.timer-team-label {
  font-size: 13px; font-weight: 700; padding: 6px 14px;
  border-radius: var(--r-pill); background: var(--surface-alt);
}
.timer-team-label.team-a { background: rgba(42, 157, 143, 0.16); color: var(--teal-dark); }
.timer-team-label.team-b { background: rgba(231, 111, 81, 0.16); color: var(--coral-dark); }

.timer-bar {
  width: 100%; max-width: 600px;
  height: 6px; border-radius: 999px;
  background: var(--separator); overflow: hidden;
}
.timer-bar-fill {
  height: 100%; background: var(--teal);
  transition: width 0.4s linear, background-color 0.6s ease;
}
.timer-bar-fill.critical { background: var(--coral-dark); }

/* Answer reveal */
.answer-card {
  background: linear-gradient(135deg, var(--saffron), var(--coral));
  color: white;
  padding: 28px;
  border-radius: var(--r-card);
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.answer-card .label {
  font-size: 13px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.9; margin-bottom: 8px;
}
.answer-card .answer {
  font-size: clamp(22px, 3vw, 30px); font-weight: 800; margin: 0;
  line-height: 1.3;
}

/* Award buttons */
.award-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.award-btn {
  padding: 18px 14px; font-weight: 700; font-size: 15px;
  border-radius: var(--r-card); border: 2px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
  transition: transform 0.18s var(--easing-spring), border-color 0.18s ease, background 0.18s ease;
}
.award-btn:hover { transform: translateY(-2px); }
.award-btn.team-a:hover, .award-btn.team-a.focus { border-color: var(--teal); background: rgba(42, 157, 143, 0.08); }
.award-btn.team-b:hover, .award-btn.team-b.focus { border-color: var(--coral); background: rgba(231, 111, 81, 0.08); }
.award-btn.skip:hover { border-color: var(--text-muted); }
@media (max-width: 600px) {
  .award-row { grid-template-columns: 1fr; }
}

/* Choices (lifelines) */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 600px) { .choices { grid-template-columns: 1fr; } }
.choice-btn {
  padding: 14px; border-radius: var(--r-button);
  border: 2px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; font-weight: 600; font-size: 15px;
  text-align: center;
}
.choice-btn.correct { border-color: var(--correct); background: rgba(46, 139, 87, 0.12); }

/* Lifelines */
.lifelines { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.lifeline-btn {
  padding: 10px 16px; border-radius: var(--r-pill);
  border: 1px solid var(--border); background: var(--surface);
  font-weight: 700; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.lifeline-btn:hover:not(:disabled) { border-color: var(--teal); }
.lifeline-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============================================================
   Surprise question modal
   ============================================================ */
.surprise-veil {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(6, 25, 21, 0.85);
  backdrop-filter: blur(8px);
  display: grid; place-items: center;
  padding: 20px;
}
.surprise-card {
  max-width: 560px; width: 100%;
  background: linear-gradient(135deg, var(--saffron), var(--coral), var(--coral-dark));
  color: white;
  border-radius: var(--r-modal);
  padding: 36px 28px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: surpriseIn 0.6s var(--easing-spring);
}
@keyframes surpriseIn {
  from { transform: scale(0.85) translateY(20px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
.surprise-eyebrow {
  font-size: 13px; font-weight: 800; letter-spacing: 0.16em;
  text-transform: uppercase; opacity: 0.9; margin-bottom: 8px;
}
.surprise-title { font-size: 28px; font-weight: 800; margin: 0 0 16px; }

/* ============================================================
   Results screen
   ============================================================ */
.results-wrap {
  max-width: 700px; margin: 0 auto;
  text-align: center; display: flex; flex-direction: column; gap: 22px;
}
.winner-card {
  background: linear-gradient(135deg, var(--saffron), var(--coral));
  color: white; padding: 36px 24px;
  border-radius: var(--r-modal);
  box-shadow: var(--shadow-lg);
}
.winner-card.tie {
  background: linear-gradient(135deg, var(--teal), var(--indigo));
}
.winner-eyebrow { font-size: 13px; letter-spacing: 0.16em; text-transform: uppercase; font-weight: 800; opacity: 0.9; margin-bottom: 8px; }
.winner-name    { font-size: clamp(28px, 5vw, 42px); font-weight: 800; margin: 0; }
.score-summary {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.summary-cell {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-card); padding: 22px;
}
.summary-cell.team-a { border-color: var(--teal); }
.summary-cell.team-b { border-color: var(--coral); }
.summary-name { font-size: 14px; color: var(--text-secondary); font-weight: 600; }
.summary-score { font-size: 36px; font-weight: 800; margin-top: 4px; }
.summary-cell.team-a .summary-score { color: var(--teal-dark); }
.summary-cell.team-b .summary-score { color: var(--coral-dark); }

/* ============================================================
   Utilities
   ============================================================ */
.hidden { display: none !important; }
.text-muted  { color: var(--text-muted); }
.text-center { text-align: center; }
.row-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

/* Footer */
.footer {
  margin-top: auto; padding: 32px 0;
  border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 13px;
  text-align: center;
}
.footer a { color: var(--text-secondary); text-decoration: none; margin: 0 8px; }
.footer a:hover { color: var(--teal); }
