/* 박자길 — night road. Deliberately one dark look: the game is a lit road on a night sky. */
:root {
  color-scheme: dark;
  --ink: #14112b; --ink-2: #1e1a44; --glass: rgba(26, 22, 60, .82); --glass-2: rgba(255, 255, 255, .05);
  --line: rgba(170, 160, 230, .24); --line-2: rgba(170, 160, 230, .42);
  --text: #f4effd; --mute: #aba4d3; --dim: #7d76a8;
  --peach: #ff9b6a; --sky: #79d2ff; --rose: #ff6f8e; --gold: #ffd36e; --mint: #7dffb2;
  --f-display: "Black Han Sans", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --f-body: "IBM Plex Sans KR", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --f-num: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --r: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--ink); color: var(--text); font-family: var(--f-body); font-size: 15px; overflow: hidden; -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }
#app { position: fixed; inset: 0; overflow: hidden; user-select: none; -webkit-user-select: none; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--glass-2); color: var(--text); }
.icon-btn:hover { border-color: var(--line-2); }

/* ---------- HUD ---------- */
#hud { position: absolute; left: 0; right: 0; top: 0; display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; pointer-events: none;
  padding: calc(12px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px)); }
#hud .icon-btn { pointer-events: auto; width: 36px; height: 36px; background: rgba(20, 17, 43, .5); }
.hud-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
#hudLabel { font-size: 12px; color: var(--mute); letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#hudPct { font-family: var(--f-num); font-weight: 600; font-size: 20px; font-variant-numeric: tabular-nums; }
#bar { position: relative; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .1); margin-top: 6px; }
#barFill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 3px; background: linear-gradient(90deg, var(--sky), var(--peach)); }
#barBest { position: absolute; top: -4px; width: 3px; height: 14px; border-radius: 2px; background: var(--gold); display: none; }
#hudCombo { grid-column: 2; justify-self: end; font-family: var(--f-num); font-size: 13px; color: var(--gold); min-height: 18px; }

/* ---------- home ---------- */
.screen { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain;
  background: linear-gradient(90deg, rgba(20, 17, 43, .92) 0%, rgba(20, 17, 43, .72) 42%, rgba(20, 17, 43, .1) 75%); }
.home-inner { width: min(470px, 100%); min-height: 100%; display: flex; flex-direction: column; gap: 18px;
  padding: calc(18px + env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px)) calc(22px + env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px)); }
@media (min-width: 900px) { .home-inner { margin-left: 6vw; justify-content: center; } }
@media (max-width: 700px) { .screen { background: linear-gradient(180deg, rgba(20, 17, 43, .55) 0%, rgba(20, 17, 43, .88) 38%, rgba(20, 17, 43, .95) 100%); } }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wordmark { font-family: var(--f-display); font-size: 26px; letter-spacing: .02em; background: linear-gradient(100deg, var(--text) 40%, var(--peach)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.name-chip { display: inline-flex; align-items: center; gap: 7px; max-width: 150px; height: 40px; padding: 0 12px 0 5px; border-radius: 999px; border: 1px solid var(--line); background: var(--glass-2); font-size: 14px; font-weight: 700; }
.name-chip:hover { border-color: var(--line-2); }
.name-chip i { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; font-style: normal; font-size: 14px; color: var(--ink); background: linear-gradient(135deg, var(--peach), var(--gold)); }
.name-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.name-chip.unset { border-color: var(--peach); color: var(--peach); animation: nudge 2.4s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 155, 106, 0); } 50% { box-shadow: 0 0 0 5px rgba(255, 155, 106, .18); } }
.wordmark, .streak { white-space: nowrap; }
.next .st { color: var(--gold); }
@media (max-width: 440px) {
  .topbar { gap: 8px; }
  .top-actions { gap: 6px; }
  .top-actions .icon-btn { width: 36px; height: 36px; }
  .streak { display: none; }            /* shown under the title instead */
  .name-chip { max-width: 150px; height: 36px; }
  .name-chip i { width: 26px; height: 26px; font-size: 13px; }
}
@media (min-width: 441px) { .next .st { display: none; } }
.streak { font-family: var(--f-num); font-size: 14px; color: var(--gold); padding: 6px 10px; border-radius: 999px; border: 1px solid rgba(255, 211, 110, .35); }

.hero { display: grid; gap: 6px; padding-top: 4vh; }
.eyebrow { font-family: var(--f-num); font-size: 12px; letter-spacing: .18em; color: var(--peach); text-transform: uppercase; }
.hero h1 { margin: 0; font-family: var(--f-display); font-weight: 400; font-size: clamp(44px, 12vw, 68px); line-height: 1.02; letter-spacing: -.01em; text-wrap: balance; }
.song-meta { color: var(--mute); font-size: 14px; }
.next { font-family: var(--f-num); font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }

.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.level { display: grid; gap: 4px; justify-items: start; text-align: left; padding: 12px; border-radius: var(--r); border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(6px); }
.level b { font-weight: 700; font-size: 15px; }
.lv-best { font-family: var(--f-num); font-size: 12px; color: var(--mute); }
.lv-bar { display: block; width: 100%; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.lv-bar i { display: block; height: 100%; width: 0; background: var(--peach); }
.level.cleared .lv-bar i { background: var(--gold); }
.level[aria-checked="true"] { border-color: var(--peach); background: rgba(255, 155, 106, .14); }

.rank-card { display: grid; gap: 8px; padding: 12px 14px; border-radius: var(--r); background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(6px); }
.rank-head { display: flex; align-items: baseline; gap: 8px; }
.rank-head b { font-size: 15px; }
.rank-head span { font-size: 12px; color: var(--mute); }
.link-btn { margin-left: auto; padding: 0; border: 0; background: none; color: var(--sky); font-size: 13px; }
.rank-top { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.rank-top li { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 8px; align-items: center; font-size: 14px; }
.rank-top .medal { font-family: var(--f-num); font-weight: 600; color: var(--mute); }
.rank-top li:nth-child(1) .medal { color: var(--gold); } .rank-top li:nth-child(2) .medal { color: #d6dbe8; } .rank-top li:nth-child(3) .medal { color: var(--peach); }
.rank-top .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-top .sc { font-family: var(--f-num); font-size: 13px; }
.rank-top li.me .nm { color: var(--peach); font-weight: 700; }
.rank-top li.empty { grid-template-columns: 1fr; color: var(--mute); font-size: 13px; }
.rank-me { font-size: 12px; color: var(--mute); border-top: 1px solid rgba(170, 160, 230, .15); padding-top: 8px; }
.rank-me b { color: var(--text); }
.play { display: grid; gap: 2px; place-items: center; border: 0; border-radius: 18px; padding: 16px; color: var(--ink);
  background: linear-gradient(100deg, var(--peach), var(--gold)); box-shadow: 0 14px 34px -14px rgba(255, 155, 106, .7); transition: transform .12s; }
.play:hover { transform: translateY(-1px); }
.play:active { transform: translateY(1px); }
.play span { font-family: var(--f-display); font-size: 28px; letter-spacing: .04em; }
.play small { font-size: 12px; font-weight: 500; opacity: .75; }
.custom-road { display: grid; gap: 1px; place-items: center; margin-top: -8px; padding: 9px 14px; border-radius: 14px;
  border: 1px solid rgba(255, 155, 106, .55); background: var(--glass); color: var(--text); backdrop-filter: blur(6px); transition: transform .12s; }
.custom-road:hover { border-color: var(--peach); transform: translateY(-1px); }
.custom-road span { font-family: var(--f-display); font-size: 19px; letter-spacing: .03em; }
.custom-road small { font-size: 11px; color: var(--mute); }
.play[disabled] { filter: grayscale(.6); opacity: .7; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--glass-2); font-size: 14px; }
.chip:hover { border-color: var(--line-2); }
.foot { margin: auto 0 0; font-size: 12px; color: var(--dim); line-height: 1.55; }

.challenge { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 12px 14px; border-radius: var(--r); background: rgba(121, 210, 255, .12); border: 1px solid rgba(121, 210, 255, .4); }
.challenge b { display: block; font-size: 15px; }
.challenge span { font-size: 13px; color: var(--mute); }

/* ---------- result sheet ---------- */
.sheet { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); width: min(460px, calc(100% - 24px));
  display: grid; gap: 10px; padding: 18px; border-radius: 20px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px);
  animation: rise .28s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes rise { from { transform: translate(-50%, 24px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.r-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.r-pct { font-family: var(--f-display); font-size: 64px; line-height: .9; }
.r-pct small { font-size: 30px; }
.r-side { text-align: right; font-size: 13px; color: var(--mute); display: grid; gap: 2px; }
.r-score { font-size: 14px; color: var(--mute); display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.r-score b { font-family: var(--f-num); font-size: 22px; color: var(--text); font-variant-numeric: tabular-nums; }
.r-score em { font-style: normal; font-weight: 700; color: var(--mint); }
.r-score span { font-size: 12px; }
#hudScore { font-family: var(--f-num); font-size: 13px; color: var(--mute); margin-right: 10px; font-variant-numeric: tabular-nums; }
.r-msg { font-family: var(--f-display); font-size: 24px; color: var(--gold); }
.r-meta { font-family: var(--f-num); font-size: 12px; color: var(--mute); }
.r-rivals { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.r-rivals li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 10px; border-radius: 10px; background: rgba(121, 210, 255, .08); }
.r-rivals .win { color: var(--mint); } .r-rivals .lose { color: var(--rose); }
.r-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.r-hint { font-size: 12px; color: var(--dim); }

.btn { padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--glass-2); font-weight: 500; font-size: 14px; }
.btn:hover { border-color: var(--line-2); }
.btn.primary { border: 0; color: var(--ink); background: linear-gradient(100deg, var(--peach), var(--gold)); font-weight: 700; }
.btn.ghost { background: none; }
.btn.kakao { display: inline-flex; align-items: center; gap: 6px; border: 0; background: #fee500; color: #191919; font-weight: 700; }
.btn.kakao:hover { background: #ffeb3b; }
.btn.share { display: inline-flex; align-items: center; gap: 6px; }
.btn.dice { width: 100%; padding: 14px; font-size: 16px; }
.seg-lv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.btn.cont { width: 100%; padding: 12px 16px; border: 0; font-weight: 700; font-size: 15px; color: var(--ink); background: linear-gradient(100deg, var(--mint), var(--sky)); }
.ad-slot { display: grid; place-items: center; min-height: 50px; max-width: 100%; overflow: hidden; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------- modal ---------- */
.modal { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(10, 8, 26, .62); backdrop-filter: blur(3px);
  padding: calc(16px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px)); }
.modal-card { width: min(520px, 100%); max-height: 100%; display: flex; flex-direction: column; border-radius: 20px; background: #1b173e; border: 1px solid var(--line); overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 10px 20px; }
.modal-head h2 { margin: 0; font-family: var(--f-display); font-weight: 400; font-size: 24px; }
.modal-body { overflow-y: auto; overflow-x: hidden; padding: 4px 20px 20px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; user-select: text; -webkit-user-select: text; }
.modal-body p { margin: 0; line-height: 1.6; color: var(--mute); font-size: 14px; }
.modal-body h3 { margin: 6px 0 0; font-size: 13px; letter-spacing: .06em; color: var(--mute); font-weight: 500; }
.list { display: grid; gap: 8px; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 12px; background: var(--glass-2); border: 1px solid var(--line); }
.row .t { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { font-size: 12px; color: var(--mute); }
.row .lvs { display: flex; gap: 6px; }
.row .lvs .btn { min-width: 52px; font-family: var(--f-num); font-size: 12px; }
.row .lvs .btn.cleared { border-color: rgba(255, 211, 110, .6); color: var(--gold); }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--mute); }
.field input[type=text] { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, .25); font-size: 15px; color: var(--text); }
.field input[type=range] { width: 100%; accent-color: var(--peach); }
.toggle { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 14px; }
.toggle input { width: 20px; height: 20px; accent-color: var(--peach); }
.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline input[type=text] { flex: 1; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { padding: 12px 8px; border-radius: 12px; background: var(--glass-2); border: 1px solid var(--line); text-align: center; }
.stat b { display: block; font-family: var(--f-num); font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--mute); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal div { aspect-ratio: 1; max-width: 100%; border-radius: 8px; background: rgba(255, 255, 255, .05); display: grid; place-items: center; font-family: var(--f-num); font-size: 10px; color: var(--dim); }
.cal .p1 { background: rgba(255, 155, 106, .25); color: var(--text); } .cal .p2 { background: rgba(255, 155, 106, .5); color: var(--text); }
.cal .c { background: var(--gold); color: var(--ink); font-weight: 600; }
.cal .today { outline: 2px solid var(--sky); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 12px; color: var(--mute); }
.legend i { display: inline-block; width: 20px; height: 6px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.howto { display: grid; gap: 10px; counter-reset: s; padding: 0; margin: 0; list-style: none; }
.howto li { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; font-size: 14px; line-height: 1.55; }
.howto li::before { counter-increment: s; content: counter(s); display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: rgba(255, 155, 106, .2); color: var(--peach); font-family: var(--f-num); font-size: 13px; }
.card-preview { width: 100%; max-width: 100%; border-radius: 14px; border: 1px solid var(--line); display: block; }
.board-list { counter-reset: r; list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.board-list li { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 10px; background: var(--glass-2); font-size: 14px; }
.board-list li::before { counter-increment: r; content: counter(r); font-family: var(--f-num); color: var(--mute); }
.board-list li.empty { grid-template-columns: 1fr; color: var(--mute); }
.board-list li.empty::before { content: none; }
.board-list li.me { background: rgba(255, 155, 106, .16); }
.board-list .v { font-family: var(--f-num); }
.calib-big { font-family: var(--f-num); font-size: 34px; text-align: center; padding: 8px; }
.calib-pad { display: grid; place-items: center; height: 120px; border-radius: 16px; border: 1px dashed var(--line-2); color: var(--mute); font-size: 14px; touch-action: manipulation; }
.calib-pad.on { border-color: var(--peach); color: var(--text); }

.loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; background: rgba(10, 8, 26, .55); color: var(--mute); font-size: 14px; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .15); border-top-color: var(--peach); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: absolute; left: 50%; top: calc(18px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 12px; background: #2a2560; border: 1px solid var(--line-2); font-size: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* Japanese: Dela Gothic One for display, Noto Sans JP for text */
:root:lang(ja) { --f-display: "Dela Gothic One", "Black Han Sans", "Noto Sans JP", sans-serif; --f-body: "Noto Sans JP", "IBM Plex Sans KR", system-ui, sans-serif; }
:root:lang(en) .wordmark { letter-spacing: .06em; }
.btn.line { display: inline-flex; align-items: center; gap: 6px; border: 0; background: #06c755; color: #fff; font-weight: 700; }
.btn.line:hover { background: #05b34c; }
.seg-lang { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
@media (max-width: 440px) {
  .wordmark { font-size: 21px; }
  :root:lang(en) .wordmark, :root:lang(ja) .wordmark { font-size: 17px; letter-spacing: .02em; }
  .name-chip { max-width: 122px; }
}
.hud-main { min-width: 0; }
.hud-row > span:last-child { flex: none; }

/* compact home: everything on one phone screen */
.home-inner { gap: 12px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
.hero { padding-top: 0; gap: 4px; }
.hero h1 { font-size: clamp(32px, 9.5vw, 58px); }
.level { padding: 9px 10px; }
.rank-card { padding: 9px 12px; gap: 5px; }
.rank-top { gap: 2px; }
.rank-me { padding-top: 6px; }
.play { padding: 12px; }
.play span { font-size: 25px; }
.custom-road { margin-top: -4px; padding: 7px 14px; }
.custom-road span { font-size: 17px; }
.foot { margin-top: 0; }
@media (max-height: 740px) { .foot { display: none; } }
.share-score { display: flex; align-items: baseline; gap: 4px; flex-wrap: wrap; font-size: 15px; color: var(--mute); }
.share-score b { font-family: var(--f-num); font-size: 26px; color: var(--gold); font-variant-numeric: tabular-nums; }
.share-score span { margin-left: auto; font-family: var(--f-num); font-size: 13px; }
.legal-links { margin: 0; font-size: 11px; color: var(--dim); }
.legal-links a { color: var(--dim); text-decoration: underline; }
