/* ══════════════════════════════════
   Code Fill Pro — Main Stylesheet
══════════════════════════════════ */

:root {
  --bg: #0b0f1a;
  --card: #1a2234;
  --border: #1e3a5f;
  --cyan: #22d3ee;
  --cyan-dim: #0e7490;
  --violet: #a78bfa;
  --green: #4ade80;
  --red: #f87171;
  --gold: #fbbf24;
  --text: #e2e8f0;
  --muted: #64748b;
}

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

body {
  font-family: 'Kanit', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(34, 211, 238, .04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34, 211, 238, .04) 1px, transparent 1px);
  background-size: 40px 40px;
  animation: gridShift 20s linear infinite;
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 20% 20%, rgba(167, 139, 250, .08) 0%, transparent 60%),
    radial-gradient(ellipse 50% 60% at 80% 80%, rgba(34, 211, 238, .07) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

@keyframes gridShift {
  from {
    background-position: 0 0, 0 0;
  }

  to {
    background-position: 0 40px, 40px 0;
  }
}

.container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  overflow-wrap: break-word;
}

.header {
  text-align: center;
  margin-bottom: 28px;
  font-family: 'Space Mono', monospace;

}

.header h1 {
  font-family: 'Space Mono', monospace;
  font-size: 2.2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--cyan) 0%, var(--violet) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -1px;
}

.header p {
  font-weight: 300;
  color: var(--muted);
  font-size: .9rem;
  margin-top: 5px;
  font-family: 'Space Mono', monospace;
}

.screen {
  animation: fadeUp .35s ease both;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── NAVBAR ── */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: linear-gradient(135deg, rgba(15, 23, 42, .92) 0%, rgba(20, 28, 47, .95) 50%, rgba(15, 23, 42, .92) 100%);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(34, 211, 238, .15);
  border-radius: 14px;
  margin-bottom: 26px;
  position: relative;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, .5),
    0 0 0 1px rgba(34, 211, 238, .05) inset;
  animation: fadeUp .35s ease both;
  transition: border-color .3s, box-shadow .3s;
}

.navbar:hover {
  border-color: rgba(34, 211, 238, .28);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, .5),
    0 0 24px rgba(34, 211, 238, .06),
    0 0 0 1px rgba(34, 211, 238, .08) inset;
}

/* Glow line at top */
.navbar::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 20%;
  right: 20%;
  height: 1px;
  border-radius: 2px;
  background: linear-gradient(90deg,
      transparent,
      rgba(34, 211, 238, .5) 30%,
      rgba(167, 139, 250, .4) 70%,
      transparent);
  z-index: 2;
  transition: opacity .3s;
}

/* Inner subtle glow */
.navbar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 14px;
  background:
    radial-gradient(ellipse at 0% 0%, rgba(34, 211, 238, .06) 0%, transparent 40%),
    radial-gradient(ellipse at 100% 100%, rgba(167, 139, 250, .04) 0%, transparent 40%);
  pointer-events: none;
}

.navbar-brand {
  font-family: 'Space Mono', monospace;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.5px;
  position: relative;
  z-index: 1;
  transition: all .25s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.navbar-brand:hover {
  text-shadow: 0 0 20px rgba(34, 211, 238, .25);
}

.navbar-brand span {
  background: linear-gradient(135deg, var(--cyan) 0%, var(--violet) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 1.2rem;
}

.navbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  z-index: 1;
}

/* Avatar with animated gradient ring */
.navbar-avatar-wrap {
  position: relative;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.navbar-avatar-wrap::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  background: conic-gradient(var(--cyan),
      var(--violet),
      var(--cyan));
  animation: avatarSpin 4s linear infinite;
  opacity: .8;
}

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

.navbar-avatar-wrap::after {
  content: '';
  position: absolute;
  inset: 1px;
  border-radius: 50%;
  background: #0f172a;
}

.navbar-avatar {
  position: relative;
  z-index: 1;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid #0f172a;
  object-fit: cover;
}

/* Online indicator */
.navbar-status {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background: var(--green);
  border: 2px solid #0f172a;
  border-radius: 50%;
  z-index: 2;
  box-shadow: 0 0 6px rgba(74, 222, 128, .6);
  animation: statusPulse 2.5s ease-in-out infinite;
}

@keyframes statusPulse {

  0%,
  100% {
    box-shadow: 0 0 4px rgba(74, 222, 128, .4);
  }

  50% {
    box-shadow: 0 0 10px rgba(74, 222, 128, .8);
  }
}

.navbar-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.navbar-name {
  font-size: .85rem;
  color: var(--text);
  font-weight: 500;
  line-height: 1.2;
}

.navbar-email {
  font-size: .68rem;
  color: var(--muted);
  font-family: 'Space Mono', monospace;
  letter-spacing: .2px;
  opacity: .8;
}

/* Shared button base — badge pill style */
.navbar-login-btn,
.navbar-logout-btn {
  font-family: 'Space Mono', monospace;
  font-size: .75rem;
  padding: 4px 12px;
  border-radius: 20px;
  font-weight: 700;
  letter-spacing: .5px;
  cursor: pointer;
  transition: all .25s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Login button — cyan badge (badge-easy style) */
.navbar-login-btn {
  background: rgba(56, 189, 248, .15);
  color: var(--cyan);
  border: 1px solid rgba(56, 189, 248, .3);
}

.navbar-login-btn:hover {
  background: rgba(56, 189, 248, .25);
  border-color: rgba(56, 189, 248, .5);
  box-shadow: 0 0 14px rgba(56, 189, 248, .15);
  transform: translateY(-1px);
}

.navbar-login-btn:active {
  transform: scale(.97);
}

/* Logout button — red badge (badge-hard style) */
.navbar-logout-btn {
  background: rgba(248, 113, 113, .15);
  color: var(--red);
  border: 1px solid rgba(248, 113, 113, .3);
}

.navbar-logout-btn:hover {
  background: rgba(248, 113, 113, .25);
  border-color: rgba(248, 113, 113, .5);
  box-shadow: 0 0 14px rgba(248, 113, 113, .15);
  transform: translateY(-1px);
}

.navbar-logout-btn:active {
  transform: scale(.97);
}

/* ── Navbar divider (vertical line) ── */
.navbar-divider {
  width: 1px;
  height: 26px;
  background: linear-gradient(180deg,
      transparent,
      rgba(34, 211, 238, .2) 30%,
      rgba(167, 139, 250, .15) 70%,
      transparent);
  flex-shrink: 0;
}

/* ────────────────────────────
   SELECT DIFFICULTY
──────────────────────────── */
.select-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-bottom: 16px;
}

.diff-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 18px 22px;
  text-align: center;
  cursor: pointer;
  transition: all .25s;
  position: relative;
  overflow: hidden;
}

.diff-card::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity .25s;
}

.diff-card.easy::before {
  background: radial-gradient(ellipse at top, rgba(74, 222, 128, .13), transparent 70%);
}

.diff-card.medium::before {
  background: radial-gradient(ellipse at top, rgba(251, 191, 36, .13), transparent 70%);
}

.diff-card.hard::before {
  background: radial-gradient(ellipse at top, rgba(248, 113, 113, .13), transparent 70%);
}

.diff-card:hover {
  transform: translateY(-6px);
}

.diff-card:hover::before {
  opacity: 1;
}

.diff-card.easy:hover {
  border-color: rgba(74, 222, 128, .5);
  box-shadow: 0 16px 40px rgba(74, 222, 128, .12);
}

.diff-card.medium:hover {
  border-color: rgba(251, 191, 36, .5);
  box-shadow: 0 16px 40px rgba(251, 191, 36, .12);
}

.diff-card.hard:hover {
  border-color: rgba(248, 113, 113, .5);
  box-shadow: 0 16px 40px rgba(248, 113, 113, .12);
}

.diff-icon {
  font-size: 2.6rem;
  margin-bottom: 12px;
}

.diff-title {
  font-family: 'Space Mono', monospace;
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.diff-card.easy .diff-title {
  color: var(--green);
}

.diff-card.medium .diff-title {
  color: var(--gold);
}

.diff-card.hard .diff-title {
  color: var(--red);
}

.diff-desc {
  font-size: .8rem;
  color: var(--muted);
  line-height: 1.55;
}

.diff-pips {
  margin-top: 14px;
  display: flex;
  gap: 6px;
  justify-content: center;
}

.pip {
  width: 20px;
  height: 4px;
  border-radius: 99px;
  transition: opacity .3s;
}

.diff-card.easy .pip {
  background: var(--green);
}

.diff-card.medium .pip {
  background: var(--gold);
}

.diff-card.hard .pip {
  background: var(--red);
}

.diff-counter {
  margin-top: 8px;
  font-family: 'Space Mono', monospace;
  font-size: .7rem;
  color: var(--muted);
}

/* ── LOCKED states ── */
.diff-card.locked {
  cursor: not-allowed;
  opacity: .5;
  filter: grayscale(.6);
}

.diff-card.locked:hover {
  transform: none !important;
  box-shadow: none !important;
  border-color: var(--border) !important;
}

.diff-card.locked::before {
  display: none;
}

.lock-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(11, 15, 26, .55);
  border-radius: 16px;
  font-size: .78rem;
  color: var(--muted);
  gap: 6px;
  backdrop-filter: blur(1px);
}

.lock-overlay span {
  font-size: 1.6rem;
}

.stage-card.locked {
  cursor: not-allowed;
  opacity: .45;
  filter: grayscale(.5);
}

.stage-card.locked:hover {
  transform: none !important;
  box-shadow: none !important;
  border-color: var(--border) !important;
}

.stage-lock-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.8rem;
  opacity: .6;
}

/* ────────────────────────────
   STAGE SELECT
──────────────────────────── */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: .85rem;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 0;
  margin-bottom: 20px;
  font-family: 'Space Mono', monospace;
  background: none;
  border: none;
  transition: color .2s;
}

.back-btn:hover {
  color: var(--cyan);
}

.section-label {
  font-family: 'Space Mono', monospace;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--muted);
  margin-bottom: 14px;
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.stage-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 16px 18px;
  text-align: center;
  cursor: pointer;
  transition: all .22s;
  position: relative;
}

.stage-card:hover {
  transform: translateY(-4px);
}

.stage-card.easy:hover {
  border-color: rgba(74, 222, 128, .5);
  box-shadow: 0 10px 30px rgba(74, 222, 128, .1);
}

.stage-card.medium:hover {
  border-color: rgba(251, 191, 36, .5);
  box-shadow: 0 10px 30px rgba(251, 191, 36, .1);
}

.stage-card.hard:hover {
  border-color: rgba(248, 113, 113, .5);
  box-shadow: 0 10px 30px rgba(248, 113, 113, .1);
}

.stage-done-badge {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: .7rem;
  color: var(--green);
  font-family: 'Space Mono', monospace;
  font-weight: 700;
}

.stage-num {
  font-family: 'Space Mono', monospace;
  font-size: 2.2rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.stage-card.easy .stage-num {
  color: var(--green);
}

.stage-card.medium .stage-num {
  color: var(--gold);
}

.stage-card.hard .stage-num {
  color: var(--red);
}

.stage-name {
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: 10px;
}

.stage-stars {
  font-size: .9rem;
  letter-spacing: 2px;
}

.pts-note {
  text-align: center;
  color: var(--muted);
  font-size: .78rem;
  font-family: 'Space Mono', monospace;
  margin-top: 4px;
}

/* ────────────────────────────
   GAME SCREEN
──────────────────────────── */
.total-score-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-family: 'Space Mono', monospace;
  font-size: .8rem;
  color: var(--muted);
}

.total-score-bar strong {
  color: var(--cyan);
  font-size: 1rem;
}

.meta-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding: 10px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.badge {
  font-family: 'Space Mono', monospace;
  font-size: .75rem;
  padding: 4px 12px;
  border-radius: 20px;
  font-weight: 700;
  letter-spacing: .5px;
}

.badge-easy {
  background: rgba(74, 222, 128, .15);
  color: var(--green);
  border: 1px solid rgba(74, 222, 128, .3);
}

.badge-medium {
  background: rgba(251, 191, 36, .15);
  color: var(--gold);
  border: 1px solid rgba(251, 191, 36, .3);
}

.badge-hard {
  background: rgba(248, 113, 113, .15);
  color: var(--red);
  border: 1px solid rgba(248, 113, 113, .3);
}

.score-box {
  font-family: 'Space Mono', monospace;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.score-val {
  color: var(--cyan);
  font-weight: 700;
  font-size: 1.2rem;
  transition: transform .2s, color .3s;
}

.score-val.bump {
  transform: scale(1.4);
  color: var(--green);
}

.score-val.drop {
  transform: scale(1.4);
  color: var(--red);
}

.code-card {
  background: #080d17;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 20px;
  box-shadow: 0 0 40px rgba(34, 211, 238, .05);
}

.code-title-bar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 8px 14px;
  display: flex;
  gap: 7px;
  align-items: center;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.dot-r {
  background: #f87171;
}

.dot-y {
  background: #fbbf24;
}

.dot-g {
  background: #4ade80;
}

.code-title-bar span {
  margin-left: auto;
  font-family: 'Space Mono', monospace;
  font-size: .7rem;
  color: var(--muted);
}

pre {
  font-family: 'Space Mono', monospace;
  font-size: .88rem;
  line-height: 1.85;
  color: #7dd3fc;
  padding: 20px 24px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  word-break: break-word;
  white-space: pre-wrap;
}

.drop-zone {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 90px;
  height: 32px;
  padding: 0 12px;
  border: 2px dashed var(--cyan-dim);
  border-radius: 6px;
  background: rgba(34, 211, 238, .06);
  color: var(--muted);
  font-size: .82rem;
  cursor: pointer;
  transition: all .2s;
  vertical-align: middle;
  font-family: 'Space Mono', monospace;
}

.drop-zone.drag-over {
  border-color: var(--cyan);
  background: rgba(34, 211, 238, .15);
  box-shadow: 0 0 12px rgba(34, 211, 238, .3);
  color: var(--cyan);
}

.drop-zone.filled {
  border-color: var(--violet);
  background: rgba(167, 139, 250, .12);
  color: var(--violet);
  cursor: grab;
}

.drop-zone.filled:hover {
  border-color: var(--cyan);
  box-shadow: 0 0 10px rgba(34, 211, 238, .2);
}

.drop-zone.dragging-out {
  opacity: .4;
  border-style: dashed;
}

.drop-zone.correct {
  border-color: var(--green) !important;
  background: rgba(74, 222, 128, .12) !important;
  color: var(--green) !important;
  box-shadow: 0 0 14px rgba(74, 222, 128, .25) !important;
}

.drop-zone.wrong {
  border-color: var(--red) !important;
  background: rgba(248, 113, 113, .12) !important;
  color: var(--red) !important;
  box-shadow: 0 0 14px rgba(248, 113, 113, .25) !important;
}

.choices-grid.choices-hover {
  outline: 2px dashed var(--cyan-dim);
  border-radius: 8px;
  background: rgba(34, 211, 238, .04);
}

/* ── Submit button ── */
.submit-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.submit-btn {
  flex-shrink: 0;
  padding: 6px 18px;
  font-family: 'Space Mono', monospace;
  font-size: .85rem;
  font-weight: 700;
  letter-spacing: .5px;
  border-radius: 20px;
  cursor: pointer;
  transition: all .25s;
  position: relative;
  overflow: hidden;
  background: rgba(56, 189, 248, .15);
  color: var(--cyan);
  border: 1px solid rgba(56, 189, 248, .3);
  box-shadow: none;
}

.submit-btn:not(:disabled):hover {
  background: rgba(56, 189, 248, .25);
  border-color: rgba(56, 189, 248, .5);
  box-shadow: 0 0 14px rgba(56, 189, 248, .15);
  transform: translateY(-1px);
}

.submit-btn:not(:disabled):active {
  transform: scale(.97);
}

.submit-btn:disabled {
  background: rgba(148, 163, 184, .08);
  color: var(--muted);
  border: 1px solid var(--border);
  cursor: not-allowed;
  box-shadow: none;
}

.submit-hint {
  font-size: .82rem;
  color: var(--muted);
  font-family: 'Space Mono', monospace;
  transition: color .3s;
}

.submit-hint.ready {
  color: var(--cyan);
}

.choices-label {
  font-size: .78rem;
  color: var(--muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 500;
}

.choices-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}

.choice {
  font-family: 'Space Mono', monospace;
  font-size: .85rem;
  padding: 9px 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: grab;
  color: var(--text);
  user-select: none;
  transition: all .2s;
  position: relative;
  overflow: hidden;
}

.choice::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(34, 211, 238, .1), rgba(167, 139, 250, .1));
  opacity: 0;
  transition: opacity .2s;
}

.choice:hover {
  border-color: var(--cyan);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
}

.choice:hover::before {
  opacity: 1;
}

.choice:active {
  cursor: grabbing;
  transform: scale(.95);
}

.choice.used {
  opacity: .3;
  pointer-events: none;
}

.result-box {
  min-height: 52px;
  padding: 14px 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: .95rem;
  font-weight: 500;
  margin-bottom: 14px;
  opacity: 0;
  transform: translateY(8px);
  transition: all .3s;
  border: 1px solid transparent;
}

.result-box.show {
  opacity: 1;
  transform: translateY(0);
}

.result-box.correct-r {
  background: rgba(74, 222, 128, .08);
  border-color: rgba(74, 222, 128, .25);
  color: var(--green);
}

.result-box.wrong-r {
  background: rgba(248, 113, 113, .08);
  border-color: rgba(248, 113, 113, .25);
  color: var(--red);
}

.result-icon {
  font-size: 1.4rem;
}

.explain-box {
  background: rgba(251, 191, 36, .06);
  border: 1px solid rgba(251, 191, 36, .2);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: .88rem;
  color: #fde68a;
  line-height: 1.6;
  opacity: 0;
  transition: opacity .4s .15s;
}

.explain-box.show {
  opacity: 1;
}

/* ────────────────────────────
   FINISH SCREEN
──────────────────────────── */
.finish-screen {
  text-align: center;
  padding: 36px 20px;
}

.finish-screen .trophy {
  font-size: 4rem;
  animation: bounce 1s infinite alternate;
}

@keyframes bounce {
  to {
    transform: translateY(-12px);
  }
}

.finish-screen h2 {
  font-family: 'Space Mono', monospace;
  font-size: 1.5rem;
  background: linear-gradient(135deg, var(--gold), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 14px 0 6px;
}

.final-score {
  font-family: 'Space Mono', monospace;
  font-size: 3rem;
  font-weight: 700;
  color: var(--cyan);
  text-shadow: 0 0 30px rgba(34, 211, 238, .5);
  margin: 6px 0;
}

.star-row {
  font-size: 2rem;
  margin: 10px 0;
  letter-spacing: 6px;
}

.finish-explain {
  margin: 16px auto 4px;
  max-width: 500px;
  background: rgba(251, 191, 36, .07);
  border: 1px solid rgba(251, 191, 36, .25);
  border-radius: 12px;
  padding: 14px 20px;
  font-size: .9rem;
  color: #fde68a;
  line-height: 1.65;
  text-align: left;
}

/* ── Answer reveal ── */
.answer-section {
  margin: 18px auto 4px;
  max-width: 560px;
  text-align: left;
}

.answer-section-title {
  font-family: 'Space Mono', monospace;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--muted);
  margin-bottom: 10px;
}

.answer-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 10px;
  margin-bottom: 8px;
  border: 1px solid transparent;
}

.answer-row.ans-correct {
  background: rgba(74, 222, 128, .07);
  border-color: rgba(74, 222, 128, .2);
}

.answer-row.ans-wrong {
  background: rgba(248, 113, 113, .07);
  border-color: rgba(248, 113, 113, .2);
}

.answer-badge {
  flex-shrink: 0;
  font-family: 'Space Mono', monospace;
  font-size: .75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  margin-top: 1px;
}

.answer-badge.ok {
  background: rgba(74, 222, 128, .18);
  color: var(--green);
}

.answer-badge.bad {
  background: rgba(248, 113, 113, .18);
  color: var(--red);
}

.answer-detail {
  flex: 1;
}

.answer-detail .ans-label {
  font-size: .78rem;
  color: var(--muted);
  font-family: 'Space Mono', monospace;
  margin-bottom: 3px;
}

.answer-val-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.ans-chip {
  font-family: 'Space Mono', monospace;
  font-size: .85rem;
  font-weight: 700;
  padding: 2px 12px;
  border-radius: 6px;
}

.ans-chip.correct-chip {
  background: rgba(74, 222, 128, .15);
  color: var(--green);
  border: 1px solid rgba(74, 222, 128, .3);
}

.ans-chip.wrong-chip {
  background: rgba(248, 113, 113, .15);
  color: var(--red);
  border: 1px solid rgba(248, 113, 113, .3);
}

.ans-chip.arrow {
  background: none;
  color: var(--muted);
  border: none;
  font-size: .8rem;
}

.ans-why {
  font-size: .82rem;
  color: var(--text);
  line-height: 1.6;
  margin-top: 5px;
}

.explain-card {
  margin: 14px auto 4px;
  max-width: 560px;
  background: rgba(34, 211, 238, .05);
  border: 1px solid rgba(34, 211, 238, .2);
  border-radius: 12px;
  padding: 14px 18px;
  font-size: .88rem;
  color: #bae6fd;
  line-height: 1.7;
  text-align: left;
}

.explain-card-title {
  font-family: 'Space Mono', monospace;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--cyan-dim);
  margin-bottom: 8px;
}

.finish-btns {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 22px;
}

.btn {
  padding: 6px 18px;
  border-radius: 20px;
  font-family: 'Space Mono', monospace;
  font-size: .85rem;
  font-weight: 700;
  letter-spacing: .5px;
  cursor: pointer;
  transition: all .25s;
  border: 1px solid transparent;
}

.btn-primary {
  background: rgba(56, 189, 248, .15);
  color: var(--cyan);
  border-color: rgba(56, 189, 248, .3);
}

.btn-secondary {
  background: rgba(148, 163, 184, .1);
  color: var(--text);
  border-color: var(--border);
}

.btn-home {
  background: rgba(148, 163, 184, .08);
  color: var(--muted);
  border-color: var(--border);
  width: 100%;
  margin-top: 8px;
}

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

.btn-primary:hover {
  background: rgba(56, 189, 248, .25);
  border-color: rgba(56, 189, 248, .5);
  box-shadow: 0 0 14px rgba(56, 189, 248, .15);
}

/* Particles */
@keyframes particleFly {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }

  100% {
    transform: translate(var(--tx), var(--ty)) scale(0);
    opacity: 0;
  }
}

.particle {
  position: fixed;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  animation: particleFly .8s ease-out forwards;
}

/* ── TIMER ── */
.timer-box {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Space Mono', monospace;
  font-size: 1rem;
  font-weight: 700;
  padding: 4px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--card);
  transition: all .3s;
}

.timer-box.warn {
  border-color: rgba(251, 191, 36, .6);
  background: rgba(251, 191, 36, .08);
  color: var(--gold);
  animation: timerPulse .6s ease-in-out infinite alternate;
}

.timer-box.danger {
  border-color: rgba(248, 113, 113, .6);
  background: rgba(248, 113, 113, .1);
  color: var(--red);
  animation: timerPulse .3s ease-in-out infinite alternate;
}

@keyframes timerPulse {
  from {
    transform: scale(1);
  }

  to {
    transform: scale(1.06);
  }
}

.timer-num {
  font-size: 1.1rem;
  min-width: 28px;
  text-align: center;
}

/* ══════════════════════════════════
   TOUCH SUPPORT & RESPONSIVE
══════════════════════════════════ */

/* ── Tap-to-select highlight ── */
.choice.selected {
  border-color: var(--cyan);
  background: rgba(34, 211, 238, .15);
  box-shadow: 0 0 16px rgba(34, 211, 238, .3);
  transform: translateY(-2px);
  animation: selectedPulse 1.2s ease-in-out infinite;
}

@keyframes selectedPulse {
  0%, 100% { box-shadow: 0 0 16px rgba(34, 211, 238, .3); }
  50% { box-shadow: 0 0 24px rgba(34, 211, 238, .5); }
}

/* Mobile hint — shown only on touch devices */
.mobile-hint {
  text-align: center;
  font-size: .72rem;
  color: var(--muted);
  margin-bottom: 8px;
  font-family: 'Space Mono', monospace;
  display: none;
}

@media (hover: none) and (pointer: coarse) {
  .mobile-hint { display: block; }
}

/* Prevent tap-highlight and callout on touch */
@media (hover: none) {
  .choice, .drop-zone, .btn, .stage-card, .diff-card, .submit-btn {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
  }
}

/* ────────────────────────────────────
   TABLET  (max-width: 768px)
──────────────────────────────────── */
@media (max-width: 768px) {
  body {
    padding: 14px;
    align-items: flex-start;
  }

  .container {
    max-width: 100%;
  }

  .header {
    margin-bottom: 20px;
  }

  .header h1 {
    font-size: 1.55rem;
  }

  .header p {
    font-size: .82rem;
  }

  /* Difficulty select: 3 col still ok on tablet */
  .select-grid {
    gap: 14px;
  }

  /* Stage grid: 3 cols on tablet */
  .stage-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }

  pre {
    font-size: .82rem;
    padding: 16px 18px;
    line-height: 1.75;
  }

  .finish-screen {
    padding: 28px 16px;
  }

  .final-score {
    font-size: 2.4rem;
  }
}

/* ────────────────────────────────────
   MOBILE  (max-width: 640px)
──────────────────────────────────── */
@media (max-width: 640px) {
  body {
    padding: 10px;
    align-items: flex-start;
  }

  .container {
    max-width: 100%;
  }

  /* ── Navbar ── */
  .navbar {
    padding: 10px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
    gap: 8px;
  }

  .navbar-brand {
    font-size: .85rem;
  }

  .navbar-brand span {
    font-size: 1rem;
  }

  .navbar-info { display: none; }
  .navbar-divider { display: none; }

  .navbar-user { gap: 8px; }

  .navbar-avatar-wrap,
  .navbar-avatar {
    width: 30px;
    height: 30px;
  }

  .navbar-login-btn,
  .navbar-logout-btn {
    font-size: .68rem;
    padding: 5px 10px;
  }

  /* ── Header ── */
  .header {
    margin-bottom: 16px;
  }

  .header h1 {
    font-size: 1.2rem;
    letter-spacing: -0.5px;
  }

  .header p {
    font-size: .72rem;
  }

  /* ── Difficulty select ── */
  .select-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .diff-card {
    padding: 20px 16px 18px;
    border-radius: 12px;
  }

  .diff-icon {
    font-size: 2rem;
    margin-bottom: 8px;
  }

  .diff-title {
    font-size: .9rem;
  }

  .diff-desc {
    font-size: .75rem;
  }

  /* ── Stage select ── */
  .stage-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }

  .stage-card {
    padding: 18px 10px 14px;
    border-radius: 10px;
  }

  .stage-num {
    font-size: 1.6rem;
  }

  .stage-name {
    font-size: .72rem;
  }

  .stage-stars {
    font-size: .78rem;
  }

  .stage-done-badge {
    font-size: .6rem;
    top: 5px;
    right: 6px;
  }

  .back-btn {
    font-size: .78rem;
    margin-bottom: 14px;
  }

  .section-label {
    font-size: .68rem;
    margin-bottom: 10px;
  }

  .pts-note {
    font-size: .7rem;
  }

  /* ── Game screen ── */
  .total-score-bar {
    font-size: .72rem;
    margin-bottom: 8px;
  }

  .total-score-bar strong {
    font-size: .88rem;
  }

  .meta-bar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
    margin-bottom: 10px;
  }

  .badge {
    font-size: .68rem;
    padding: 3px 10px;
  }

  .score-box {
    font-size: .85rem;
  }

  .score-val {
    font-size: 1rem;
  }

  .timer-box {
    font-size: .85rem;
    padding: 3px 10px;
  }

  .timer-num {
    font-size: .95rem;
    min-width: 24px;
  }

  /* ── Code card ── */
  .code-card {
    border-radius: 10px;
    margin-bottom: 14px;
  }

  .code-title-bar {
    padding: 6px 10px;
  }

  .code-title-bar span {
    font-size: .62rem;
  }

  .dot {
    width: 8px;
    height: 8px;
  }

  pre {
    font-size: .72rem;
    padding: 12px 10px;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
  }

  .drop-zone {
    min-width: 60px;
    height: 26px;
    font-size: .68rem;
    padding: 0 6px;
    border-width: 1.5px;
  }

  /* ── Choices ── */
  .choices-label {
    font-size: .68rem;
    letter-spacing: 1px;
    margin-bottom: 8px;
  }

  .choices-grid {
    gap: 8px;
    margin-bottom: 14px;
  }

  .choice {
    font-size: .75rem;
    padding: 10px 14px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
  }

  /* ── Submit ── */
  .submit-wrap {
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
  }

  .submit-btn {
    width: 100%;
    padding: 12px 18px;
    min-height: 44px;
    font-size: .82rem;
  }

  .submit-hint {
    font-size: .72rem;
    text-align: center;
  }

  /* ── Result box ── */
  .result-box {
    padding: 10px 14px;
    font-size: .85rem;
    gap: 10px;
    margin-bottom: 10px;
  }

  .result-icon {
    font-size: 1.2rem;
  }

  /* ── Finish screen ── */
  .finish-screen {
    padding: 20px 10px;
  }

  .finish-screen .trophy {
    font-size: 3rem;
  }

  .finish-screen h2 {
    font-size: 1.2rem;
  }

  .final-score {
    font-size: 2rem;
  }

  .star-row {
    font-size: 1.5rem;
    letter-spacing: 4px;
  }

  /* ── Answer review ── */
  .answer-section {
    max-width: 100%;
    margin: 14px auto 4px;
  }

  .answer-section-title {
    font-size: .65rem;
  }

  .answer-row {
    flex-direction: column;
    gap: 6px;
    padding: 10px 10px;
  }

  .answer-badge {
    font-size: .68rem;
    padding: 2px 8px;
  }

  .ans-label {
    font-size: .7rem !important;
  }

  .ans-val-row {
    flex-wrap: wrap;
    gap: 6px;
  }

  .ans-chip {
    font-size: .75rem;
    padding: 2px 8px;
  }

  .ans-why {
    font-size: .72rem;
  }

  /* ── Explain card ── */
  .explain-card {
    padding: 10px 12px;
    font-size: .78rem;
    max-width: 100%;
  }

  .explain-card-title {
    font-size: .62rem;
  }

  /* ── Buttons ── */
  .finish-btns {
    gap: 10px;
    margin-top: 16px;
  }

  .btn {
    padding: 10px 16px;
    font-size: .78rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .btn-home {
    margin-top: 6px;
    min-height: 44px;
  }

  .finish-explain {
    padding: 10px 14px;
    font-size: .8rem;
  }
}

/* ────────────────────────────────────
   SMALL PHONE  (max-width: 380px)
──────────────────────────────────── */
@media (max-width: 380px) {
  body {
    padding: 6px;
  }

  .navbar {
    padding: 8px 10px;
    border-radius: 8px;
    margin-bottom: 12px;
  }

  .navbar-brand {
    font-size: .75rem;
  }

  .navbar-brand span {
    font-size: .88rem;
  }

  .header h1 {
    font-size: 1rem;
  }

  .header p {
    font-size: .65rem;
  }

  .header {
    margin-bottom: 12px;
  }

  .diff-card {
    padding: 16px 12px 14px;
  }

  .diff-icon {
    font-size: 1.6rem;
  }

  .diff-title {
    font-size: .82rem;
  }

  .stage-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .stage-card {
    padding: 14px 8px 12px;
  }

  .stage-num {
    font-size: 1.3rem;
  }

  .stage-name {
    font-size: .65rem;
  }

  pre {
    font-size: .65rem;
    padding: 10px 8px;
    line-height: 1.6;
  }

  .drop-zone {
    min-width: 48px;
    height: 24px;
    font-size: .62rem;
    padding: 0 4px;
  }

  .choice {
    font-size: .7rem;
    padding: 8px 10px;
    min-height: 40px;
  }

  .choices-grid {
    gap: 6px;
  }

  .meta-bar {
    padding: 6px 8px;
    gap: 6px;
  }

  .badge {
    font-size: .62rem;
    padding: 2px 8px;
  }

  .timer-box {
    font-size: .78rem;
    padding: 2px 8px;
  }

  .final-score {
    font-size: 1.6rem;
  }

  .finish-screen .trophy {
    font-size: 2.4rem;
  }

  .finish-screen h2 {
    font-size: 1rem;
  }

  .star-row {
    font-size: 1.2rem;
  }

  .btn {
    font-size: .72rem;
    padding: 8px 12px;
  }
}

/* ────────────────────────────────────
   LARGE SCREEN  (min-width: 1200px)
──────────────────────────────────── */
@media (min-width: 1200px) {
  .container {
    max-width: 900px;
  }

  .select-grid {
    gap: 22px;
  }

  .diff-card {
    padding: 32px 22px 26px;
  }

  .stage-grid {
    gap: 16px;
  }

  pre {
    font-size: .92rem;
    padding: 22px 28px;
  }
}

/* ────────────────────────────────────
   SAFE-AREA (notch / dynamic island)
──────────────────────────────────── */
@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-top: max(14px, env(safe-area-inset-top));
    padding-bottom: max(14px, env(safe-area-inset-bottom));
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
}

/* ────────────────────────────────────
   LANDSCAPE PHONE
──────────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  body {
    align-items: flex-start;
    padding: 8px;
  }

  .header {
    margin-bottom: 10px;
  }

  .header h1 {
    font-size: 1.1rem;
  }

  .finish-screen .trophy {
    font-size: 2rem;
  }

  .finish-screen h2 {
    font-size: 1rem;
  }

  .final-score {
    font-size: 1.8rem;
  }

  .star-row {
    font-size: 1.2rem;
    margin: 6px 0;
  }

  .select-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }

  .diff-card {
    padding: 14px 12px;
  }

  .diff-icon {
    font-size: 1.6rem;
    margin-bottom: 4px;
  }
}