/* ================= KETRIS ================= */
:root {
  --bg: #06040f;
  --bg2: #120a24;
  --accent: #ff2bd6;
  --accent2: #22e6ff;
  --grid: #1e1540;
  --ink: #f3ecff;
  --muted: #a394c8;
  --panel: rgba(255, 255, 255, 0.045);
  --line: rgba(255, 255, 255, 0.11);
  --hype: 0;
  --font: "Pretendard", "Segoe UI Variable", "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
  --font-num: "Impact", "Arial Black", "Segoe UI Black", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  user-select: none;
}

body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(1000px 700px at 15% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 65%),
    radial-gradient(900px 700px at 110% 110%, color-mix(in srgb, var(--accent2) 20%, transparent), transparent 62%),
    linear-gradient(160deg, var(--bg2), var(--bg) 60%);
}
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 1; opacity: .18;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,.055) 0 1px, transparent 1px 3px);
}

#app { position: relative; z-index: 2; height: 100%; }

.screen { display: none; height: 100%; }
.screen.active { display: block; }

/* ---------- 공통 ---------- */
.btn {
  font-family: var(--font); font-weight: 800; font-size: 15px;
  padding: 13px 22px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); cursor: pointer;
  transition: transform .09s ease, box-shadow .18s ease, background .18s ease;
  letter-spacing: .2px;
}
.btn:hover { transform: translateY(-2px); background: rgba(255,255,255,.09); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn.primary {
  border: none; color: #12001f;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  box-shadow: 0 8px 26px -8px var(--accent), 0 0 0 1px rgba(255,255,255,.15) inset;
}
.btn.primary:hover { box-shadow: 0 14px 34px -8px var(--accent), 0 0 26px -4px var(--accent2); }
.btn.ghost { color: var(--muted); }
.btn.ghost:hover { color: var(--ink); }
.btn.block { display: block; width: 100%; }

/* ---------- 타이틀 ---------- */
#screen-title { overflow-y: auto; }
.title-wrap {
  max-width: 560px; margin: 0 auto; padding: 22px 20px 32px;
  display: flex; flex-direction: column; gap: 10px;
}
.logo {
  margin: 6px 0 0; text-align: center; font-family: var(--font-num);
  font-size: clamp(46px, 12vw, 76px); letter-spacing: 3px; line-height: .95;
  background: linear-gradient(180deg, #fff 8%, var(--accent2) 45%, var(--accent) 95%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 22px color-mix(in srgb, var(--accent) 60%, transparent));
  animation: logoPulse 3.6s ease-in-out infinite;
}
.logo span {
  display: inline-block; transform: rotate(-8deg) translateY(-2px);
  background: linear-gradient(180deg, #fff 8%, var(--accent2) 45%, var(--accent) 95%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
@keyframes logoPulse { 50% { filter: drop-shadow(0 0 34px color-mix(in srgb, var(--accent2) 75%, transparent)); } }
.tagline { margin: 0 0 2px; text-align: center; color: var(--muted); font-size: 14px; font-weight: 600; }

/* 프로필 스트립 — 랭크 / 다음 랭크까지 / 누적 */
.profile {
  display: flex; align-items: center; gap: 14px;
  background: rgba(0,0,0,.28); border: 1px solid var(--line);
  border-radius: 14px; padding: 11px 14px;
}
.prank { font-size: 17px; font-weight: 800; color: var(--accent2); white-space: nowrap; }
.prank em { font-style: normal; font-size: 20px; }
.pbar { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.ptrack { height: 5px; border-radius: 99px; background: rgba(255,255,255,.15); overflow: hidden; }
#rank-fill {
  height: 100%; width: 0%; border-radius: 99px;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 70%, transparent);
  transition: width .4s ease;
}
.plabel { font-size: 10px; color: var(--muted); font-weight: 700; letter-spacing: .5px; }
.pstat { text-align: right; flex: 0 0 auto; white-space: nowrap; }
.pstat > span { display: block; font-size: 10px; color: var(--muted); font-weight: 700; letter-spacing: 1px; }
.pstat b { display: block; font-size: 15px; font-weight: 900; font-variant-numeric: tabular-nums; }

.sec { margin: 8px 0 0; font-size: 12px; letter-spacing: 2px; color: var(--muted); font-weight: 800; }

/* 모드 카드 — 최고기록 배지를 카드 안으로 */
.mode-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode-card {
  text-align: left; cursor: pointer; font-family: var(--font);
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px; color: var(--ink); transition: all .16s ease;
}
.mode-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mode-head b { font-size: 17px; font-weight: 800; }
.rec {
  font-size: 10px; font-weight: 900; letter-spacing: .5px; padding: 3px 8px; border-radius: 99px;
  background: color-mix(in srgb, var(--accent2) 14%, transparent); color: var(--accent2);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.rec.empty { background: rgba(255,255,255,.06); color: var(--muted); }
.mode-card p { margin: 4px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.mode-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent2) 60%, transparent); }
.mode-card.sel {
  border-color: transparent;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent2) 26%, transparent), color-mix(in srgb, var(--accent) 26%, transparent));
  box-shadow: 0 0 0 2px var(--accent2) inset, 0 10px 30px -12px var(--accent2);
}
.mode-card.sel .rec { background: rgba(0,0,0,.3); }

/* 주 CTA — 선택한 모드 이름을 그대로 */
.cta {
  display: flex; align-items: center; justify-content: center; gap: 10px; cursor: pointer;
  font-family: var(--font); font-weight: 800; font-size: 17px; padding: 18px;
  border: none; border-radius: 14px; color: #12001f;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  box-shadow: 0 10px 30px -8px var(--accent), 0 0 0 1px rgba(255,255,255,.15) inset;
  transition: transform .09s ease, box-shadow .18s ease;
}
.cta:hover { transform: translateY(-2px); box-shadow: 0 16px 38px -8px var(--accent), 0 0 26px -4px var(--accent2); }
.cta:active { transform: translateY(1px) scale(.99); }
.cta svg { display: block; }

/* 설정 바 — 스킨 / 볼륨 / 조작법 */
.setbar {
  background: rgba(0,0,0,.28); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 9px;
}
.skin-row { display: flex; gap: 6px; }
.skin-chip {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  font-family: var(--font); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 6px; color: var(--muted); font-size: 11px; font-weight: 700;
  transition: all .16s ease;
}
.skin-chip .dots { display: flex; gap: 2px; }
.skin-chip .dots i { width: 7px; height: 7px; border-radius: 2px; display: block; }
.skin-chip:hover { color: var(--ink); }
.skin-chip.sel { color: #14001f; background: linear-gradient(135deg, var(--accent2), var(--accent)); border-color: transparent; }
.set-row { display: flex; align-items: center; gap: 12px; }
.vol { flex: 1; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.keys-btn {
  font-family: var(--font); font-size: 12px; font-weight: 800; color: var(--muted); cursor: pointer;
  padding: 7px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); white-space: nowrap; transition: color .16s ease;
}
.keys-btn:hover { color: var(--ink); }

input[type=range] {
  flex: 1; min-width: 0; -webkit-appearance: none; appearance: none; height: 5px; border-radius: 99px;
  background: rgba(255,255,255,.15); outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent2), var(--accent)); cursor: pointer;
  box-shadow: 0 0 12px var(--accent);
}
input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border: none; border-radius: 50%;
  background: var(--accent); cursor: pointer;
}

.hint { text-align: center; font-size: 11px; color: var(--muted); margin: 2px 0 0; opacity: .75; }

/* ---------- 게임 ---------- */
.game-shell {
  position: relative; height: 100%; max-width: 760px; margin: 0 auto;
  padding: 10px 10px 12px; display: flex; flex-direction: column; gap: 8px;
}
.topbar { display: flex; align-items: center; gap: 10px; }
.mode-tag {
  font-size: 11px; font-weight: 800; letter-spacing: 1.5px; padding: 6px 11px; border-radius: 99px;
  background: linear-gradient(135deg, var(--accent2), var(--accent)); color: #14001f;
}
.score-wrap { flex: 1; text-align: center; line-height: 1; }
.score-wrap .lbl { display: block; font-size: 9px; letter-spacing: 3px; color: var(--muted); font-weight: 800; }
.score-wrap b {
  display: block; font-family: var(--font-num); font-size: clamp(24px, 6vw, 34px); letter-spacing: 1px;
  color: #fff; text-shadow: 0 0 18px color-mix(in srgb, var(--accent2) 80%, transparent);
}
.score-wrap b.bump { animation: bump .3s cubic-bezier(.2,1.6,.4,1); }
@keyframes bump { 0% { transform: scale(1.35); color: var(--accent2); } 100% { transform: scale(1); } }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); color: var(--ink); font-size: 13px;
}
.icon-btn:hover { background: rgba(255,255,255,.1); }

/* HYPE — 두껍게, 눈금과 수치 */
.hype { display: flex; align-items: center; gap: 8px; }
.hype-label { font-size: 9px; font-weight: 900; letter-spacing: 2px; color: var(--muted); }
.hype-bar {
  flex: 1; height: 12px; border-radius: 99px; background: rgba(255,255,255,.08);
  overflow: hidden; position: relative;
}
#hype-fill {
  height: 100%; width: 0%; border-radius: 99px;
  background: linear-gradient(90deg, var(--accent2), var(--accent), #ffd84d);
  box-shadow: 0 0 14px var(--accent); transition: width .12s linear;
}
.hype-bar .tick { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(255,255,255,.22); }
.hype-pct {
  font-size: 10px; font-weight: 900; color: var(--accent2);
  font-variant-numeric: tabular-nums; min-width: 32px; text-align: right;
}

.play-area { flex: 1; min-height: 0; display: flex; gap: 10px; justify-content: center; align-items: stretch; }
.side { width: 108px; display: flex; flex-direction: column; gap: 8px; flex: 0 0 auto; justify-content: flex-start; }
.panel {
  background: rgba(0,0,0,.32); border: 1px solid var(--line); border-radius: 14px;
  padding: 8px; display: flex; flex-direction: column; gap: 4px;
}
.panel-title { font-size: 9px; letter-spacing: 2.5px; color: var(--muted); font-weight: 900; text-align: center; }
#hold { width: 100%; height: 48px; display: block; }

/* 레벨을 큰 숫자로, 나머지는 보조 */
.panel.statcol { flex: 0 0 auto; }
.lv-big {
  display: flex; align-items: center; justify-content: center; padding: 4px 0 2px;
  font-size: clamp(28px, 7vw, 40px); font-weight: 900; line-height: 1; color: var(--accent2);
  font-variant-numeric: tabular-nums; text-shadow: 0 0 22px color-mix(in srgb, var(--accent2) 45%, transparent);
}
.lv-big.bump { animation: bump .3s cubic-bezier(.2,1.6,.4,1); }
.divider { height: 1px; background: rgba(255,255,255,.09); margin: 6px 0; flex: 0 0 auto; }
.srow { display: flex; justify-content: space-between; align-items: baseline; }
.srow span { font-size: 9.5px; letter-spacing: 1px; color: var(--muted); font-weight: 700; }
.srow b { font-size: 15px; font-weight: 900; font-variant-numeric: tabular-nums; color: var(--ink); }
#goal-wrap b { color: var(--accent2); }

/* NEXT — 첫 조각만 강조 */
.panel.next-box { flex: 0 0 auto; }
.next-first {
  height: 76px; flex: 0 0 auto; margin-top: 2px; border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--accent2) 35%, transparent);
  background: color-mix(in srgb, var(--accent2) 6%, transparent);
  box-shadow: 0 0 18px -6px color-mix(in srgb, var(--accent2) 60%, transparent);
}
#next-first { width: 100%; height: 100%; display: block; }
.next-rest { height: 200px; margin-top: 6px; display: flex; }
#next { width: 100%; height: 100%; display: block; opacity: .82; }

.board-wrap {
  position: relative;
  height: 100%; aspect-ratio: 1 / 2; max-width: 100%; flex: 0 1 auto;
  border-radius: 16px; overflow: hidden;
  box-shadow: 0 0 0 1px var(--line), 0 24px 60px -20px #000,
              0 0 calc(30px + var(--hype) * 60px) calc(var(--hype) * 6px) color-mix(in srgb, var(--accent) 55%, transparent);
}
#board { width: 100%; height: 100%; display: block; touch-action: none; }

/* 콤보 / B2B — 보드 위로 */
.board-tags {
  position: absolute; top: 10px; right: 10px; z-index: 4;
  display: flex; flex-direction: column; gap: 5px; align-items: flex-end;
  pointer-events: none;
}
.tag {
  font-size: 11px; font-weight: 900; padding: 5px 10px; border-radius: 99px;
  animation: tagIn .25s ease; white-space: nowrap;
}
.tag.combo { background: linear-gradient(135deg, #ffd84d, #ff8a3d); color: #2a1400; box-shadow: 0 0 18px -4px #ffd84d; }
.tag.b2b { background: linear-gradient(135deg, var(--accent), #ff8a3d); color: #26000f; box-shadow: 0 0 18px -4px var(--accent); }
@keyframes tagIn { from { transform: scale(.6); opacity: 0; } }

/* 터치 컨트롤 */
.touchpad { display: none; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.tbtn {
  font-family: var(--font); font-weight: 800; font-size: 18px; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 0; cursor: pointer;
}
.tbtn.small { font-size: 13px; }
.tbtn.wide { grid-column: span 4; font-size: 13px; letter-spacing: 1px; }
.tbtn.down { background: linear-gradient(135deg, var(--accent2), var(--accent)); color: #14001f; }
@media (pointer: coarse) { .touchpad { display: grid; } .side { width: 86px; } }

/* 오버레이 */
.overlay {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(4,2,12,.82); backdrop-filter: blur(6px); border-radius: 16px; z-index: 5;
}
.overlay.show { display: flex; }
.over-card { display: flex; flex-direction: column; gap: 10px; width: min(300px, 80%); text-align: center; }
.over-card h2 { margin: 0 0 6px; font-family: var(--font-num); font-size: 30px; letter-spacing: 2px; color: var(--accent2); }

/* ---------- 결과 ---------- */
#screen-result { display: none; }
#screen-result.active { display: flex; align-items: center; justify-content: center; padding: 18px; overflow-y: auto; }
.result-card {
  width: min(430px, 100%); background: rgba(10,5,22,.72); border: 1px solid var(--line);
  border-radius: 22px; padding: 22px; text-align: center;
  box-shadow: 0 30px 80px -30px #000, 0 0 60px -30px var(--accent);
  animation: cardIn .38s cubic-bezier(.2,1.3,.4,1);
}
@keyframes cardIn { from { transform: translateY(24px) scale(.94); opacity: 0; } }
.new-best {
  display: inline-block; font-size: 12px; font-weight: 900; padding: 6px 14px; border-radius: 99px;
  background: linear-gradient(135deg, #ffd84d, var(--accent)); color: #23000f; margin-bottom: 8px;
  animation: bestPulse 1.1s ease-in-out infinite;
}
@keyframes bestPulse { 50% { transform: scale(1.07); } }
.res-title { margin: 0 0 14px; font-family: var(--font-num); font-size: 38px; letter-spacing: 2px; }
.res-title.lose { color: #ff5c85; text-shadow: 0 0 26px rgba(255,92,133,.55); }
.res-title.win { color: #7dff9e; text-shadow: 0 0 26px rgba(125,255,158,.55); }

/* 랭크를 보상 축으로 */
.rank-block {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: color-mix(in srgb, var(--accent2) 7%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent2) 22%, transparent);
  border-radius: 16px; padding: 12px 14px;
}
.rank-medal {
  width: 46px; height: 46px; flex: 0 0 auto; border-radius: 14px; font-size: 26px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.35); box-shadow: 0 0 22px -6px var(--accent2);
}
.rank-body { flex: 1; min-width: 0; }
.rank-name { font-size: 20px; font-weight: 900; color: var(--accent2); line-height: 1.1; }
.rank-track { height: 6px; border-radius: 99px; background: rgba(255,255,255,.15); overflow: hidden; margin: 8px 0 5px; }
#res-rank-fill {
  height: 100%; width: 0%; border-radius: 99px;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 70%, transparent);
  transition: width .6s cubic-bezier(.2,1,.3,1);
}
.rank-note { font-size: 10.5px; color: var(--muted); font-weight: 700; }
.rank-note b { color: var(--ink); }

.res-main { background: rgba(0,0,0,.3); border-radius: 16px; padding: 14px; margin-top: 12px; }
.res-big span { display: block; font-size: 10px; letter-spacing: 3px; color: var(--muted); font-weight: 800; }
.res-big b { display: block; font-family: var(--font-num); font-size: 44px; letter-spacing: 1px; color: #fff; text-shadow: 0 0 24px var(--accent2); }
.res-sub { display: flex; gap: 10px; margin-top: 10px; }
.res-sub > div { flex: 1; background: rgba(255,255,255,.05); border-radius: 12px; padding: 8px; }
.res-sub span { display: block; font-size: 9.5px; color: var(--muted); letter-spacing: 2px; font-weight: 800; }
.res-sub b { font-size: 21px; font-weight: 900; font-variant-numeric: tabular-nums; color: var(--accent2); }

/* 자랑거리 3개만 크게 */
.highlights { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 12px; }
.hl { background: rgba(255,255,255,.05); border-radius: 12px; padding: 10px 5px; }
.hl span { display: block; font-size: 9.5px; color: var(--muted); font-weight: 700; }
.hl b { display: block; margin-top: 2px; font-size: 24px; font-weight: 900; font-variant-numeric: tabular-nums; color: var(--ink); }
.hl.gold b { color: #ffd84d; }
.minor {
  display: flex; justify-content: center; gap: 14px; margin: 9px 0 16px;
  font-size: 11px; color: var(--muted); font-weight: 700;
}
.minor b { color: var(--ink); font-variant-numeric: tabular-nums; }

.result-card .btn.primary { font-size: 16px; padding: 16px; }
.sub-row { display: flex; gap: 8px; margin-top: 8px; }
.sub-row .btn { flex: 1; font-size: 13px; padding: 11px 8px; }

/* ---------- 도움말 ---------- */
#screen-help { overflow-y: auto; }
.help-card { max-width: 520px; margin: 0 auto; padding: 28px 20px 44px; }
.help-card h2 { font-family: var(--font-num); font-size: 24px; letter-spacing: 2px; color: var(--accent2); margin: 22px 0 10px; }
.help-card h2:first-child { margin-top: 0; }
.keys { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 7px; }
.keys li { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.keys li span { margin-left: auto; color: var(--ink); font-weight: 600; }
kbd {
  font-family: var(--font); font-size: 11px; font-weight: 800; padding: 4px 8px; border-radius: 7px;
  background: rgba(255,255,255,.08); border: 1px solid var(--line); border-bottom-width: 2px; color: var(--ink);
}
.help-p { font-size: 13px; line-height: 1.7; color: var(--muted); }
.tips { padding-left: 18px; margin: 0; font-size: 13px; line-height: 1.9; color: var(--muted); }
.tips b { color: var(--accent2); }
#btn-help-close { width: 100%; margin-top: 26px; padding: 15px; }

/* ---------- 작은 화면 ---------- */
@media (max-width: 480px) {
  .side { width: 74px; }
  #hold { height: 40px; }
  .next-first { height: 58px; }
  .panel { padding: 6px; }
  .srow b { font-size: 13px; }
  .game-shell { padding: 8px 8px 10px; }
  .profile { gap: 10px; padding: 10px; }
  .pstat span { display: none; }
  .skin-chip { font-size: 10px; padding: 7px 4px; }
  .setbar { padding: 8px; }
}
@media (max-height: 760px) {
  .next-rest { height: 150px; }
}
@media (max-height: 620px) {
  .hype-bar { height: 8px; }
  .hype-pct { display: none; }
  .next-first { height: 56px; }
  .next-rest { height: 116px; }
  #hold { height: 38px; }
}
