:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  --bg: #13201b;
  --panel: #15231e;
  --surface: #1c2c25;
  --surface-hover: #273b32;
  --text: #f4f6e9;
  --muted: #b9c8b8;
  --line: #cfe5ca29;
  --accent: #d9ef9d;
  --accent-hover: #e5f8b9;
  --ink: #22331f;
  --error: #ffb8a7;
  --radius: 1.25rem;
  --gutter: clamp(1.15rem, 5.25vw, 6rem);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-width: 18rem; min-height: 100%; }
body { color: var(--text); background: var(--bg); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { line-height: 1.13; }
p { line-height: 1.55; }
input, select {
  width: 100%; min-height: 3rem; border: 1px solid var(--line); border-radius: .65rem;
  background-color: #101b16; color: var(--text); padding: .65rem .85rem;
}
input::placeholder { color: #869888; }
select {
  appearance: none; padding-right: 2.5rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 1.1rem) center, calc(100% - .8rem) center;
  background-size: .31rem .31rem;
  background-repeat: no-repeat;
}
label, legend { font-size: .9rem; font-weight: 650; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; margin-bottom: .55rem; }
label.field { display: grid; gap: .42rem; }
.muted { color: var(--muted); }
.small { font-size: .83rem; }
.error { min-height: 0; color: var(--error); font-size: .9rem; line-height: 1.5; }
.error:empty { display: none; }
.mono { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.stack { display: grid; gap: 1rem; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: .85rem; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }

#landscape, #shade { position: fixed; inset: 0; width: 100%; height: 100%; }
#landscape { display: block; background-color: #587575; }
#shade {
  pointer-events: none;
  background: linear-gradient(90deg, #0c1715e8 0%, #101e17dc 18%, #10201871 57%, #101e1742 100%),
    linear-gradient(0deg, #101d16dc 0%, transparent 62%);
}
[data-screen="entry"] #shade {
  background: linear-gradient(90deg, #101d17db, #10201966 56%, #17251b50 100%),
    linear-gradient(0deg, #0f1a15a8, transparent 54%);
}
[data-screen="drive"] #shade {
  background: linear-gradient(180deg, #14251cc4, transparent 18%, transparent 77%, #13211ab0);
}

.topbar {
  position: absolute; z-index: 3; inset: 0 0 auto; padding: 1.35rem var(--gutter);
  display: flex; align-items: center; justify-content: space-between; gap: .7rem; pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: .68rem; letter-spacing: -.025em; font-weight: 740; white-space: nowrap; }
.road-sign {
  flex: none; display: grid; place-items: center; width: 1.85rem; height: 1.85rem;
  border-radius: .43rem; background: var(--accent); color: var(--ink); transform: rotate(-12deg);
}
.road-sign::before {
  content: ''; width: .62rem; height: 1.05rem; transform: skew(-12deg);
  border-inline: 2px solid currentColor; background-image: linear-gradient(currentColor 55%, transparent 55%);
  background-size: 1px .31rem; background-repeat: repeat-y; background-position: center;
}
.lang-switch, .segmented {
  display: inline-flex; border: 1px solid var(--line); border-radius: .7rem; padding: .2rem; gap: .18rem; background: #14231ecf;
}
.lang-switch button, .segmented button {
  border: 0; border-radius: .5rem; background: transparent; padding: .45rem .65rem; color: var(--muted); font-weight: 660; font-size: .9rem;
}
.lang-switch button[aria-pressed="true"], .segmented button[aria-pressed="true"] { background: var(--accent); color: var(--ink); }
.top-actions { display: flex; align-items: center; gap: .55rem; }
.balance {
  display: inline-flex; align-items: center; gap: .48rem; min-width: 3.6rem; min-height: 2.5rem; justify-content: center;
  border: 1px solid #e5ed9d42; padding: .35rem .7rem; border-radius: .7rem; font-weight: 720; color: #f3f6ce; background: #17261dec;
}
.coin { display: inline-block; width: .83rem; height: .83rem; border: 2px solid #ebd38c; border-radius: 50%; background: #e5bc59; box-shadow: inset 0 0 0 2px #a76c2370; flex: none; }
.chat-count { padding: .05rem .27rem; border-radius: .25rem; color: var(--ink); background: var(--accent); font-size: .75rem; }

#app { position: relative; z-index: 1; min-height: 100dvh; }
#app:focus { outline: none; }
.screen {
  min-height: 100dvh;
  padding: clamp(5.7rem, 12vh, 8.5rem) var(--gutter) clamp(2rem, 6vh, 5rem);
}
.entry {
  width: min(100%, 112rem); margin-inline: auto; align-items: center; display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(20rem, 29rem); gap: clamp(2rem, 6vw, 9rem);
}
.title-alt { color: #e0efc5; font-weight: 650; font-size: clamp(1rem, 1.6vw, 1.3rem); margin-bottom: .7rem; }
.hero h1 { font-size: clamp(4.65rem, 11.5vw, 11rem); line-height: .84; letter-spacing: -.065em; font-weight: 830; }
.hero h1 span:last-child { display: block; color: var(--accent); }
html[lang="ko"] .hero h1 { font-size: clamp(4rem, 9.9vw, 9rem); letter-spacing: -.095em; line-height: .96; }
.hero-copy { margin-top: clamp(1.1rem, 4.4vh, 2.2rem); max-width: 24rem; color: #e4eddb; font-size: clamp(1.02rem, 1.65vw, 1.25rem); }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: clamp(1.1rem, 2.4vw, 2rem);
}
.entry-card { background: #14231eee; box-shadow: 0 1.2rem 4.5rem #07100b56; }
.entry-card h2 { font-size: clamp(1.35rem, 2.15vw, 1.8rem); letter-spacing: -.035em; margin-bottom: 1.25rem; }
.chapter-radio { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; }
.chapter-option { position: relative; cursor: pointer; }
.chapter-option input { position: absolute; width: 1px; height: 1px; min-height: 0; opacity: 0; }
.chapter-option span {
  display: flex; align-items: center; justify-content: center; min-height: 3.31rem; height: 100%;
  padding: .65rem .48rem; text-align: center; border: 1px solid var(--line); border-radius: .63rem; background: var(--surface); font-size: .86rem;
}
.chapter-option input:checked + span { border-color: var(--accent); background: #d9ef9d1b; color: var(--accent); }
.chapter-option input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 3px; }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 2.8rem; border-radius: .65rem; padding: .6rem 1rem;
  border: 1px solid var(--line); background: var(--surface); font-size: .94rem; font-weight: 670; white-space: nowrap;
  transition: background-color .15s, border-color .15s;
}
.button:hover:not(:disabled) { background: var(--surface-hover); border-color: #cfe5ca50; }
.button.primary { background: var(--accent); color: var(--ink); border-color: var(--accent); }
.button.primary:hover:not(:disabled) { background: var(--accent-hover); }
.button.subtle { background: #18271fed; }
.button.ghost { background: transparent; }
.button.compact { min-height: 2.5rem; font-size: .86rem; padding: .4rem .66rem; }
.button.full { width: 100%; }
.button.danger { color: var(--error); }
.page-title { font-size: clamp(2rem, 4.5vw, 4rem); letter-spacing: -.065em; margin-top: .25rem; }
.section-title { font-size: clamp(1.3rem, 3vw, 1.85rem); letter-spacing: -.035em; }
.eyebrow { color: var(--accent); font-weight: 730; font-size: .87rem; }

.center-layout { display: grid; place-content: center; justify-items: stretch; }
.question-card { width: min(42rem, calc(100vw - 2 * var(--gutter))); max-width: 100%; display: grid; gap: 1.2rem; }
.question-text { font-size: clamp(1.12rem, 2.2vw, 1.42rem); font-weight: 600; line-height: 1.52; overflow-wrap: anywhere; }
.quiz-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: .7rem; }
.quiz-form .error { grid-column: 1/-1; }
.progress { display: flex; gap: .3rem; width: 100%; height: .28rem; }
.progress span { flex: 1; background: #cbe1c12e; border-radius: .24rem; }
.progress span.done { background: var(--accent); }
.progress span.active { background: #d9ef9d79; }
.result { border-left: .22rem solid var(--accent); padding-left: 1rem; }
.result.wrong { border-color: var(--error); }
.result h2 { font-size: 1.6rem; }

.menu-layout { display: grid; align-content: center; gap: 1.2rem; }
.menu-layout .page-title { font-size: clamp(2.35rem, 6vw, 5.8rem); }
.menu-grid { width: min(32rem, 100%); display: grid; gap: .48rem; grid-template-columns: 1fr 1fr; }
.menu-grid .button { justify-content: flex-start; min-height: 3.4rem; background: #1b2e25ef; padding-inline: 1.1rem; }
.menu-grid .primary { grid-column: 1/-1; min-height: 4.3rem; background: var(--accent); color: var(--ink); font-size: 1.23rem; }
.menu-footer { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }

.inner { max-width: 68rem; margin-inline: auto; display: grid; gap: 1.2rem; }
.inner-heading { display: grid; justify-items: start; gap: .5rem; margin-bottom: .3rem; }
.inner-heading h1 { overflow-wrap: anywhere; }
.subnav {
  display: flex; gap: .4rem; flex-wrap: wrap; align-items: center;
  border-bottom: 1px solid var(--line); padding-bottom: .55rem;
}
.subnav .button[aria-pressed="true"] { background: var(--accent); color: var(--ink); border-color: var(--accent); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); gap: .8rem; }
.tile { display: flex; flex-direction: column; align-items: flex-start; gap: .85rem; }
.tile .actions { margin-top: auto; }
.tile h2 { font-size: 1.23rem; letter-spacing: -.02em; }
.stat-big { font-size: 2.4rem; line-height: 1; font-weight: 760; letter-spacing: -.07em; }
.badge { color: var(--accent); font-size: .81rem; font-weight: 680; }
.not-earned .badge { color: var(--muted); }
.scenes { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); }
.scene-tile {
  --scene-tint: #627d54;
  background: linear-gradient(155deg, color-mix(in srgb, var(--scene-tint), var(--panel) 50%), var(--panel) 68%);
  border-top: 3px solid var(--scene-tint);
}
.scene-tile[data-scene="dirt"] { --scene-tint: #bf9c63; }
.scene-tile[data-scene="inland"] { --scene-tint: #76a7a9; }
.scene-tile[data-scene="offworld"] { --scene-tint: #b296bf; }
.scene-tile[data-scene="driftmas"] { --scene-tint: #a6c0ce; }
.setting-rows { display: grid; gap: 0; }
.setting-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(9rem, 1fr); align-items: center; gap: 1rem; padding: .85rem 0; }
.setting-row + .setting-row { border-top: 1px solid var(--line); }
.setting-row .actions { justify-content: flex-end; }
.setting-row label { font-size: 1rem; }
.swatches { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .45rem; }
.swatch {
  width: 2rem; height: 2rem; border-radius: .45rem; border: 1px solid #fff5;
  background: var(--paint); padding: 0;
}
.swatch[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 3px; }
.data-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr)); gap: .6rem; }
.data-cell { display: grid; gap: .36rem; border: 1px solid var(--line); background: var(--surface); border-radius: .62rem; padding: .7rem .85rem; }
.data-cell strong { font-size: 1.33rem; letter-spacing: -.04em; }
.transfer-form { display: grid; grid-template-columns: minmax(9rem, 1fr) minmax(7rem, .45fr) auto; gap: .65rem; align-items: end; }
.transfer-list { list-style: none; padding: 0; margin: 0; }
.transfer-list li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }

dialog {
  color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: clamp(1rem, 2.7vw, 2rem); width: min(42rem, calc(100% - 2 * var(--gutter))); max-height: calc(100dvh - 2rem);
  box-shadow: 0 1.2rem 4rem #101a16a8; overflow: auto;
}
dialog::backdrop { background: #0d1b16a8; }
dialog .question-card { width: auto; padding: 0; border: 0; background: transparent; }
.tutorial-list { display: grid; grid-template-columns: max-content 1fr; gap: .55rem 1rem; margin: 0; }
.tutorial-list dt { font-weight: 700; }
.tutorial-list dd { margin: 0; color: var(--muted); }
.toast {
  z-index: 9; position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%);
  max-width: calc(100% - 2rem); border: 1px solid var(--line); border-radius: .72rem; padding: .67rem .95rem;
  color: var(--text); background: #17251ff5; box-shadow: 0 .4rem 1.4rem #0c14136c; text-align: center;
}

.drive-layout { position: fixed; inset: 0; min-height: 100dvh; pointer-events: none; }
.drive-layout .button { pointer-events: auto; }
.route-hud {
  position: absolute; left: var(--gutter); bottom: 1.55rem; display: grid; gap: .28rem;
  min-width: min(14rem, 40vw); color: #faf9e6; text-shadow: 0 1px 5px #112018;
}
.route-hud strong, .speed-hud strong { font-size: clamp(1.9rem, 4.5vw, 4.1rem); font-weight: 740; letter-spacing: -.06em; line-height: .98; }
.route-hud .small { color: #e0ebd9; }
.drive-meter { margin-top: .36rem; height: .22rem; background: #f2f9dc4d; border-radius: .2rem; overflow: hidden; }
.drive-meter span { display: block; height: 100%; width: 0; background: var(--accent); }
.speed-hud {
  position: absolute; bottom: 1.55rem; right: var(--gutter); display: grid; gap: .3rem; justify-items: end;
  color: #fbfbe9; text-shadow: 0 1px 5px #112018;
}
.drive-help { position: absolute; inset: auto 0 1.4rem; text-align: center; color: #f3f6e5; text-shadow: 0 1px 5px #112018; }
#road-warning { color: #fee4a6; font-weight: 700; }
.touch-drive { display: none; }

.chat-drawer {
  position: fixed; z-index: 5; right: var(--gutter); top: 4.95rem; bottom: min(1.25rem, 3vh); width: min(26rem, calc(100vw - 2 * var(--gutter)));
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; border: 1px solid var(--line); border-radius: var(--radius);
  background: #14231efa; box-shadow: 0 .7rem 2rem #0a1611a8; overflow: hidden;
}
.chat-header { padding: 1rem; border-bottom: 1px solid var(--line); }
.chat-header h2 { font-size: 1.22rem; letter-spacing: -.03em; }
.chat-messages { overflow: auto; overscroll-behavior: contain; padding: 1rem; display: flex; flex-direction: column; gap: .6rem; }
.message { padding: .55rem .65rem; border-radius: .62rem; background: var(--surface); overflow-wrap: anywhere; }
.message p { line-height: 1.35; margin-top: .23rem; }
.message .quoted { color: var(--muted); font-size: .81rem; border-left: 2px solid var(--line); padding-left: .45rem; }
.message time { font-size: .76rem; margin-left: .28rem; }
.message .ping { font-weight: 690; color: var(--accent); }
.message .ping.you { color: var(--ink); background: var(--accent); border-radius: .2rem; padding-inline: .1rem; }
.message .chat-reply { min-height: 1.6rem; padding: .17rem .38rem; }
.chat-form { display: grid; gap: .55rem; padding: .8rem; border-top: 1px solid var(--line); }
.chat-compose { display: grid; grid-template-columns: 1fr auto; gap: .45rem; }
.chat-controls { display: flex; gap: .5rem; align-items: center; justify-content: space-between; }
.chat-form .button.compact { min-height: 2rem; }
.chat-reply-draft { border-left: .18rem solid var(--accent); padding-left: .5rem; font-size: .86rem; }
.chat-mentions { display: flex; flex-wrap: wrap; gap: .35rem; max-height: 5rem; overflow: auto; }
.noscript { position: relative; padding: 2rem; color: var(--text); z-index: 12; }

@media (max-width: 62rem) {
  .entry { grid-template-columns: minmax(0, 1fr) minmax(19rem, 24rem); gap: 1.6rem; }
  .drive-help { bottom: .52rem; }
}
@media (max-width: 43rem) {
  .entry { grid-template-columns: 1fr; align-content: center; }
  .hero h1 { font-size: clamp(3.9rem, 13vw, 6rem); }
  .hero h1 span:last-child { display: inline; }
  html[lang="ko"] .hero h1 { font-size: clamp(3.1rem, 11vw, 5.5rem); }
  .hero h1 span + span::before { content: ' '; }
  .hero-copy { margin-top: .75rem; }
  .title-alt { margin-bottom: .35rem; }
  .entry-card h2 { margin-bottom: .9rem; }
  .transfer-form { grid-template-columns: 1fr 1fr; }
  .transfer-form button { grid-column: 1/-1; }
  .tutorial-list { grid-template-columns: 1fr; gap: .28rem; }
  .tutorial-list dd { margin-bottom: .35rem; }
  .drive-help { display: none; }
  [data-screen="drive"] .brand span:last-child { display: none; }
}
@media (max-width: 27rem) {
  .quiz-form { grid-template-columns: 1fr; }
  .setting-row { grid-template-columns: 1fr; }
  .setting-row .actions, .swatches { justify-content: flex-start; }
  .menu-grid { grid-template-columns: 1fr; }
  .topbar { padding-top: .95rem; }
}
@media (pointer: coarse) {
  .drive-help { display: none; }
  .touch-drive { display: flex; justify-content: space-between; position: absolute; inset: auto var(--gutter) 1rem; gap: 1rem; }
  .touch-drive > div { display: flex; gap: .35rem; }
  .touch-drive .button { min-width: 2.9rem; touch-action: none; user-select: none; }
  .route-hud, .speed-hud { bottom: 4.8rem; }
}
@media (prefers-reduced-motion: reduce) { .button { transition: none; } }
