/* ═══════════════════════════════════════════
   PIXEL CODING — style.css
   Proportional, Responsive & Natural UI
═══════════════════════════════════════════ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

:root {
  /* Color Palette — Clean Natural Educational Theme */
  --bg-page: #0f1422;
  --bg-panel: #182032;
  --bg-card: #202b42;
  --bg-card-hover: #293754;
  --bg-input: #121927;

  --border: #2e3c5a;
  --border-light: #3d4f75;
  --border-focus: #3b82f6;

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-active: #1d4ed8;

  --success: #10b981;
  --success-hover: #059669;

  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 10px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);

  /* 8 Standard Pixel Colors */
  --px-1: #f8fafc; /* 1: Putih */
  --px-2: #1e293b; /* 2: Hitam */
  --px-3: #ef4444; /* 3: Merah */
  --px-4: #eab308; /* 4: Kuning */
  --px-5: #22c55e; /* 5: Hijau */
  --px-6: #a855f7; /* 6: Ungu */
  --px-7: #f97316; /* 7: Oranye */
  --px-8: #3b82f6; /* 8: Biru */

  /* Dynamic Proportional Arena Sizing — Large & Strictly 1-Screen */
  --current-rows: 8;
  --current-cols: 8;
  --arena-row-h: clamp(26px, calc((100dvh - 160px) / (var(--current-rows, 8) + 0.25)), 56px);
  --arena-code-w: clamp(140px, 20vw, 240px);
}

/* Light Theme */
body.light-mode {
  --bg-page: #f1f5f9;
  --bg-panel: #ffffff;
  --bg-card: #e2e8f0;
  --bg-card-hover: #cbd5e1;
  --bg-input: #f8fafc;

  --border: #cbd5e1;
  --border-light: #94a3b8;
  --border-focus: #2563eb;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;

  --shadow-md: 0 4px 10px rgba(0, 0, 0, 0.08);
}

html, body {
  width: 100%;
  height: 100%;
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  overflow-x: hidden;
}

.bg-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 28px 28px;
}

/* ════════════════════════════════════════
   PAGES SYSTEM
════════════════════════════════════════ */
.page {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 100vh;
  display: none;
  flex-direction: column;
}

.page.active {
  display: flex;
}

/* 1-Screen Viewport Fit on Desktop */
#page-game.active {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ════════════════════════════════════════
   HEADER
════════════════════════════════════════ */
.game-header {
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background-color: var(--bg-panel);
  border-bottom: 1.5px solid var(--border);
  z-index: 50;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--primary);
}

.header-svg-icon {
  stroke: var(--primary);
  flex-shrink: 0;
}

.game-title {
  font-size: clamp(0.9rem, 2vw, 1.05rem);
  font-weight: 900;
  letter-spacing: -0.2px;
  color: var(--text-main);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
  border-color: var(--border-light);
}

.header-center {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.player-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.player-label strong {
  color: var(--text-main);
}

.score-pill {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 800;
}
.score-pill span {
  color: var(--warning);
}

.level-chip {
  background: var(--primary);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.question-chip {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--text-muted);
  white-space: nowrap;
}

.game-stats-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stat-badge {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 3px;
}

.stat-badge.score span {
  color: var(--warning);
}

.stat-badge.lives {
  display: flex;
  align-items: center;
  gap: 2px;
}

.heart-svg {
  width: 14px;
  height: 14px;
  fill: var(--danger);
  flex-shrink: 0;
}
.heart-svg.empty {
  fill: var(--text-dim);
  opacity: 0.4;
}

.stat-badge.timer {
  font-family: monospace;
  color: var(--info);
  font-size: 0.8rem;
}

/* ════════════════════════════════════════
   BUTTONS
════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
  border-color: #2563eb;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
  border-color: var(--primary-active);
}

/* Pulsing glow for the main CTA button (Mulai Permainan) */
#btn-start {
  position: relative;
  animation: btn-pulse 2.4s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5);
}
@keyframes btn-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.55); }
  60%  { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); }
  100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}
#btn-start:hover,
#btn-start:active {
  animation: none;
}

.btn-secondary {
  background-color: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border);
}
.btn-secondary:hover {
  background-color: var(--bg-card-hover);
  border-color: var(--border-light);
}

.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
}
.btn-danger:hover {
  background-color: #dc2626;
}

.btn-lg {
  padding: 0.65rem 1.35rem;
  font-size: 0.95rem;
}

.btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}

.btn-xs {
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
}

.btn-block {
  width: 100%;
}

/* ════════════════════════════════════════
   HOME PAGE
════════════════════════════════════════ */
.home-main {
  flex: 1;
  max-width: 920px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2.25rem;
}

.hero-section {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.hero-badge {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
}

.hero-title {
  font-size: clamp(1.6rem, 4vw, 2.5rem);
  font-weight: 900;
  line-height: 1.25;
  letter-spacing: -0.5px;
}

.hero-title .highlight {
  color: var(--primary);
}

.hero-desc {
  font-size: clamp(0.85rem, 1.5vw, 1rem);
  color: var(--text-muted);
  max-width: 580px;
  line-height: 1.55;
  font-weight: 600;
}

.feature-pills {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.pill {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 800;
}
.pill-1 { border-left: 3px solid var(--primary); }
.pill-2 { border-left: 3px solid var(--success); }
.pill-3 { border-left: 3px solid var(--warning); }

.home-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 0.75rem;
  justify-content: center;
  align-items: center;
  margin-top: 0.5rem;
  width: 100%;
  max-width: 440px;
}
.home-actions .btn {
  flex: 1 1 0;
  min-width: 0;
  white-space: nowrap;
}

.player-form {
  display: none;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 1rem;
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 360px;
  margin-top: 0.5rem;
}
.player-form.show {
  display: flex;
}
.player-form label {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--text-muted);
}
.input-inline {
  display: flex;
  gap: 0.4rem;
}
.input-inline input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  outline: none;
}
.input-inline input:focus {
  border-color: var(--border-focus);
}

.concept-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  width: 100%;
}

.concept-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 1.25rem;
  border-radius: var(--radius-md);
  text-align: left;
  transition: border-color 0.15s;
}
.concept-card:hover {
  border-color: var(--border-light);
}

.concept-icon-wrap {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.concept-card h3 {
  font-size: 0.95rem;
  font-weight: 800;
  margin-bottom: 0.35rem;
}
.concept-card p {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* ════════════════════════════════════════
   TUTORIAL PAGE
════════════════════════════════════════ */
.tutorial-content {
  max-width: 680px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.tutorial-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.tutorial-header-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.level-tag {
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
}
.level-tag-1 { background: var(--primary); color: #fff; }
.level-tag-2 { background: var(--success); color: #fff; }
.level-tag-3 { background: var(--warning); color: #0f172a; }

.tutorial-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.tutorial-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.code-pill {
  font-family: monospace;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--info);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-sm);
}

.arrow-sep {
  font-size: 1.1rem;
  color: var(--text-dim);
}

.pixel-preview-row {
  display: flex;
  gap: 2px;
}

.demo-px {
  width: 16px;
  height: 16px;
  border-radius: 2px;
  display: inline-block;
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.demo-px.w { background: var(--px-1); border-color: #cbd5e1; }
.demo-px.b { background: var(--px-2); border-color: #334155; }

.tutorial-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

.color-palette-guide {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 800;
}

.guide-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.chip-dot {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  display: inline-block;
}

/* ════════════════════════════════════════
   LEVEL SELECT PAGE
════════════════════════════════════════ */
.level-select-content {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  align-items: center;
}

.section-heading {
  text-align: center;
}
.section-title {
  font-size: 1.45rem;
  font-weight: 900;
}
.section-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.level-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.15rem;
  width: 100%;
}

.level-card {
  background: var(--bg-panel);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.35rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  cursor: pointer;
  transition: all 0.15s;
}

.level-card:hover {
  border-color: var(--border-focus);
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.level-card.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.level-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.level-badge-sm {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--primary);
  background: var(--bg-card);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}

.level-stars-display {
  font-size: 0.95rem;
  color: var(--warning);
  letter-spacing: 1px;
}

.level-card-title {
  font-size: 1rem;
  font-weight: 800;
}

.level-card-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
  flex: 1;
}

.level-card-footer {
  margin-top: 0.4rem;
}

.status-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-dim);
}
.status-tag.unlocked {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
}

.achievements-section {
  width: 100%;
  margin-top: 0.5rem;
}
.sub-section-title {
  font-size: 0.9rem;
  font-weight: 800;
  margin-bottom: 0.65rem;
}
.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.6rem;
}

.achievement-item {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 0.65rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  opacity: 0.45;
}
.achievement-item.unlocked {
  opacity: 1;
  border-color: rgba(245, 158, 11, 0.4);
}
.ach-icon-circle {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.ach-name {
  font-size: 0.75rem;
  font-weight: 800;
}
.ach-desc {
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* ════════════════════════════════════════
   GAMEPLAY SCREEN (PROPORTIONAL 1-SCREEN)
════════════════════════════════════════ */
.game-info-bar {
  height: 38px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  gap: 0.5rem;
}

.info-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow: hidden;
}

.theme-tag {
  font-size: 0.75rem;
  font-weight: 800;
  background: var(--bg-card);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--warning);
  white-space: nowrap;
}

.task-instruction {
  font-size: clamp(0.75rem, 1.3vw, 0.85rem);
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.color-palette-bar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--bg-card);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.palette-label {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--text-muted);
  white-space: nowrap;
}

.palette-chips {
  display: flex;
  gap: 3px;
}

.p-chip {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}
.p-chip:hover {
  transform: scale(1.2);
}
.p-chip.selected {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px var(--border-focus);
  transform: scale(1.15);
}

.hint-count-pill {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  font-size: 0.65rem;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  font-weight: 800;
}

/* ════════════════════════════════════════
   MAIN ARENA: PROPORTIONAL ROW-ALIGNED GRID
════════════════════════════════════════ */
.game-arena-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.75rem;
  overflow: hidden;
  box-sizing: border-box;
}

.game-arena {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--bg-panel);
  border: 2px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: calc(100dvh - 142px);
  touch-action: none;
  box-sizing: border-box;
}

.arena-row {
  display: flex;
  align-items: center;
  gap: clamp(6px, 1.2vw, 14px);
  height: var(--arena-row-h);
}

.arena-row-label {
  width: 28px;
  font-family: monospace;
  font-size: clamp(0.75rem, 1.1vw, 0.95rem);
  font-weight: 900;
  color: var(--text-dim);
  text-align: right;
  flex-shrink: 0;
}

/* Left Tokens for Level 1 & 3A */
.arena-row-code {
  width: var(--arena-code-w);
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  white-space: nowrap;
  flex-shrink: 0;
  scrollbar-width: none;
}
.arena-row-code::-webkit-scrollbar { display: none; }

.code-badge {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  color: var(--info);
  font-family: monospace;
  font-size: clamp(0.82rem, 1.2vw, 1.05rem);
  font-weight: 900;
  padding: 2px 7px;
  border-radius: 4px;
  line-height: 1.2;
}

.color-badge-num {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: clamp(0.68rem, 1vw, 0.76rem);
  font-weight: 800;
  line-height: 1.2;
}

.color-dot {
  width: 7px;
  height: 7px;
  border-radius: 2px;
  display: inline-block;
  flex-shrink: 0;
}

/* Pixel Cells — Always Square Aspect Ratio */
.arena-pixel-row {
  display: flex;
  gap: 3px;
  height: 100%;
  touch-action: none;
}

.px-cell {
  height: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 4px;
  border: 1.5px solid rgba(255, 255, 255, 0.12);
  cursor: pointer;
  transition: transform 0.06s, filter 0.06s;
  flex-shrink: 0;
}
.px-cell:hover {
  filter: brightness(1.2);
  transform: scale(1.06);
  z-index: 2;
}
.px-cell:active {
  transform: scale(0.95);
}
.px-cell.readonly {
  cursor: default;
}
.px-cell.readonly:hover {
  transform: none;
  filter: none;
}

.px-cell.c-1 { background-color: var(--px-1); border-color: #cbd5e1; }
.px-cell.c-2 { background-color: var(--px-2); border-color: #334155; }
.px-cell.c-3 { background-color: var(--px-3); border-color: #dc2626; }
.px-cell.c-4 { background-color: var(--px-4); border-color: #ca8a04; }
.px-cell.c-5 { background-color: var(--px-5); border-color: #16a34a; }
.px-cell.c-6 { background-color: var(--px-6); border-color: #9333ea; }
.px-cell.c-7 { background-color: var(--px-7); border-color: #ea580c; }
.px-cell.c-8 { background-color: var(--px-8); border-color: #2563eb; }

.px-cell.wrong-highlight {
  outline: 2px solid var(--danger);
  animation: shake 0.3s ease;
}

/* Right Input for Level 2 & 3B */
.arena-row-input {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 150px;
}

.row-text-input {
  flex: 1;
  max-width: 260px;
  height: 90%;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  color: var(--text-main);
  border-radius: 6px;
  padding: 0 8px;
  font-family: monospace;
  font-size: clamp(0.82rem, 1.1vw, 0.95rem);
  font-weight: 800;
  outline: none;
}
.row-text-input:focus {
  border-color: var(--border-focus);
}
.row-text-input.invalid {
  border-color: var(--danger);
  animation: shake 0.3s ease;
}

.row-sum-tag {
  font-size: clamp(0.72rem, 1vw, 0.82rem);
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text-dim);
  white-space: nowrap;
}
.row-sum-tag.ok {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
}
.row-sum-tag.bad {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

/* ════════════════════════════════════════
   BOTTOM ACTION BAR
════════════════════════════════════════ */
.game-actions-bar {
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  background: var(--bg-panel);
  border-top: 1.5px solid var(--border);
  padding: 0 1rem;
}

.combo-banner {
  position: absolute;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--warning);
  color: #0f172a;
  padding: 0.2rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 900;
  z-index: 40;
  box-shadow: var(--shadow-md);
}

/* ════════════════════════════════════════
   MODAL DIALOGS
════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.dialog-box {
  background: var(--bg-panel);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  max-width: 360px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: var(--shadow-lg);
}

.dialog-header {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.dialog-header h3 {
  font-size: 1.05rem;
  font-weight: 800;
}
.dialog-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.45;
}
.dialog-body {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.dialog-footer {
  display: flex;
  gap: 0.45rem;
  justify-content: flex-end;
  margin-top: 0.35rem;
}

/* Feedback & Image Reveal Modal */
.feedback-modal-box {
  background: var(--bg-panel);
  border: 1.5px solid var(--success);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  max-width: 340px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 2;
}

.feedback-modal-box.wrong {
  border-color: var(--danger);
}

.feedback-status-badge {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 900;
}
.feedback-modal-box.wrong .feedback-status-badge {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.feedback-title {
  font-size: 1.15rem;
  font-weight: 900;
}
.feedback-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.reveal-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.65rem;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.reveal-title {
  font-size: 0.8rem;
  font-weight: 700;
}

.preview-12-grid {
  display: grid;
  gap: 1.5px;
  width: 140px;
  height: 140px;
  background: #ffffff;
  border: 2px solid #94a3b8;
  padding: 4px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.preview-px {
  aspect-ratio: 1;
  border-radius: 1px;
}

.feedback-score-display {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--warning);
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

/* ════════════════════════════════════════
   RESULT PAGE
════════════════════════════════════════ */
.result-content {
  flex: 1;
  max-width: 560px;
  margin: 0 auto;
  padding: 2rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1rem;
}

.result-icon-wrap {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(245, 158, 11, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.result-title {
  font-size: 1.3rem;
  font-weight: 900;
}

.result-stats-table {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
  width: 100%;
}

.res-stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 0.65rem 0.35rem;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.res-stat-num {
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--primary);
}
.res-stat-lbl {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 700;
}

.result-stars-row {
  font-size: 1.5rem;
  letter-spacing: 3px;
  color: var(--warning);
}

.learning-insight-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem;
  display: flex;
  gap: 0.65rem;
  text-align: left;
  align-items: flex-start;
  width: 100%;
}
.insight-icon {
  flex-shrink: 0;
  margin-top: 2px;
}
.insight-body {
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text-muted);
}
.insight-body strong {
  color: var(--text-main);
}

.new-achievement-box {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.65rem;
  width: 100%;
}
.new-achievement-box h4 {
  font-size: 0.8rem;
  color: var(--warning);
  margin-bottom: 0.3rem;
}

.result-actions-row {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 0.25rem;
}

/* ════════════════════════════════════════
   UTILITY & ANIMATIONS
════════════════════════════════════════ */
.hidden {
  display: none !important;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-3px); }
  40%, 80% { transform: translateX(3px); }
}

.score-pop {
  position: fixed;
  z-index: 120;
  pointer-events: none;
  font-size: 0.9rem;
  font-weight: 900;
  color: var(--warning);
  animation: floatUp 0.9s ease forwards;
}

@keyframes floatUp {
  0% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-40px); opacity: 0; }
}

/* ════════════════════════════════════════
   RESPONSIVE MEDIA QUERIES
════════════════════════════════════════ */
@media (max-width: 768px) {
  :root {
    --arena-code-w: 120px;
  }
  .task-instruction {
    display: none;
  }
  .level-cards {
    grid-template-columns: 1fr;
  }
  .concept-cards {
    grid-template-columns: 1fr;
  }
  /* Game info bar: stack left content only */
  .game-info-bar {
    padding: 0 0.75rem;
    gap: 0.4rem;
  }
}

/* ── Mobile ≤ 600px (phone portrait) ── */
@media (max-width: 600px) {
  :root {
    --arena-row-h: clamp(20px, calc((100dvh - 138px) / (var(--current-rows, 8) + 0.4)), 36px);
    --arena-code-w: clamp(72px, 26vw, 105px);
  }

  /* ── GAME HEADER ── */
  .game-header {
    padding: 0 0.4rem;
    gap: 0.3rem;
    height: 44px;
  }
  /* Hide "Keluar" label, keep only the arrow icon */
  .btn-exit .btn-text {
    display: none;
  }
  .btn-exit {
    padding: 0.2rem 0.4rem;
    min-width: 0;
  }

  /* Level chip: compact, ellipsis if still long */
  .level-chip {
    font-size: 0.68rem;
    padding: 0.15rem 0.45rem;
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .question-chip {
    font-size: 0.72rem;
  }

  /* Stats: tighter */
  .game-stats-row {
    gap: 0.2rem;
  }
  .stat-badge {
    padding: 0.12rem 0.3rem;
    font-size: 0.68rem;
    gap: 2px;
  }
  /* Hide "Poin" text, show just number */
  .stat-unit {
    display: none;
  }
  .heart-svg {
    width: 12px;
    height: 12px;
  }

  /* ── GAME INFO BAR ── */
  .game-info-bar {
    height: 34px;
    padding: 0 0.4rem;
    gap: 0.3rem;
  }
  .theme-tag {
    font-size: 0.68rem;
    padding: 0.12rem 0.4rem;
  }
  .task-instruction {
    display: none;
  }
  /* Color palette: tighter */
  .palette-label {
    display: none;         /* hide "Pilih Warna:" text to save space */
  }
  .color-palette-bar {
    padding: 0.15rem 0.35rem;
    gap: 0.25rem;
  }
  .p-chip {
    width: 20px;
    height: 20px;
    font-size: 0.62rem;
  }

  /* ── ARENA ── */
  .game-arena-wrapper {
    padding: 0.15rem 0.35rem;
  }
  .game-arena {
    padding: 5px 7px;
    gap: 2px;
    max-height: calc(100dvh - 138px);
  }
  .arena-row {
    gap: 3px;
  }
  .arena-row-label {
    width: 18px;
    font-size: 0.58rem;
  }
  .code-badge {
    padding: 1px 3px;
    font-size: 0.68rem;
    border-width: 1px;
  }
  .px-cell {
    border-radius: 2px;
    border-width: 1px;
  }
  .row-text-input {
    font-size: 0.75rem;
    padding: 0 5px;
    border-radius: 4px;
  }
  .row-sum-tag {
    font-size: 0.65rem;
    padding: 1px 4px;
  }

  /* ── ACTION BAR ── */
  .game-actions-bar {
    padding: 0 0.4rem;
    gap: 0.4rem;
    height: 44px;
  }
  .game-actions-bar .btn {
    font-size: 0.78rem;
    padding: 0.3rem 0.7rem;
  }

  /* ── HOME ACTIONS in 1 row ── */
  .home-actions {
    gap: 0.5rem;
    max-width: 100%;
    padding: 0 1rem;
  }
  .home-actions .btn {
    font-size: 0.85rem;
    padding: 0.55rem 0.75rem;
  }

  /* Result */
  .result-stats-table {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── Very small phones ≤ 380px ── */
@media (max-width: 380px) {
  :root {
    --arena-code-w: 65px;
    --arena-row-h: clamp(18px, calc((100dvh - 135px) / (var(--current-rows, 8) + 0.4)), 30px);
  }
  .level-chip {
    max-width: 72px;
    font-size: 0.62rem;
  }
  .game-actions-bar .btn {
    font-size: 0.72rem;
    padding: 0.28rem 0.5rem;
  }
  .code-badge {
    font-size: 0.6rem;
    padding: 0 2px;
  }
  .p-chip {
    width: 18px;
    height: 18px;
    font-size: 0.56rem;
  }
}

/* ── Landscape Mobile (short screens) ── */
@media (max-height: 520px) {
  :root {
    --arena-row-h: calc((100dvh - 108px) / (var(--current-rows, 8) + 0.3));
  }
  .game-header {
    height: 36px;
  }
  .game-info-bar {
    height: 28px;
  }
  .game-actions-bar {
    height: 36px;
  }
  .game-arena {
    max-height: calc(100dvh - 108px);
    padding: 3px 5px;
  }
}

/* ════════════════════════════════════════
   BANNER TRAKTIR KOPI (Saweria)
════════════════════════════════════════ */
.saweria-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #000167;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.35);
  z-index: 9999;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.banner-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 1200px;
  gap: 16px;
}

.banner-text {
  color: #e2e8f0;
  font-size: 0.85rem;
  line-height: 1.4;
  flex: 1;
}

.banner-bold {
  font-weight: 800;
  color: #60a5fa;
  display: block;
  margin-bottom: 2px;
  font-size: 0.95rem;
}

.saweria-btn {
  background: #ea580c;
  color: white;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  transition: all 0.2s ease;
  white-space: nowrap;
  font-size: 0.9rem;
  font-family: 'Nunito', sans-serif;
}

.saweria-btn:hover {
  background: #c2410c;
  transform: translateY(-2px);
}

.saweria-btn i {
  font-size: 1rem;
}

/* Kompensasi tinggi banner agar konten tidak tertutup */
body {
  padding-bottom: 56px;
}

/* Halaman game: kurangi arena height agar tidak tertutup banner */
#page-game.active {
  height: calc(100dvh - 56px);
  height: calc(100vh - 56px);
}

:root {
  --arena-row-h: clamp(26px, calc((100dvh - 216px) / (var(--current-rows, 8) + 0.25)), 56px);
}

@media (max-width: 480px) {
  .saweria-banner {
    padding: 8px 12px;
  }
  .banner-text {
    font-size: 0.7rem;
  }
  .banner-bold {
    font-size: 0.8rem;
  }
  .saweria-btn {
    padding: 6px 12px;
    font-size: 0.8rem;
    gap: 6px;
  }
  .saweria-btn i {
    font-size: 0.9rem;
  }
  body {
    padding-bottom: 50px;
  }
  #page-game.active {
    height: calc(100dvh - 50px);
    height: calc(100vh - 50px);
  }
  :root {
    --arena-row-h: clamp(22px, calc((100dvh - 210px) / (var(--current-rows, 8) + 0.25)), 48px);
  }
}

@media (max-height: 520px) {
  body {
    padding-bottom: 46px;
  }
  :root {
    --arena-row-h: calc((100dvh - 154px) / (var(--current-rows, 8) + 0.3));
  }
}
