:root {
  color-scheme: dark;
  --void: #06030e;
  --ink: #0c071a;
  --cyan: #38f6ff;
  --pink: #ff3fce;
  --lime: #a5ff42;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: block;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 36%, rgba(77, 17, 113, 0.5), transparent 48rem),
    linear-gradient(145deg, #010105 0%, var(--void) 48%, #090311 100%);
  font-family: "Pretendard", "Noto Sans KR", ui-sans-serif, system-ui, sans-serif;
}

.game-shell {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding:
    max(4px, env(safe-area-inset-top))
    max(4px, env(safe-area-inset-right))
    max(4px, env(safe-area-inset-bottom))
    max(4px, env(safe-area-inset-left));
  display: block;
}

body.nomonori-shell-ready .game-shell {
  height: calc(100vh - 64px);
  height: calc(100dvh - 64px);
}

#game {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: #06030e;
  box-shadow:
    0 0 0 1px rgba(255, 63, 206, 0.08),
    0 0 58px rgba(56, 246, 255, 0.14),
    0 32px 90px rgba(0, 0, 0, 0.68);
  touch-action: none;
  display: grid;
  place-items: center;
}

#game canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
}

.screen-reader-guide {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.course-select {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  align-items: center;
  padding: 24px;
  overflow: auto;
  background: radial-gradient(ellipse at 50% 0, #284158c9, transparent 70%), rgba(6, 15, 30, 0.95);
  color: #eff7fc;
  letter-spacing: 0;
}
.course-select[hidden] { display: none; }
.course-select-inner { width: min(100%, 940px); margin: auto; }
.course-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.course-header h1 { font-size: 32px; margin: 0 0 10px; }
.course-header h2 { font-size: 16px; font-weight: 500; color: #adcadc; margin: 0; }
.course-header img { object-fit: contain; flex-shrink: 0; }
.course-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.course-option {
  position: relative; min-width: 0; border: 2px solid #3b5269; border-radius: 18px;
  padding: 12px; background: linear-gradient(155deg, #233b50, #112238); color: inherit; font: inherit;
  box-shadow: 0 7px 0 #061321, 0 12px 26px #0004;
  text-align: left; cursor: pointer; transition: border-color 150ms, background 150ms, transform 150ms;
}
.course-option:hover { background: linear-gradient(155deg, #304b61, #183047); transform: translateY(-2px); }
.course-option[aria-pressed="true"] { border-color: var(--course-color); background: linear-gradient(155deg, #355469, #1b3446); box-shadow: 0 7px 0 #061321, 0 0 0 3px color-mix(in srgb, var(--course-color) 16%, transparent), 0 16px 30px #0005; }
.course-option:focus-visible, #race-start:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }
.course-option canvas { display: block; width: 100%; height: 188px; object-fit: contain; margin-bottom: 14px; border-radius: 12px !important; box-shadow: none !important; }
.course-copy { display: block; padding: 0 6px 5px; }
.course-option strong { display: block; font-size: 19px; margin: 0 0 8px; }
.course-option small { display: block; color: #abbec1; font-size: 12px; line-height: 1.5; }
.course-option .course-level { display: inline-block; color: var(--course-color); font-size: 11px; font-weight: 700; margin-bottom: 10px; padding: 3px 9px; border-radius: 20px; background: #081a2c; }
.course-option .course-distance { color: #d4e3eb; font-size: 11px; margin-top: 10px; }
.course-option .course-selected { position: absolute; top: 9px; right: 9px; color: #102233; background: var(--course-color); padding: 4px 8px; border-radius: 7px; font-size: 11px; font-weight: 800; }
.course-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 24px; }
.course-footer p { color: #b8cdce; font-size: 14px; margin: 0; }
#race-start { min-width: 180px; min-height: 48px; padding: 12px 32px; border: 0; border-radius: 12px; background: var(--selected-course-color, #43e4df); box-shadow: 0 4px 0 #07131f; color: #071618; font-family: inherit; font-weight: 800; font-size: 16px; cursor: pointer; }
#race-start:disabled { opacity: 0.4; cursor: wait; }
@media (max-width: 600px) {
  .course-select { padding: 20px 16px; }
  .course-header { margin-bottom: 18px; }
  .course-header h1 { font-size: 24px; }
  .course-header img { width: 64px; height: 64px; }
  .course-options { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .course-option { display: grid; grid-template-columns: 108px minmax(0, 1fr); align-items: center; gap: 10px; padding: 10px; min-height: 136px; }
  .course-option canvas { height: 100px; margin: 0; }
  .course-copy { padding: 0; }
  .course-option strong { font-size: 17px; margin-bottom: 4px; }
  .course-option .course-level { margin-bottom: 5px; padding: 2px 7px; }
  .course-option .course-selected { top: 5px; right: 7px; font-size: 9px; padding: 3px 6px; }
  .course-option .course-distance { margin-top: 5px; font-size: 10px; }
  .course-footer { flex-direction: column; gap: 14px; margin-top: 20px; }
  #race-start { width: 100%; }
}
@media (max-height: 480px) and (min-width: 601px) {
  .course-select { padding: 10px 24px; }
  .course-header { margin-bottom: 8px; }
  .course-header h1 { font-size: 22px; margin-bottom: 3px; }
  .course-header h2 { font-size: 13px; }
  .course-header img { width: 40px; height: 40px; }
  .course-option canvas { height: 64px; margin-bottom: 6px; }
  .course-option { padding: 8px; }
  .course-copy { padding-bottom: 0; }
  .course-option strong { font-size: 16px; margin-bottom: 3px; }
  .course-option .course-level { margin-bottom: 2px; font-size: 10px; padding: 1px 6px; }
  .course-option .course-distance { margin-top: 3px; font-size: 10px; }
  .course-footer { margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .course-option { transition: none; }
  #game {
    box-shadow: none;
  }
}

@media (max-width: 700px) {
  body.nomonori-shell-ready .game-shell {
    height: calc(100vh - 58px);
    height: calc(100dvh - 58px);
  }
}

/* 오프라인 경기 로비와 결과 */
.course-select-inner { width: min(100%, 1020px); }
.course-header { margin-bottom: 16px; }
.course-header img { width: 76px; height: 76px; }
.course-header h1 { font-size: 28px; }
.course-option[hidden], .race-overlay[hidden] { display: none; }
.race-setup { margin-bottom: 18px; }
.setup-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.setup-fields label { display: grid; gap: 7px; color: #adc4d7; font-size: 12px; }
.setup-fields select { width: 100%; border: 1px solid #52758a; border-radius: 10px; background: #102c40; color: #effaff; font: inherit; font-size: 14px; padding: 11px 12px; min-height: 44px; }
.setup-description { margin: 11px 0 9px; color: #d9eff2; font-size: 13px; }
.garage-preview { display: flex; align-items: center; gap: 12px; color: #a1c0cc; font-size: 12px; }
.garage-kart { font-size: 32px; line-height: 30px; text-shadow: 0 0 18px currentColor; transform: skew(-14deg); }
#career-progress { margin-left: auto; color: #c4e4c8; white-space: nowrap; }
.setup-actions { display: flex; gap: 8px; margin: 14px 0; }
.race-setup button, .race-modal button, .settings-dialog button { min-height: 44px; border: 1px solid #4b6c82; border-radius: 10px; background: #153247; color: #dffaff; padding: 10px 16px; font: inherit; font-size: 13px; cursor: pointer; }
.race-setup button:hover, .race-modal button:hover, .settings-dialog button:hover { background: #28546a; }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid #d5ffea; outline-offset: 3px; }
.region-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 4px; gap: 4px; background: #051a29; border-radius: 13px; }
.region-tabs button { border: 0; background: transparent; padding: 9px 4px; min-height: 40px; color: #91acbf; }
.region-tabs button[aria-pressed="true"] { background: #356175; color: #fff; box-shadow: inset 0 -2px #9cebe2; }
.course-option canvas { height: 150px; margin-bottom: 8px; }
.course-option .course-record { color: #cdecc0; margin-top: 8px; }
.course-footer { position: sticky; bottom: -24px; background: #0b2032f5; padding: 14px 0; margin-top: 12px; z-index: 2; }
.race-overlay { position: absolute; inset: 0; z-index: 20; padding: 24px; display: grid; place-items: center; overflow: auto; background: #030e20dd; backdrop-filter: blur(10px); color: #ecfaff; }
.race-modal { width: min(100%, 640px); margin: auto; padding: 26px; background: linear-gradient(140deg, #203e53, #0e253b); border: 1px solid #618b9c; border-radius: 22px; box-shadow: 0 24px 70px #0008; }
.race-modal h2 { margin: 5px 0 12px; font-size: 26px; }
.eyebrow { margin: 0 0 6px; color: #92d8dc; font-size: 12px; }
.finish-time { color: #b6ffdd; font-size: 46px; font-weight: 800; letter-spacing: -1px; font-variant-numeric: tabular-nums; }
.record-change, .result-hint, .cup-standing { color: #c0d7e1; font-size: 13px; line-height: 1.6; margin: 8px 0; }
.split-results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0; }
.split-results div { display: grid; gap: 5px; border-radius: 9px; background: #092136; padding: 10px; font-size: 13px; }
.split-results span { color: #87aebf; font-size: 11px; }
.result-rivals { margin: 16px 0; border-top: 1px solid #345669; }
.rival-row { display: grid; grid-template-columns: 24px 1fr auto; gap: 8px; padding: 7px 8px; font-size: 12px; color: #9fc0cf; }
.rival-row.is-player { color: #c9ffe1; background: #194d52; border-radius: 6px; }
.rival-row strong { font-weight: 600; }
.result-actions { display: flex; gap: 8px; margin-top: 18px; }
.race-modal .primary { background: #a4edd7; border-color: #a4edd7; color: #082a2e; font-weight: 800; flex: 1; }
.race-modal .primary:hover { background: #d1ffed; }
.save-note { font-size: 11px; color: #8caebd; line-height: 1.6; margin: 12px 0 0; }
.pause-modal { max-width: 360px; display: grid; gap: 12px; }
.settings-dialog { width: min(calc(100% - 24px), 450px); max-height: calc(100dvh - 32px); overflow: auto; border: 1px solid #648c9f; border-radius: 20px; padding: 24px; background: #143047; color: #e6f7ff; }
.settings-dialog::backdrop { background: #000a; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 12px; }
.dialog-heading h2 { margin: 0; font-size: 22px; }
.settings-dialog label { display: grid; gap: 8px; font-size: 13px; margin: 18px 0; }
.settings-dialog input[type="range"] { width: 100%; min-height: 28px; accent-color: #a4edd7; }
.settings-dialog label.check { display: flex; align-items: center; gap: 10px; }
.settings-dialog input[type="checkbox"] { width: 20px; height: 20px; accent-color: #a4edd7; }
.settings-guide, #storage-warning { color: #a7c9d8; font-size: 12px; line-height: 1.8; }
@media (max-width: 600px) {
  .course-header h1 { font-size: 23px; }
  .course-header img { width: 54px; height: 54px; }
  .setup-fields { gap: 7px; }
  .setup-fields label { font-size: 10px; }
  .setup-fields select { font-size: 12px; padding: 8px 5px; }
  .garage-preview { gap: 8px; flex-wrap: wrap; }
  #career-progress { width: 100%; margin-left: 0; font-size: 11px; }
  .setup-actions { margin: 12px 0; }
  .setup-actions button { padding: 9px 12px; font-size: 12px; }
  .region-tabs button { font-size: 11px; }
  .course-option canvas { height: 100px; margin: 0; }
  .course-footer { bottom: -20px; gap: 10px; }
  .course-option .course-record { font-size: 10px; margin-top: 4px; }
  .race-overlay { padding: 12px; }
  .race-modal { padding: 20px; }
  .race-modal h2 { font-size: 23px; }
  .finish-time { font-size: 39px; }
}
@media (max-height: 480px) and (min-width: 601px) {
  .course-header { margin-bottom: 8px; }
  .course-header img { width: 40px; height: 40px; }
  .course-option canvas { height: 90px; }
  .garage-preview { display: none; }
  .race-modal { padding: 20px; }
  .course-footer { bottom: -10px; }
}
