/* ===========================================================
   Dolanan — shared theme tokens & base styles
   =========================================================== */

/* ===== Light palette (default) ===== */
:root {
  --bg: #eff6ff;
  --bg-2: #dbeafe;
  --card: #ffffff;
  --card-2: #f1f5f9;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --secondary: #cbd5e1;
  --accent: #0ea5e9;
  --accent-warm: #f59e0b;
  --danger: #ef4444;
  --success: #10b981;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #dbeafe;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 10px 30px rgba(59, 130, 246, 0.15);
  --shadow-sm: 0 2px 8px rgba(59, 130, 246, 0.1);
  --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;

  /* Gradient stops — referenced in body so dark mode can override them. */
  --grad-a: #e0f2fe;
  --grad-b: #eff6ff;
  --grad-c: #dbeafe;
}

/* ===== Dark palette ===== */
/* Activated by system preference OR by a manual [data-theme="dark"] on <html>. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f172a;
    --bg-2: #1e293b;
    --card: #1e293b;
    --card-2: #334155;
    --primary: #60a5fa;
    --primary-hover: #93c5fd;
    --secondary: #475569;
    --accent: #38bdf8;
    --accent-warm: #fbbf24;
    --danger: #f87171;
    --success: #34d399;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --grad-a: #0f172a;
    --grad-b: #1e293b;
    --grad-c: #0f172a;
    color-scheme: dark;
  }
}

/* Manual override: user clicked the dark/light toggle. */
:root[data-theme="dark"] {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --card: #1e293b;
  --card-2: #334155;
  --primary: #60a5fa;
  --primary-hover: #93c5fd;
  --secondary: #475569;
  --accent: #38bdf8;
  --accent-warm: #fbbf24;
  --danger: #f87171;
  --success: #34d399;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --grad-a: #0f172a;
  --grad-b: #1e293b;
  --grad-c: #0f172a;
  color-scheme: dark;
}
:root[data-theme="light"] {
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  min-height: 100%;
  /* `clip` avoids creating a scroll container on iOS that breaks body scroll */
  overflow-x: clip;
}

body {
  font-family: var(--font-stack);
  color: var(--text);
  background:
    linear-gradient(135deg, var(--grad-a) 0%, var(--grad-b) 50%, var(--grad-c) 100%);
  background-attachment: fixed;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  padding:
    max(12px, env(safe-area-inset-top))
    clamp(12px, 4vw, 24px)
    calc(max(24px, env(safe-area-inset-bottom)) + 32px);
}

/* Game pages: tight padding, no footer — game fills naturally. */
body.game {
  padding-top: max(4px, env(safe-area-inset-top));
  padding-bottom: max(4px, env(safe-area-inset-bottom));
  padding-left: clamp(6px, 2.5vw, 16px);
  padding-right: clamp(6px, 2.5vw, 16px);
}

/* Prevent accidental text selection during gameplay, but keep inputs selectable. */
body { user-select: none; }
input, textarea, [contenteditable] { user-select: auto; }

/* The HTML `hidden` attribute must always win — several of our component
   classes (.btn, .modal-backdrop, .turn-pill, etc.) set `display: inline-flex`
   or `display: flex`, which has higher specificity than the browser default
   for [hidden] and would make hidden elements still appear. */
[hidden] { display: none !important; }

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

a:hover {
  color: var(--primary-hover);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

h1,
h2,
h3 {
  margin: 0 0 12px;
  line-height: 1.2;
}

/* ===== Header / logo =========================== */
.app-header {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 0 12px;
  text-align: center;
}

.logo {
  font-weight: 800;
  font-size: clamp(28px, 6vw, 42px);
  letter-spacing: 3px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-transform: uppercase;
}

.tagline {
  color: var(--text-muted);
  margin-top: 4px;
  font-size: 14px;
}

/* ===== Buttons ================================= */
.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius);
  padding: 12px 20px;
  font-weight: 600;
  font-size: 15px;
  min-height: 44px;
  min-width: 44px;
  transition: transform 0.15s ease-out, background 0.2s ease-out,
    box-shadow 0.2s ease-out;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-hover), var(--accent));
}

.btn-secondary {
  background: var(--card-2);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--bg-2);
}

.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.btn-ghost:hover {
  background: rgba(59, 130, 246, 0.08);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

/* ===== Segmented language toggle ===== */
.lang-seg {
  display: inline-flex;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.lang-seg button {
  appearance: none;
  border: none;
  background: transparent;
  padding: 6px 14px;
  min-height: 32px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.lang-seg button.active {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.lang-seg button:not(.active):hover {
  color: var(--text);
}

/* ===== Cards =================================== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ===== Modal =================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
  animation: fade-in 0.15s ease-out;
}


.modal {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow);
  text-align: center;
}

.modal h2 {
  margin-bottom: 8px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 16px;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ===== Back link =============================== */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 14px;
  padding: 8px 12px;
  margin: 16px 0;
  border-radius: var(--radius);
  min-height: 44px;
}

.back-link:hover {
  background: rgba(59, 130, 246, 0.08);
  color: var(--primary);
}

/* ===== Footer ================================== */
.app-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 32px 16px 16px;
  max-width: 960px;
  margin: 40px auto 0;
}

.app-footer a {
  font-weight: 600;
}

/* ===== Utility ================================= */
.center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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