/* ============================================================
   Mobile-first stylesheet, prepared for Capacitor/iOS wrapping
   ============================================================ */

:root {
  /* Warm earthy palette – adjust per game */
  --color-bg: #f5efe6;
  --color-surface: #ffffff;
  --color-primary: #8a6d4b;
  --color-primary-dark: #6e5539;
  --color-text: #2e2a24;
  --color-danger: #a94436;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.12);

  /* Safe areas: needed on iPhone (notch/home indicator) inside Capacitor */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  /* Prevent iOS rubber-band scrolling in the app shell */
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  /* Removes 300ms tap delay and blocks double-tap zoom – critical for game feel */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  /* Prevent text selection while dragging cards */
  -webkit-user-select: none;
  user-select: none;
}

/* ===== Screen system: one .screen visible at a time ===== */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right))
           calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.active { display: flex; flex-direction: column; align-items: center; }

.screen-inner {
  width: 100%;
  max-width: 480px; /* Phone-width layout even on desktop browsers */
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

h1 { font-size: 2rem; text-align: center; margin-top: 8vh; }
h2 { font-size: 1.4rem; text-align: center; }
.tagline { text-align: center; opacity: 0.7; }

/* ===== Buttons: min 44px tall = Apple's minimum touch target ===== */
.btn {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 12px 20px;
  font-size: 1.05rem;
  border: none;
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:active { background: var(--color-primary-dark); }
.btn-danger { background: var(--color-danger); color: #fff; }
/* Starkare accentfärg (samma som Bibellinjen) för att sticka ut från "Spela igen" */
.btn-accent { background: #6d3904; color: #fff; }
.btn-accent:active { background: #4f2a03; }

.menu-buttons { display: flex; flex-direction: column; gap: 12px; margin-top: 4vh; }

.menu-footer { margin-top: auto; text-align: center; font-size: 0.85rem; opacity: 0.75; padding-bottom: 8px; }
.menu-footer a { color: var(--color-primary-dark); }

.info-link {
  display: block;
  text-align: center;
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--color-primary-dark);
}

#scoring-text p { margin-bottom: 12px; }

/* ===== Game screen ===== */
.game-header {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

#game-board {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.game-footer { display: flex; gap: 12px; }
.game-footer .btn { flex: 1; }

/* ===== Flip card (quote front, reveal back) ===== */
#flip-card {
  flex: 1;
  min-height: 240px;
  perspective: 1000px;
}

#flip-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s;
}
#flip-inner.flipped { transform: rotateY(180deg); }

#card-front, #card-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 14px;
  overflow-y: auto;
  text-align: center;
}
#card-back { transform: rotateY(180deg); }

#quote-text, #quote-text-back {
  font-size: 1.15rem;
  line-height: 1.5;
  font-style: italic;
}

/* Svårighetsprickar, nedre högra hörnet av kortet, se game.js renderQuote() */
.level-dots {
  position: absolute;
  right: 16px;
  bottom: 12px;
  font-size: 1.1rem;
  letter-spacing: 3px;
}
.level-dots.level-1 { color: #2e7d32; }
.level-dots.level-2 { color: #8bc34a; }
.level-dots.level-3 { color: #ffab00; }
.level-dots.level-4 { color: #f4511e; }
.level-dots.level-5 { color: #c62828; }

/* Nivå-upp-notis på resultatskärmen: samma färgskala som .level-dots
   men fristående (ingen absolut positionering) och större, med en kort
   "pop" + färgövertoning när prickarna byter till nästa nivå. Se
   game.js renderLevelUpNotice(). */
.level-up-dots {
  display: inline-block;
  font-size: 1.6rem;
  letter-spacing: 5px;
  transition: color 0.5s ease;
}
.level-up-dots.level-1 { color: #2e7d32; }
.level-up-dots.level-2 { color: #8bc34a; }
.level-up-dots.level-3 { color: #ffab00; }
.level-up-dots.level-4 { color: #f4511e; }
.level-up-dots.level-5 { color: #c62828; }
@keyframes level-up-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.35); }
  100% { transform: scale(1); }
}
.level-up-dots.pop { animation: level-up-pop 0.45s ease; }
.level-up-fineprint { font-size: 0.75rem; opacity: 0.6; }

#quote-ref { font-size: 1.2rem; font-weight: 700; }
#round-points { font-size: 1.05rem; font-weight: 600; opacity: 0.8; }

.part-correct { color: #2e7d32; }
.part-wrong { color: #c62828; }

/* Litet märke som visar att flera bibelställen godtas för citatet */
.altrefs-badge {
  font-size: 0.8rem;
  padding: 2px 10px;
  border-radius: 999px;
  background: #eee3d3;
  color: var(--color-primary-dark);
}

/* Notis om liknande/godtagna alternativa ställen, se game.js renderReveal() */
.alt-refs-note {
  font-size: 0.85rem;
  font-weight: 400;
  opacity: 0.8;
  margin-top: 4px;
}

/* ===== Guess dropdowns ===== */
#guess-controls { display: flex; flex-direction: column; gap: 10px; }
.guess-row { display: flex; gap: 10px; }
.guess-row select { flex: 1; }

#guess-controls select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  font-size: 1rem;
  /* Transparent base border so outline color changes don't shift layout */
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow);
  color: var(--color-text);
}
#guess-controls select:disabled { opacity: 0.45; }

/* Orange = ändrad sedan senaste gissningen ("fiddled with") */
#guess-controls select.touched {
  border-color: #e08a2e;
}

/* Locked (correct) selects stay fully visible with a green marker */
#guess-controls select.locked {
  opacity: 1;
  border: 2px solid #2e7d32;
  color: #2e7d32;
  font-weight: 600;
}

#guess-instruction-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 0.85rem;
  opacity: 0.7;
}
#game-tries { font-weight: 600; white-space: nowrap; }

#guess-feedback {
  display: flex;
  gap: 8px;
  justify-content: center;
  min-height: 24px;
  flex-wrap: wrap;
}
.fb {
  font-size: 0.85rem;
  padding: 2px 10px;
  border-radius: 999px;
}
.fb:empty { display: none; }
.fb-correct { background: #e3f2e5; color: #2e7d32; font-weight: 700; }
.fb-hint { background: #fdeaea; color: #c62828; }

/* Pulse = kvitto på att gissningen behandlats, även om inget låstes */
@keyframes fb-pulse {
  0% { transform: scale(0.9); opacity: 0.3; }
  100% { transform: scale(1); opacity: 1; }
}
#guess-feedback.pulse { animation: fb-pulse 0.35s ease; }

.btn:disabled { opacity: 0.45; pointer-events: none; }

.result-score { font-size: 2rem; font-weight: 700; text-align: center; }
.result-time { text-align: center; opacity: 0.8; }

/* ===== Options: every setting is its own box (label [+subtitle] left, control right) ===== */
.option-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
}

.option-box-text { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; min-width: 0; }
.option-box-label { font-weight: 600; font-size: 0.95rem; }
.option-box-subtitle { font-size: 0.8rem; opacity: 0.65; }

.option-box-select {
  width: 130px;
  min-height: 40px;
  padding: 8px 12px;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--color-bg);
  color: var(--color-text);
  flex-shrink: 0;
}

/* Kvarvarande bruk: raden med bara "Återställ all data"-knappen */
.option-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
}

/* ===== Toggle-switch (kryssruta stylad som ett skjutreglage) ===== */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.switch-track {
  position: absolute;
  inset: 0;
  background: #d8cdbd;
  border-radius: 999px;
  transition: background 0.15s ease;
  pointer-events: none;
}
.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease;
}
.switch input:checked + .switch-track { background: var(--color-primary); }
.switch input:checked + .switch-track .switch-knob { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--color-primary-dark); outline-offset: 2px; }

/* ===== Menu play buttons (one per game mode, see App.renderMenuPlayButtons) ===== */
.mode-play-list { display: flex; flex-direction: column; gap: 12px; margin-top: 4vh; }

.mode-play-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 14px 20px;
  font-size: 1.05rem;
  font-family: inherit;
  text-align: left;
  border: none;
  border-radius: var(--radius);
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.mode-play-btn:active { transform: scale(0.98); background: var(--color-primary-dark); }
.mode-play-name { font-weight: 700; font-size: 1.1rem; }
.mode-play-desc { font-size: 0.85rem; opacity: 0.9; }

.mode-play-btn.locked {
  background: var(--color-surface);
  color: var(--color-text);
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}
.mode-play-btn.locked:active { transform: none; }
.mode-play-btn .mode-play-lock { font-size: 0.78rem; opacity: 0.85; margin-top: 2px; }

/* ===== Confirm / suggestion boxes (mode picker, result screen) ===== */
.confirm-box, .suggestion-box {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.confirm-box p, .suggestion-box p { text-align: center; }
.confirm-box[hidden], .suggestion-box[hidden] { display: none; }

/* ===== Leaderboard (kolumner: Namn | Lösta | Poäng | Tid) =====
   Tre flikar (Lätt/Normal/Svår) - poäng är inte jämförbara mellan
   spellägen eftersom de gissar olika många delar. Se app.js. */
.tab-row { display: flex; gap: 8px; }
.tab-btn {
  flex: 1;
  min-height: 44px;
  padding: 8px 12px;
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 600;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow);
  cursor: pointer;
  opacity: 0.6;
}
.tab-btn.active { border-color: var(--color-primary); color: var(--color-primary-dark); opacity: 1; }

#leaderboard-table { display: flex; flex-direction: column; gap: 8px; }
#leaderboard-list { display: flex; flex-direction: column; gap: 8px; }

.lb-row {
  display: grid;
  grid-template-columns: 1fr 60px 90px 60px;
  gap: 8px;
  align-items: center;
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow);
}
.lb-head {
  background: transparent;
  box-shadow: none;
  padding-top: 0;
  padding-bottom: 0;
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.65;
}
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-num { text-align: right; font-variant-numeric: tabular-nums; }
.lb-empty { display: block; text-align: center; opacity: 0.7; }
