:root {
  --font-main: 'Rubik', 'Heebo', system-ui, -apple-system, sans-serif;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow-card: 0 12px 30px rgba(15, 23, 42, 0.1);
  --shadow-soft: 0 4px 14px rgba(15, 23, 42, 0.08);
  --ok-green: #16a34a;
  --ok-green-bg: #dcfce7;
  --ok-green-border: #4ade80;
  --retry-red: #dc2626;
  --retry-red-bg: #fee2e2;
  --retry-red-border: #fca5a5;
}

/* ZELDA THEME — Hyrule Emerald, Gold & Warm Parchment */
html[data-theme="zelda"] {
  --bg-page: linear-gradient(160deg, #f3f9ef 0%, #e7f3e4 50%, #fdf8e7 100%);
  --bg-hero: linear-gradient(135deg, #115e3b 0%, #1b7a4b 55%, #166534 100%);
  --hero-border: #eab308;
  --hero-text: #fefce8;
  --accent: #ca8a04;
  --accent-strong: #eab308;
  --accent-text: #1c1917;
  --card-bg: #fffdf7;
  --card-border: #d6e4c3;
  --text-main: #1f2937;
  --text-muted: #526056;
  --chip-bg: #fef3c7;
  --chip-border: #f59e0b;
  --chip-hover: #fde68a;
  --chip-text: #78350f;
  --finale-bg: linear-gradient(135deg, #fffbeb 0%, #ecfdf5 100%);
  --finale-border: #eab308;
}

/* SONIC THEME — Cobalt Blue, Electric Gold & Speed Red */
html[data-theme="sonic"] {
  --bg-page: linear-gradient(160deg, #eff6ff 0%, #dbeafe 55%, #fef9c3 100%);
  --bg-hero: linear-gradient(135deg, #1d4ed8 0%, #2563eb 55%, #0284c7 100%);
  --hero-border: #facc15;
  --hero-text: #ffffff;
  --accent: #eab308;
  --accent-strong: #facc15;
  --accent-text: #1e293b;
  --card-bg: #ffffff;
  --card-border: #bfdbfe;
  --text-main: #0f172a;
  --text-muted: #475569;
  --chip-bg: #e0f2fe;
  --chip-border: #0ea5e9;
  --chip-hover: #bae6fd;
  --chip-text: #0c4a6e;
  --finale-bg: linear-gradient(135deg, #eff6ff 0%, #fef9c3 100%);
  --finale-border: #3b82f6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-main);
  background: var(--bg-page);
  color: var(--text-main);
  direction: rtl;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 90;
}

.app-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-right)) max(64px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

button,
.small-action-btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* HEADER */
.hero-header {
  background: var(--bg-hero);
  color: var(--hero-text);
  border: 3px solid var(--hero-border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-card);
  margin-bottom: 24px;
}

.hero-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.theme-emblem {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.16);
  border: 2px solid rgba(255, 255, 255, 0.35);
  display: grid;
  place-items: center;
  font-size: 2rem;
  flex-shrink: 0;
}

.app-title {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2rem);
  font-weight: 800;
  line-height: 1.2;
}

.app-subtitle {
  margin: 4px 0 0;
  font-size: 1rem;
  opacity: 0.92;
}

.theme-switcher {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.22);
  padding: 5px;
  border-radius: 999px;
  gap: 6px;
}

.theme-pill {
  border: none;
  background: transparent;
  color: #ffffff;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 9px 18px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: transform 0.16s ease, background-color 0.2s ease, color 0.2s ease;
}

.theme-pill:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.12);
}

.theme-pill.active {
  background: var(--accent-strong);
  color: var(--accent-text);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

.hero-bottom {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.22);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.quest-meter {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.18);
  padding: 8px 14px;
  border-radius: 999px;
}

.meter-label {
  font-size: 0.95rem;
  font-weight: 600;
}

.meter-icons {
  display: flex;
  align-items: center;
  gap: 6px;
}

.meter-slot {
  font-size: 1.35rem;
  line-height: 1;
  opacity: 0.35;
  filter: grayscale(0.6);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease, filter 0.2s ease;
}

.meter-slot.filled {
  opacity: 1;
  filter: none;
  transform: scale(1.16);
}

.meter-count {
  font-weight: 800;
  font-size: 1rem;
  min-width: 38px;
  text-align: center;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.tool-btn {
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.2s ease;
}

.tool-btn:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.24);
}

.tool-btn[aria-pressed="false"] {
  opacity: 0.72;
}

.tool-btn-accent {
  background: var(--accent-strong);
  color: var(--accent-text);
  border-color: transparent;
  font-weight: 800;
}

.tool-btn-accent:hover {
  background: #fde047;
}

/* STATE CARDS */
.state-card {
  background: var(--card-bg);
  border: 2px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 40px 24px;
  text-align: center;
  box-shadow: var(--shadow-card);
}

.state-card .tool-btn-accent {
  margin-top: 12px;
}

.state-title {
  margin: 14px 0 6px;
  font-size: 1.45rem;
}

.state-desc {
  margin: 0;
  color: var(--text-muted);
  font-size: 1.05rem;
}

.error-emoji {
  font-size: 2.8rem;
}

.spinner-orb {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  border-radius: 50%;
  border: 5px solid var(--card-border);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* SENTENCE CARDS */
.sentences-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sentence-card {
  background: var(--card-bg);
  border: 2.5px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-soft);
  transition: border-color 0.25s ease, box-shadow 0.25s ease, background-color 0.25s ease;
}

.sentence-card.is-v {
  border-color: var(--ok-green-border);
  background: linear-gradient(135deg, #ffffff 0%, #f0fdf4 100%);
  box-shadow: 0 10px 26px rgba(22, 163, 74, 0.14);
}

.sentence-card.is-x {
  border-color: var(--retry-red-border);
  background: linear-gradient(135deg, #ffffff 0%, #fef2f2 100%);
  animation: gentleShake 0.35s ease;
}

@keyframes gentleShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(5px); }
  75% { transform: translateX(-5px); }
}

.sentence-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.sentence-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0;
}

.sentence-num {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--chip-bg);
  border: 2px solid var(--chip-border);
  color: var(--chip-text);
  font-weight: 800;
  font-size: 1.2rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.sentence-card.is-v .sentence-num {
  background: var(--ok-green);
  border-color: var(--ok-green);
  color: #ffffff;
}

.sentence-text {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px 8px;
  font-size: clamp(1.75rem, 3.3vw, 2.35rem);
  font-weight: 700;
  line-height: 2.2;
  padding: 4px 0;
}

.word-plain {
  display: inline-block;
  padding: 2px 3px;
}

.word-chip {
  appearance: none;
  font-family: inherit;
  font-size: inherit;
  font-weight: 800;
  line-height: 1.55;
  color: var(--chip-text);
  background: var(--chip-bg);
  border: 2px solid var(--chip-border);
  border-radius: 14px;
  padding: 2px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 3px 0 var(--chip-border);
  transition: transform 0.14s ease, background-color 0.18s ease, box-shadow 0.14s ease;
}

.word-chip:hover {
  background: var(--chip-hover);
  transform: translateY(-2px);
}

.word-chip:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 var(--chip-border);
}

.word-punct {
  font-weight: 700;
  margin-inline-start: -3px;
}

/* V / X BUTTONS */
.sentence-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.judge-btn {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  border: 2.5px solid #cbd5e1;
  background: #ffffff;
  font-size: 1.6rem;
  font-weight: 800;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.judge-btn:hover {
  transform: scale(1.07);
}

.judge-btn-v {
  color: var(--ok-green);
  border-color: #86efac;
}

.judge-btn-v.active,
.judge-btn-v:hover {
  background: var(--ok-green);
  border-color: var(--ok-green);
  color: #ffffff;
}

.judge-btn-x {
  color: var(--retry-red);
  border-color: #fecaca;
}

.judge-btn-x.active,
.judge-btn-x:hover {
  background: var(--retry-red);
  border-color: var(--retry-red);
  color: #ffffff;
}

/* SENTENCE ILLUSTRATION AREA */
.sentence-art-area {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1.5px dashed var(--card-border);
}

.art-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #f0fdf4;
  border: 1.5px solid #86efac;
  color: #166534;
  padding: 9px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.98rem;
}

.art-status-pill.is-error {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #991b1b;
}

.mini-spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid #bbf7d0;
  border-top-color: #16a34a;
  animation: spin 0.8s linear infinite;
}

.sentence-art-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}

.sentence-art-thumb {
  width: 240px;
  max-width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 16px;
  border: 2.5px solid var(--ok-green-border);
  box-shadow: var(--shadow-soft);
  cursor: zoom-in;
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.art-meta-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.art-caption {
  font-weight: 700;
  color: #166534;
  font-size: 1rem;
}

.small-action-btn {
  border: 1.5px solid var(--card-border);
  background: #ffffff;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.18s ease, transform 0.14s ease;
}

.small-action-btn:hover {
  background: #f8fafc;
  transform: translateY(-1px);
}

/* GRAND FINALE CARD */
.finale-card {
  margin-top: 28px;
  background: var(--finale-bg);
  border: 3px solid var(--finale-border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  text-align: center;
  box-shadow: var(--shadow-card);
  animation: popIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.finale-badge {
  display: inline-block;
  background: var(--accent-strong);
  color: var(--accent-text);
  font-weight: 800;
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 0.95rem;
  margin-bottom: 10px;
}

.finale-title {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2rem);
  font-weight: 800;
}

.finale-subtitle {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 1.05rem;
}

.finale-body {
  margin-top: 20px;
}

.finale-image {
  width: 100%;
  max-width: 720px;
  border-radius: 20px;
  border: 3px solid var(--finale-border);
  box-shadow: var(--shadow-card);
  cursor: zoom-in;
  animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

/* MODALS */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-card {
  position: relative;
  background: #ffffff;
  border-radius: var(--radius-lg);
  border: 3px solid var(--accent-strong);
  width: 100%;
  max-width: 480px;
  padding: 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  animation: popIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-close {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: #f1f5f9;
  color: #334155;
  font-size: 1.15rem;
  font-weight: 800;
  cursor: pointer;
}

.modal-close:hover {
  background: #e2e8f0;
}

.word-modal-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 14px;
}

.word-modal-he {
  margin: 0;
  font-size: 2.3rem;
  font-weight: 800;
  line-height: 1.4;
}

.speak-btn {
  border: 1.5px solid var(--chip-border);
  background: var(--chip-bg);
  color: var(--chip-text);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.speak-btn:hover {
  background: var(--chip-hover);
}

.word-modal-body {
  min-height: 240px;
  border-radius: 18px;
  background: radial-gradient(circle at center, #f8fafc 0%, #eef2f7 100%);
  border: 2px solid #e2e8f0;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: hidden;
}

.word-modal-img {
  max-width: 100%;
  max-height: 280px;
  object-fit: contain;
  border-radius: 12px;
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), gentleFloat 3.4s ease-in-out infinite 0.35s;
}

.word-modal-footer {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.source-pill {
  background: #e0f2fe;
  color: #0369a1;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
}

.source-pill.is-theme {
  background: #dcfce7;
  color: #15803d;
}

.word-en-title {
  font-size: 0.9rem;
  color: var(--text-muted);
  direction: ltr;
}

/* LIGHTBOX */
.lightbox-card {
  position: relative;
  max-width: min(92vw, 900px);
  max-height: 90vh;
  background: #0f172a;
  padding: 16px;
  border-radius: 22px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  text-align: center;
}

.lightbox-img {
  max-width: 100%;
  max-height: 76vh;
  border-radius: 14px;
  display: block;
  margin: 0 auto;
}

.lightbox-caption {
  color: #f8fafc;
  font-size: 1.25rem;
  font-weight: 700;
  margin: 12px 0 4px;
}

@keyframes popIn {
  0% {
    opacity: 0;
    transform: scale(0.86);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes gentleFloat {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-6px);
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 12px 12px 48px;
  }

  .hero-header {
    padding: 16px;
    border-radius: 20px;
    margin-bottom: 16px;
  }

  .theme-emblem {
    width: 48px;
    height: 48px;
    font-size: 1.6rem;
    border-radius: 14px;
  }

  .app-title {
    font-size: 1.3rem;
  }

  .app-subtitle {
    font-size: 0.88rem;
  }

  .theme-switcher {
    width: 100%;
  }

  .theme-pill {
    flex: 1;
    justify-content: center;
    padding: 10px 12px;
  }

  .quest-meter {
    width: 100%;
    justify-content: space-between;
  }

  .toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 8px;
  }

  .tool-btn {
    width: 100%;
    text-align: center;
    padding: 10px 10px;
    font-size: 0.92rem;
  }

  .sentence-card {
    padding: 12px 10px;
    border-radius: 18px;
  }

  .sentence-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .sentence-left {
    align-items: center;
    gap: 8px;
  }

  .sentence-num {
    width: 28px;
    height: 28px;
    font-size: 0.9rem;
    border-radius: 9px;
    margin-top: 0;
  }

  .sentence-text {
    font-size: clamp(1.02rem, 4.1vw, 1.28rem);
    line-height: 1.95;
    gap: 4px 5px;
    padding: 2px 0;
  }

  .word-plain {
    padding: 0 1px;
  }

  .word-chip {
    padding: 1px 7px;
    border-width: 1.5px;
    border-radius: 10px;
    box-shadow: 0 2px 0 var(--chip-border);
    line-height: 1.55;
  }

  .sentence-actions {
    justify-content: stretch;
  }

  .judge-btn {
    flex: 1;
    height: 44px;
    font-size: 1.35rem;
    border-radius: 14px;
  }

  .sentence-art-card {
    flex-direction: column;
    align-items: stretch;
  }

  .sentence-art-thumb {
    width: 100%;
  }

  .art-meta-col {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
  }

  .modal-card {
    max-height: 90dvh;
    overflow-y: auto;
    padding: 20px 16px;
  }

  .word-modal-he {
    font-size: 1.9rem;
  }

  .word-modal-img {
    max-height: 45dvh;
  }

  .login-card {
    padding: 26px 20px;
  }
}

/* LOGIN PAGE */
.login-body {
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-shell {
  width: 100%;
  max-width: 440px;
}

.login-card {
  background: var(--card-bg);
  border: 3px solid var(--hero-border);
  border-radius: var(--radius-lg);
  padding: 34px 28px;
  box-shadow: var(--shadow-card);
  text-align: center;
}

.login-emblem {
  width: 68px;
  height: 68px;
  margin: 0 auto 14px;
  border-radius: 20px;
  background: var(--bg-hero);
  display: grid;
  place-items: center;
  font-size: 2.1rem;
  box-shadow: var(--shadow-soft);
}

.login-title {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 800;
}

.login-subtitle {
  margin: 6px 0 24px;
  color: var(--text-muted);
  font-size: 1rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: right;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-weight: 700;
  font-size: 0.95rem;
}

.field-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--card-border);
  background: #ffffff;
  font-family: inherit;
  font-size: 1.05rem;
  color: var(--text-main);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.25);
}

.login-error {
  margin: 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--retry-red-bg);
  border: 1.5px solid var(--retry-red-border);
  color: #991b1b;
  font-weight: 600;
  font-size: 0.95rem;
  text-align: center;
}

.login-submit-btn {
  margin-top: 6px;
  width: 100%;
  padding: 13px 18px;
  border: none;
  border-radius: 999px;
  background: var(--bg-hero);
  color: #ffffff;
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.login-submit-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.login-submit-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.turnstile-container {
  display: flex;
  justify-content: center;
  margin: 4px 0;
}
