/* ── Reset ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Base ────────────────────────────────────────── */
body {
  background: #0d1117;
  color: #e6edf3;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 20px 80px;
}

a { color: #6eb5ff; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── HUD ─────────────────────────────────────────── */
#hud {
  width: 100%;
  max-width: 900px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  font-size: 13px;
  color: #8b949e;
}

.level-badge {
  background: #1a3a5e;
  color: #79c0ff;
  border: 1px solid #388bfd44;
  border-radius: 20px;
  padding: 3px 14px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* ── Level header ────────────────────────────────── */
#level-header {
  width: 100%;
  max-width: 900px;
  margin-bottom: 16px;
}

#story-text {
  font-size: 17px;
  font-weight: 500;
  color: #e6edf3;
  margin-bottom: 4px;
  font-style: italic;
  opacity: 0.8;
}

#guide-text {
  font-size: 13px;
  color: #58a6ff;
  font-family: 'Courier New', Courier, monospace;
  letter-spacing: 0.3px;
}

/* ── Two-pane game container ──────────────────────── */
#game-container {
  width: 100%;
  max-width: 900px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

.pane-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #484f58;
  margin-bottom: 8px;
}

/* ── Editor pane ─────────────────────────────────── */
#editor-box {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 28px 24px;
  min-height: 100px;
}

#editor-area {
  font-family: 'Courier New', Courier, monospace;
  font-size: 22px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: keep-all;
}

/* Locked (pre-filled) text */
#editor-area .locked {
  color: #8b949e;
}

/* Completed phase syntax */
#editor-area .filled {
  color: #3fb950;
  font-weight: 700;
}

/* Slot: cursor position (next char to type) */
#editor-area .slot-cursor {
  color: #e6edf3;
  border-bottom: 3px solid #58a6ff;
  animation: blink 1s step-end infinite;
}

/* Slot: correctly typed */
#editor-area .slot-correct {
  color: #3fb950;
  font-weight: 700;
}

/* Slot: incorrectly typed */
#editor-area .slot-error {
  color: #f85149;
  background: #3d1a1a;
  border-radius: 2px;
}

/* Slot: not yet typed in current phase */
#editor-area .slot-empty {
  color: #484f58;
  border-bottom: 2px dashed #388bfd66;
}

/* Slot: future phase placeholder */
#editor-area .slot-future {
  color: #2d333b;
  border-bottom: 2px dashed #30363d;
}

@keyframes blink {
  0%, 100% { border-bottom-color: #58a6ff; }
  50%       { border-bottom-color: transparent; }
}

/* IME warning */
#ime-warning {
  margin-top: 10px;
  font-size: 12px;
  color: #f0883e;
  display: none;
}
#ime-warning.visible { display: block; }

/* ── Preview pane ────────────────────────────────── */
#preview-box {
  background: #ffffff;
  border-radius: 10px;
  padding: 28px 24px;
  min-height: 100px;
  overflow: hidden;
}

#preview-card {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: #24292f;
}

/* Markdown output inside preview */
#preview-card h1 { font-size: 30px; font-weight: 700; border-bottom: 2px solid #d0d7de; padding-bottom: 8px; margin-bottom: 12px; }
#preview-card h2 { font-size: 22px; font-weight: 600; border-bottom: 1px solid #d0d7de; padding-bottom: 6px; margin-bottom: 10px; }
#preview-card h3 { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
#preview-card p  { margin: 0; }
#preview-card strong { font-weight: 700; }
#preview-card em { font-style: italic; }
#preview-card a  { color: #0969da; text-decoration: underline; }
#preview-card code {
  background: #f6f8fa;
  border: 1px solid #d0d7de;
  border-radius: 3px;
  padding: 2px 6px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 14px;
}
#preview-card pre {
  background: #f6f8fa;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  padding: 16px;
  overflow-x: auto;
}
#preview-card pre code { background: none; border: none; padding: 0; }
#preview-card ul, #preview-card ol { padding-left: 24px; }
#preview-card li { margin: 6px 0; }

/* ── Feedback animations ─────────────────────────── */

/* Level 1 — H1 boom: expand + glow */
@keyframes boom {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.18); letter-spacing: 3px; }
  65%  { transform: scale(1.06); }
  100% { transform: scale(1); letter-spacing: normal; }
}
#preview-card.fx-boom h1 {
  animation: boom 0.75s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
  display: block;
  transform-origin: left center;
}

/* Level 2 — H3 shrink: scale in from larger */
@keyframes shrink {
  0%   { transform: scale(1.3); opacity: 0.6; }
  60%  { transform: scale(0.92); }
  100% { transform: scale(1); opacity: 1; }
}
#preview-card.fx-shrink h3 {
  animation: shrink 0.6s ease-out both;
  display: block;
  transform-origin: left center;
}

/* Level 3 — Bold shake: horizontal jolt */
@keyframes hshake {
  0%, 100% { transform: translateX(0); }
  15%  { transform: translateX(-8px); }
  35%  { transform: translateX(8px); }
  55%  { transform: translateX(-5px); }
  75%  { transform: translateX(5px); }
}
#preview-card.fx-shake {
  animation: hshake 0.55s ease-in-out;
}

/* Level 4 — Italic tilt: wind sway */
@keyframes sway {
  0%   { transform: rotate(0deg); }
  20%  { transform: rotate(-2.5deg); }
  50%  { transform: rotate(2.5deg); }
  80%  { transform: rotate(-1.5deg); }
  100% { transform: rotate(0deg); }
}
#preview-card.fx-tilt {
  animation: sway 0.9s ease-in-out;
  transform-origin: top center;
}

/* Level 5 — List pop-in: items appear with stagger */
@keyframes popIn {
  0%   { opacity: 0; transform: translateX(-12px); }
  100% { opacity: 1; transform: translateX(0); }
}
#preview-card.fx-pop li {
  animation: popIn 0.35s ease-out both;
}
#preview-card.fx-pop li:nth-child(1) { animation-delay: 0.00s; }
#preview-card.fx-pop li:nth-child(2) { animation-delay: 0.12s; }
#preview-card.fx-pop li:nth-child(3) { animation-delay: 0.24s; }

/* ── Hidden input trap ───────────────────────────── */
#input-trap {
  position: absolute;
  left: -9999px;
  opacity: 0;
  width: 1px;
  height: 1px;
}

/* ── Footer ──────────────────────────────────────── */
footer {
  margin-top: 48px;
  font-size: 13px;
  color: #484f58;
  text-align: center;
}

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 680px) {
  #game-container {
    grid-template-columns: 1fr;
  }
  #editor-area { font-size: 18px; }
}

/* ═══════════════════════════════════════════════════
   INTRO PAGE (index.html)
   ═══════════════════════════════════════════════════ */
.back-link {
  align-self: flex-start;
  margin-bottom: 40px;
  font-size: 14px;
  letter-spacing: 0.5px;
}

.intro-wrap {
  width: 100%;
  max-width: 640px;
  text-align: center;
  margin-top: 20px;
}

.intro-wrap h1 {
  font-size: clamp(32px, 6vw, 52px);
  font-weight: 700;
  letter-spacing: -1px;
  margin-bottom: 16px;
}

.intro-wrap .tagline {
  font-size: 18px;
  color: #8b949e;
  margin-bottom: 40px;
  line-height: 1.5;
}

.level-pills {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 48px;
}

.level-pill {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 12px 20px;
  text-align: left;
  min-width: 140px;
}

.pill-num {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: #484f58;
  margin-bottom: 4px;
}

.pill-name {
  font-size: 15px;
  font-weight: 600;
  color: #e6edf3;
}

.pill-example {
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  color: #8b949e;
  margin-top: 4px;
}

.btn-start {
  display: inline-block;
  background: #238636;
  color: #fff;
  text-decoration: none;
  padding: 14px 48px;
  border-radius: 8px;
  font-size: 17px;
  font-weight: 600;
  transition: background 0.2s, transform 0.15s;
}
.btn-start:hover { background: #2ea043; transform: translateY(-2px); text-decoration: none; }

.intro-note {
  margin-top: 20px;
  font-size: 13px;
  color: #484f58;
}

/* ═══════════════════════════════════════════════════
   COMPLETE PAGE (complete.html)
   ═══════════════════════════════════════════════════ */
.complete-wrap {
  width: 100%;
  max-width: 560px;
  text-align: center;
  margin-top: 20px;
}

.complete-wrap h1 {
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 12px;
}

.complete-wrap .subtitle {
  font-size: 17px;
  color: #8b949e;
  margin-bottom: 40px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 40px;
}

.stat-card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 24px 16px;
}

.stat-value {
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 13px;
  color: #8b949e;
}

.accuracy-great  { color: #3fb950; }
.accuracy-ok     { color: #d29922; }
.accuracy-low    { color: #f85149; }

.btn-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-primary {
  display: inline-block;
  background: #238636;
  color: #fff;
  text-decoration: none;
  padding: 10px 28px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.2s;
}
.btn-primary:hover { background: #2ea043; text-decoration: none; }

.btn-ghost {
  display: inline-block;
  background: transparent;
  color: #8b949e;
  border: 1px solid #30363d;
  text-decoration: none;
  padding: 10px 28px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  transition: border-color 0.2s, color 0.2s;
}
.btn-ghost:hover { border-color: #58a6ff; color: #58a6ff; text-decoration: none; }

@media (max-width: 600px) {
  .stat-grid { grid-template-columns: 1fr; }
}
