/* RotaSum 프로토타입 — 네모와 숫자로 만든다. 아트로 재미를 구제하지 않는다 */

:root {
  --bg: #13151b;
  --panel: #1c1f28;
  --panel-2: #232733;
  --line: #2f3442;
  --text: #e8ebf2;
  --muted: #8c93a3;
  --cell-bg: #2a2f3c;
  --queue-bg: #1f232d;
  --accent: #ffd166;
  --good: #6ee7a0;
  --bad: #ff7272;
  --cell: 48px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
button:hover { border-color: #4a5164; }
button.primary { background: var(--accent); color: #1a1406; border-color: transparent; font-weight: 800; }
kbd { font-size: 11px; opacity: .7; margin-left: 6px; font-family: inherit; }
.muted { color: var(--muted); }

.app {
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 좁은 화면: 두 열 묶음을 풀어 한 줄로 쌓고 실험실은 맨 아래로 */
.info-col, .stage-col { display: contents; }
.lab { order: 9; }

/* 넓은 화면: 왼쪽 정보, 오른쪽 판. 판이 세로를 다 쓸 수 있다 */
@media (min-width: 980px) {
  .app { max-width: 1320px; flex-direction: row; align-items: flex-start; gap: 20px; }
  .info-col { display: flex; flex-direction: column; gap: 10px; width: 360px; flex: none; }
  .stage-col { display: flex; flex-direction: column; gap: 10px; flex: 1; min-width: 0; }
  .lab { order: 0; }
  .route { flex-wrap: wrap; }
  .route li { min-width: 0; flex: 1 1 40%; }
}

/* ---- HUD ---------------------------------------------------------------- */

.hud { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.hp { display: flex; align-items: center; gap: 8px; flex: 1; }
.hp-bar { flex: 1; height: 10px; background: var(--panel-2); border-radius: 6px; overflow: hidden; }
.hp-bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ff6b6b, #ffb36b); transition: width .4s; }
.stat { color: var(--muted); }
.stat b { color: var(--text); }

.route {
  list-style: none; margin: 0; padding: 0;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
}
.route li {
  flex: 1 0 auto;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 8px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line);
  font-size: 11px; color: var(--muted); min-width: 86px;
}
.route li .ico { font-size: 18px; }
.route li .chips { display: flex; gap: 3px; }
.route li .zero-chance { font-size: 9px; color: #fff4c2; background: #5a4a14; border-radius: 4px; padding: 0 4px; }
.route li.done { opacity: .4; }
.route li.current { border-color: var(--accent); color: var(--text); }
.route li.upcoming { border-style: dashed; border-color: #56607a; }

.chip {
  display: inline-grid; place-items: center;
  min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 5px; font-style: normal; font-weight: 800; font-size: 12px;
  color: var(--g); background: color-mix(in srgb, var(--g) 18%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--g) 60%, transparent);
}

.encounter { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.enc-head { display: flex; align-items: center; gap: 10px; }
.enc-icon { font-size: 30px; }
.enc-title { flex: 1; min-width: 0; }
.enc-title h2 { margin: 0; font-size: 16px; }
.enc-title p { margin: 2px 0 0; font-size: 12px; color: var(--muted); min-height: 2.6em; }
.enc-phase { font-size: 12px; color: var(--accent); white-space: nowrap; }

/* 조우마다 게이지 줄 수가 달라도(2~4줄) 패널 높이가 같아야 판 크기가 조우 사이에 흔들리지 않는다 */
.gauges { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; min-height: 122px; }
.gauge { display: grid; grid-template-columns: 92px 1fr; grid-template-rows: auto auto; column-gap: 8px; font-size: 12px; }
.gauge .gl { grid-row: span 2; align-self: center; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.gauge .gb { position: relative; height: 10px; background: var(--panel-2); border-radius: 6px; overflow: hidden; align-self: end; }
.gauge .gb i { position: absolute; inset: 0 auto 0 0; background: var(--g); border-radius: 6px; transition: width .25s; }
.gauge .gb u { position: absolute; top: -2px; bottom: -2px; width: 2px; background: #fff; text-decoration: none; }
.gauge .gt { color: var(--muted); font-size: 11px; }

.timer { position: relative; height: 16px; background: var(--panel); border-radius: 8px; overflow: hidden; }
.timer i { position: absolute; inset: 0 auto 0 0; background: #5aa9ff; }
.timer i.low { background: var(--bad); }
.timer span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; font-weight: 700; }

/* ---- 판 ----------------------------------------------------------------- */

.play { position: relative; display: flex; justify-content: center; gap: 8px; padding: 4px 0; }

.board-wrap { position: relative; flex: none; }
.board-wrap.busy .row-hits { pointer-events: none; }

.queue-bg {
  position: absolute; left: 0; top: 0;
  border-radius: 10px; background: repeating-linear-gradient(135deg, #191c24 0 6px, #1c2029 6px 12px);
}
.queue-bg span { position: absolute; left: -2px; top: -14px; font-size: 10px; color: var(--muted); }

.board-frame {
  position: absolute; left: 0;
  border-radius: 12px; background: #181b23;
  box-shadow: 0 0 0 2px #333a4a;
}
/* 정사각형은 90도 돌려도 외형이 같다. 모서리 표시가 회전을 보이게 한다 (11장) */
.board-frame .corner {
  position: absolute; left: -2px; top: -2px; width: 22px; height: 22px;
  border-left: 4px solid var(--accent); border-top: 4px solid var(--accent); border-top-left-radius: 12px;
}

.cells { position: absolute; left: 0; --move: 0ms; --ease: ease-in-out; }

.cell {
  position: absolute; left: 0; top: 0;
  width: var(--cell); height: var(--cell);
  transition: transform var(--move) var(--ease), opacity var(--move) linear;
  will-change: transform;
}
.cell .digit {
  position: absolute; inset: 3px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--cell-bg);
  font-weight: 800; font-size: calc(var(--cell) * .48); line-height: 1;
  font-variant-numeric: tabular-nums;
  color: #dde2ec;
  transition: background .15s, color .15s, transform var(--move, 200ms) var(--ease, ease);
}
/* 6과 9는 밑줄로 구분한다 (D012) */
.cell[data-v="6"] .digit, .cell[data-v="9"] .digit { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }

/* 대기열 칸은 낮은 줄에 맞춰 줄여 그린다. 판으로 들어오면 원래 크기로 돌아온다 */
.cell.queued .digit { background: var(--queue-bg); color: #6f7687; transform: scale(var(--qscale, .6)); }
.cell.q-hidden { opacity: 0; }
.cell.mapped .digit {
  color: var(--g);
  background: color-mix(in srgb, var(--g) 22%, var(--cell-bg));
  box-shadow: inset 0 0 0 2px var(--g);
}
.cell.next .digit { outline: 2px dashed color-mix(in srgb, var(--g) 70%, transparent); outline-offset: -5px; }
.cell.absorbed { opacity: 0; }

.cell.hit .digit { animation: hit var(--explode, 280ms) ease-out forwards; }
@keyframes hit {
  50% { transform: scale(1.22); background: var(--g); color: #111; }
  100% { transform: scale(1.1); background: var(--g); color: #111; }
}
.cell.shape .digit { animation: shape var(--combo-hold, 260ms) ease-out forwards; }
@keyframes shape {
  40% { transform: scale(1.2) rotate(-6deg); }
  100% { transform: scale(1.14); background: #fff4c2; color: #3b2a00; box-shadow: 0 0 22px #ffd166; }
}
/* ② 히트스톱 — 빛나는 칸이 한 박자 굳고 더 밝아진다 */
.board-wrap.hitstop .cell.shape .digit { animation-play-state: paused; filter: brightness(1.35) saturate(1.2); }

/* ---- 콤보 이펙트 (7단계, D048) ------------------------------------------- */

.fx-shapes { position: absolute; left: 0; pointer-events: none; overflow: visible; z-index: 2; }
.fx-mark {
  fill: none; stroke: var(--fx); stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 1; stroke-dashoffset: 1;
  filter: drop-shadow(0 0 6px var(--fx)) drop-shadow(0 0 14px var(--fx));
}
.fx-shapes.draw .fx-mark { animation: fx-draw var(--combo-hold, 260ms) cubic-bezier(.3, .7, .4, 1) forwards; }
.fx-shapes.fade .fx-mark { stroke-dashoffset: 0; opacity: 0; transition: opacity 140ms; }
@keyframes fx-draw { to { stroke-dashoffset: 0; } }

/* ③ 파편과 고리 */
.fx-shard {
  position: absolute; width: var(--s); height: var(--s);
  background: var(--fx); border-radius: 2px;
  box-shadow: 0 0 6px var(--fx);
  transform: translate(-50%, -50%);
  animation: fx-shard var(--shard-ms, 560ms) cubic-bezier(.15, .75, .3, 1) forwards;
  pointer-events: none; z-index: 3;
}
@keyframes fx-shard {
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rot)) scale(.25); opacity: 0; }
}
.fx-ring {
  position: absolute; width: var(--ring); height: var(--ring);
  border: 3px solid var(--fx); border-radius: 50%;
  transform: translate(-50%, -50%) scale(.2);
  animation: fx-ring calc(var(--shard-ms, 560ms) * .6) ease-out forwards;
  pointer-events: none; z-index: 3;
}
@keyframes fx-ring { to { transform: translate(-50%, -50%) scale(1); opacity: 0; border-width: 1px; } }

/* ④ 흔들림과 섬광 */
.board-wrap.shake { animation: fx-shake 280ms linear; }
@keyframes fx-shake {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(calc(var(--shake) * -1), calc(var(--shake) * .5)); }
  30% { transform: translate(var(--shake), calc(var(--shake) * -.6)); }
  45% { transform: translate(calc(var(--shake) * -.7), calc(var(--shake) * -.3)); }
  60% { transform: translate(calc(var(--shake) * .5), calc(var(--shake) * .6)); }
  80% { transform: translate(calc(var(--shake) * -.25), calc(var(--shake) * -.2)); }
}
.fx-flash { position: absolute; left: 0; border-radius: 12px; background: var(--flash, #fff); opacity: 0; pointer-events: none; z-index: 2; }
.fx-flash.on { animation: fx-flash 240ms ease-out; }
@keyframes fx-flash { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ⑤ 콤보 숫자 — 단수가 오를수록 크다 */
.combo-count {
  position: absolute; left: 50%; z-index: 4;
  display: flex; flex-direction: row; align-items: baseline; gap: 6px; line-height: 1;
  transform: translate(-50%, -50%) scale(0); opacity: 0;
  pointer-events: none; text-align: center; white-space: nowrap;
}
.combo-count b {
  font-size: calc(var(--cell) * (1.1 + var(--power, 1) * .18)); font-weight: 900;
  color: #fff; -webkit-text-stroke: 2px #ff9f1c;
  text-shadow: 0 4px 0 #b3470a, 0 0 24px rgba(255, 180, 60, .8);
}
.combo-count span { font-size: calc(var(--cell) * .42); font-weight: 900; letter-spacing: .12em; color: #ffd166; text-shadow: 0 2px 0 #7a3b00; }
.combo-count em { align-self: center; font-size: calc(var(--cell) * .28); font-style: normal; font-weight: 800; color: #fff; background: rgba(0, 0, 0, .55); padding: 2px 8px; border-radius: 8px; }
.combo-count.show { animation: fx-count var(--combo-badge, 1000ms) cubic-bezier(.2, 1.4, .4, 1) forwards; }
@keyframes fx-count {
  0% { transform: translate(-50%, -50%) scale(.2) rotate(-12deg); opacity: 0; }
  18% { transform: translate(-50%, -50%) scale(1.25) rotate(4deg); opacity: 1; }
  32% { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
  80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -80%) scale(.9); opacity: 0; }
}
.combo-count.zero b { color: #fff4c2; -webkit-text-stroke-color: #d4a017; text-shadow: 0 4px 0 #7a5a00, 0 0 32px #ffd166; }

/* 움직임을 줄이는 설정이면 흔들림·섬광을 끈다 */
@media (prefers-reduced-motion: reduce) {
  .board-wrap.shake { animation: none; }
  .fx-flash.on { animation: none; }
}
.cell.gone .digit { animation: gone 120ms ease-in forwards; }
@keyframes gone { to { transform: scale(.2); opacity: 0; } }

.row-hits { position: absolute; left: 0; }
.rowhit { position: absolute; left: 0; right: 0; border-radius: 8px; cursor: pointer; }
.rowhit.hover, .rowhit:hover { background: rgba(255, 255, 255, .06); box-shadow: inset 0 0 0 2px rgba(255, 209, 102, .5); }

.floats { position: absolute; inset: 0; pointer-events: none; }
.float {
  position: absolute; transform: translate(-50%, 0);
  font-weight: 900; font-size: 15px; text-shadow: 0 1px 3px #000;
  animation: float-up 900ms ease-out forwards;
}
.float.plus { color: var(--accent); }
@keyframes float-up { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -26px; } }

.banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.9);
  padding: 8px 14px; border-radius: 12px;
  background: rgba(10, 12, 16, .88); border: 1px solid var(--line);
  font-weight: 900; font-size: 16px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s;
}
.banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.banner.combo { color: #ffd166; font-size: 20px; border-color: #ffd166; }
.banner.good { color: var(--good); }
.banner.bad { color: var(--bad); }

/* ---- 줄 결과 미리보기 (7.1) ----------------------------------------------- */

.previews { position: relative; flex: none; }
.previews.dim, .previews.busy { opacity: .45; }
.pv {
  position: absolute; left: 0; right: 0;
  display: grid; grid-template-columns: repeat(var(--pvc, 6), var(--pvw, 12px)) 1fr;
  align-content: center; align-items: center;
  padding: 0 3px; border-radius: 8px;
  background: transparent; border: 1px solid transparent;
  font-size: 12px; font-weight: 700; line-height: 1.2; color: #5d6474; font-variant-numeric: tabular-nums;
}
.pv span { text-align: center; }
.pv.hot { background: #1e222c; border-color: #3a4152; color: #7d8494; }
.pv-title {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: flex-end; padding: 0 4px 4px;
  font-size: 11px; line-height: 1.25; color: var(--muted);
}
.pv b.empty { visibility: hidden; }
.pv b { grid-column: -2 / -1; grid-row: 1 / span 2; justify-self: end; margin-left: 2px; font-size: 11px; background: var(--accent); color: #1a1406; border-radius: 6px; padding: 0 5px; }
.pv.hover { border-color: var(--accent); }

/* ---- 조작 --------------------------------------------------------------- */

.controls { display: flex; gap: 8px; justify-content: center; }
.controls button { flex: 1; max-width: 320px; padding: 14px 0; font-size: 18px; font-weight: 800; }
.timer.paused i { background: #8a93a8; }
.keys { margin: 0; text-align: center; font-size: 11px; color: var(--muted); }
@media (pointer: coarse) { .keys { display: none; } }

.overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(10, 12, 16, .55); backdrop-filter: blur(2px);
  border-radius: 14px; z-index: 5;
}
.overlay[hidden] { display: none; }
.card {
  width: min(92%, 340px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px; text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .5);
}
.card-icon { font-size: 40px; }
.card h3 { margin: 4px 0 6px; }
.card p { margin: 6px 0; font-size: 13px; }
.card .phase-line { color: var(--accent); }
.card .hint-line { color: var(--muted); }
.card .next-line { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 8px; }
.card .next-line small { opacity: .8; }
.card button { margin-top: 8px; width: 100%; padding: 12px; }
.card.win h3 { color: var(--good); }
.card.lose h3 { color: var(--bad); }

/* ---- 실험실 ------------------------------------------------------------- */

.lab { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; font-size: 13px; }
.lab summary { cursor: pointer; font-weight: 700; }
.lab-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 10px 0; }
.lab label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.lab input, .lab select {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; min-width: 0;
}
.tele-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 12px 0 6px; }
.tele-head button { padding: 4px 10px; font-size: 12px; }
.tele { overflow-x: auto; }
.tele table { border-collapse: collapse; font-size: 11px; white-space: nowrap; }
.tele th, .tele td { padding: 3px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.tele th { color: var(--muted); font-weight: 600; }

/* 좁은 화면: 게이지를 한 줄(이름 · 막대 · 숫자)로 줄여 판에 세로를 돌려준다 */
@media (max-width: 979px) {
  .pv { font-size: 11px; }
  .route li { flex-direction: row; min-width: 0; flex: none; gap: 5px; }
  .route li .nm { display: none; }
  .route li.current .nm { display: inline; }
  .enc-title p { min-height: 0; }
  .gauges { min-height: 96px; gap: 4px; margin-top: 6px; }
  .gauge { grid-template-columns: 74px minmax(0, 1fr) auto; grid-template-rows: auto; align-items: center; }
  .gauge .gl { grid-row: auto; }
  .gauge .gb { align-self: center; }
  .gauge .gt { white-space: nowrap; }
  .enc-icon { font-size: 24px; }
  .route li { padding: 4px 6px; }
  .route li .ico { font-size: 15px; }
}

@media (max-width: 420px) {
  .app { padding: 10px 16px 32px; }
  .lab-grid { grid-template-columns: minmax(0, 1fr); }
}
