/* Drift Board — 흐름 예측 퍼즐
   분위기: 강물 위 종이배(03 §1). 새벽 하늘빛 배경, 짙은 청록 물 판, 흰 종이로 접은 색 배. */

:root {
  --sky: #e6f1f2;
  --sky-2: #cfe3e6;
  --ink: #17313b;
  --ink-soft: #5b7780;
  --water: #1f6f86;
  --water-2: #175a70;
  --water-3: #2a88a1;
  --paper: #fffdf7;
  --accent: #ff7a45;
  --gold: #f2b233;
  --shadow: 0 6px 16px rgba(18, 52, 64, 0.18);
  --cell: 56px;
  --speed: 1;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 80% -10%, rgba(255, 236, 200, 0.75), transparent 45%),
    linear-gradient(180deg, var(--sky), var(--sky-2));
  background-attachment: fixed;
  font: 16px/1.5 "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.app { max-width: 480px; margin: 0 auto; min-height: 100%; position: relative; overflow-x: hidden; }
.screen { padding: 12px 16px 20px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--paper);
  box-shadow: 0 2px 0 rgba(18, 52, 64, 0.2); font-size: 18px; display: grid; place-items: center;
}
.icon-btn:active { transform: translateY(2px); box-shadow: none; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 999px; background: var(--paper); font-size: 14px; color: var(--ink-soft); }
.pill b { color: var(--ink); }

/* ── 지도: 강 ── */
.map-head { text-align: center; padding: 14px 0 6px; }
.logo { margin: 0; font-size: 40px; font-weight: 900; letter-spacing: 0.01em; display: inline-flex; align-items: center; gap: 10px; }
.logo-boat {
  width: 44px; height: 30px; position: relative;
  background: linear-gradient(180deg, #fff 0 45%, #e9e2d3 45%);
  clip-path: polygon(0 45%, 22% 45%, 50% 0, 78% 45%, 100% 45%, 82% 100%, 18% 100%);
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.2));
  animation: bob 2.4s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-3px) rotate(-4deg); } }
.tagline { margin: 4px 0 12px; color: var(--ink-soft); font-size: 14px; }
.map-stats { display: flex; justify-content: center; align-items: center; gap: 8px; }

.daily-card {
  width: 100%; margin: 12px 0 8px; padding: 14px 16px; border: 0; border-radius: 16px; text-align: left;
  background: linear-gradient(135deg, var(--water-2), var(--water)); color: #fff; box-shadow: var(--shadow);
  display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center;
}
.daily-card .d-icon { font-size: 30px; text-align: center; }
.daily-card .d-title { font-weight: 800; font-size: 17px; display: block; }
.daily-card .d-sub { font-size: 13px; opacity: 0.85; display: block; }
.daily-card .d-go { padding: 8px 14px; border-radius: 999px; background: var(--gold); color: var(--ink); font-weight: 800; font-size: 14px; }
.daily-card.done .d-go { background: #ffffff2a; color: #fff; }

.chapter {
  position: relative; margin-top: 18px; padding: 16px 14px 22px; border-radius: 18px; overflow: hidden;
  background: var(--paper); box-shadow: var(--shadow);
}
/* 챕터마다 강이 가로질러 굽이친다 */
.chapter::before {
  content: ""; position: absolute; left: -10%; right: -10%; top: 70px; height: 150px; z-index: 0; opacity: 0.18;
  background: radial-gradient(60% 40% at 30% 50%, var(--c) 0 55%, transparent 56%), radial-gradient(60% 40% at 75% 60%, var(--c) 0 55%, transparent 56%);
}
.chapter > * { position: relative; z-index: 1; }
.chapter.locked { opacity: 0.55; filter: grayscale(0.7); }
.chapter h2 { margin: 0; font-size: 19px; line-height: 28px; }
.chapter .ch-intro { margin: 0; font-size: 13px; color: var(--ink-soft); }
.chapter .ch-stars { position: absolute; right: 14px; top: 16px; font-size: 13px; font-weight: 800; color: #c98c10; line-height: 28px; }
.levels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px 8px; padding-top: 14px; }
.lv {
  position: relative; justify-self: center; width: 56px; height: 56px; border: 0; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--c) 70%, #fff), var(--c) 65%); color: #fff; font-weight: 900; font-size: 20px;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
  box-shadow: 0 4px 0 color-mix(in srgb, var(--c) 60%, #000), 0 6px 10px rgba(0, 0, 0, 0.15);
}
.lv.boss { width: 62px; height: 62px; }
.lv.boss::before { content: "👑"; position: absolute; left: 50%; top: -2px; transform: translate(-50%, -60%); font-size: 15px; }
.lv.locked { background: #dde6e8; color: #9bb0b6; text-shadow: none; cursor: default; box-shadow: 0 3px 0 #c6d3d6; }
.lv.current { animation: float 1.6s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-5px); } }
.lv-wrap { position: relative; display: grid; justify-items: center; }
.lv-stars { position: absolute; bottom: -18px; font-size: 11px; letter-spacing: -1px; color: #c98c10; white-space: nowrap; }
.lv-stars .off { color: rgba(0, 0, 0, 0.15); }
.map-foot { margin: 24px 0 8px; text-align: center; font-size: 12px; color: var(--ink-soft); opacity: 0.7; }

/* ── 게임 화면: 위아래 고정, 가운데 판이 남는 높이를 다 쓴다 ── */
.screen.game { display: flex; flex-direction: column; height: 100vh; height: 100dvh; padding-bottom: 12px; }
.hud { display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 10px; }
.hud-title { line-height: 1.2; min-width: 0; }
.hud-title b { font-size: 20px; }
.hud-title span { display: block; font-size: 12px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turns { display: flex; gap: 3px; align-items: center; }
.turn-chip {
  width: 22px; height: 16px; position: relative; transition: opacity 0.3s, transform 0.3s;
  background: linear-gradient(180deg, #fff 0 45%, #e3dccb 45%);
  clip-path: polygon(0 45%, 22% 45%, 50% 0, 78% 45%, 100% 45%, 82% 100%, 18% 100%);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}
.turn-chip.used { opacity: 0.2; transform: scale(0.8); }
.turns-label { font-size: 12px; color: var(--ink-soft); margin-right: 4px; white-space: nowrap; }
.goal {
  margin: 10px 0 4px; padding: 8px 14px; border-radius: 12px; background: var(--paper);
  display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; min-height: 42px; white-space: nowrap;
  box-shadow: 0 2px 0 rgba(18, 52, 64, 0.12);
}
.goal .swatch { width: 22px; height: 22px; border-radius: 50%; background: var(--c); display: inline-grid; place-items: center; color: #fff; font-size: 11px; }
.goal.bump { animation: bump 0.35s; }
.goal.bad { color: #c2410c; }
@keyframes bump { 40% { transform: scale(1.05); } }

.stage { flex: 1 1 auto; min-height: 180px; display: flex; align-items: center; justify-content: center; touch-action: none; user-select: none; -webkit-user-select: none; }

/* ── 물 판 ── */
.board {
  position: relative; border-radius: 14px; overflow: visible;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.07) 1px, transparent 1px) 0 0 / var(--cell) var(--cell),
    linear-gradient(180deg, rgba(255, 255, 255, 0.07) 1px, transparent 1px) 0 0 / var(--cell) var(--cell),
    radial-gradient(120% 90% at 30% 20%, var(--water-3), var(--water) 55%, var(--water-2));
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.12), inset 0 -10px 30px rgba(0, 0, 0, 0.18), 0 10px 22px rgba(18, 52, 64, 0.3);
}
/* 물결 무늬가 천천히 흐른다 */
.board::before {
  content: ""; position: absolute; inset: 0; border-radius: 14px; pointer-events: none; opacity: 0.22;
  background: repeating-radial-gradient(ellipse 60px 14px at 50% 50%, transparent 0 9px, rgba(255, 255, 255, 0.6) 10px, transparent 11px 22px);
  background-size: 120px 60px; animation: waves 9s linear infinite;
}
@keyframes waves { to { background-position: 120px 60px; } }
.board.ripple::after {
  content: ""; position: absolute; inset: 0; border-radius: 14px; pointer-events: none;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35); animation: rippleOut calc(0.45s * var(--speed)) ease-out forwards;
}
@keyframes rippleOut { from { opacity: 1; } to { opacity: 0; box-shadow: inset 0 0 0 10px rgba(255, 255, 255, 0); } }
.ground, .ghosts, .boats, .fx { position: absolute; inset: 0; pointer-events: none; }
.ghosts { z-index: 2; }
.boats { z-index: 3; }
.fx { z-index: 5; }

.gcell { position: absolute; width: var(--cell); height: var(--cell); display: grid; place-items: center; }
.gcell i { display: block; }
.rock i {
  width: 78%; height: 72%; border-radius: 42% 48% 38% 46% / 50% 44% 52% 46%;
  background: radial-gradient(circle at 35% 30%, #c9d1cf, #8a9593 55%, #5f6967);
  box-shadow: 0 4px 0 #46504e, 0 6px 10px rgba(0, 0, 0, 0.3);
}
.whirl i {
  width: 82%; height: 82%; border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, rgba(255, 255, 255, 0.55) 0 18deg, transparent 18deg 60deg), radial-gradient(circle, #0e4d61 0 22%, #196a80 60%, transparent 70%);
  -webkit-mask: radial-gradient(circle, #000 60%, transparent 71%); mask: radial-gradient(circle, #000 60%, transparent 71%);
  animation: spin 2.4s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.stream i {
  width: 100%; height: 100%; opacity: 0.5;
  background: repeating-linear-gradient(90deg, transparent 0 8px, rgba(255, 255, 255, 0.85) 8px 10px, transparent 10px 16px);
  -webkit-mask: linear-gradient(90deg, transparent, #000 25% 75%, transparent); mask: linear-gradient(90deg, transparent, #000 25% 75%, transparent);
  animation: stream 0.9s linear infinite;
}
.stream { background: rgba(120, 220, 240, 0.16); }
.stream::after { content: "➜"; position: absolute; color: rgba(255, 255, 255, 0.75); font-size: calc(var(--cell) * 0.34); font-weight: 900; }
.stream.d0 i, .stream.d0::after { transform: rotate(-90deg); }
.stream.d2 i, .stream.d2::after { transform: rotate(90deg); }
.stream.d3 i, .stream.d3::after { transform: rotate(180deg); }
@keyframes stream { to { background-position: 16px 0; } }
.portal i {
  width: 80%; height: 80%; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.9) 0 18%, var(--pc) 45%, transparent 72%);
  animation: mist 2.2s ease-in-out infinite;
}
.portal b { position: absolute; right: 4px; bottom: 1px; font-size: calc(var(--cell) * 0.2); color: #fff; opacity: 0.8; }
.portal.p1 { --pc: rgba(196, 160, 255, 0.85); }
.portal.p2 { --pc: rgba(255, 170, 210, 0.85); }
.portal.p3 { --pc: rgba(170, 255, 200, 0.85); }
.portal.p4 { --pc: rgba(255, 220, 150, 0.85); }
@keyframes mist { 50% { transform: scale(0.85); opacity: 0.75; } }

/* ── 종이배 ── */
.boat, .buoy, .ghost {
  position: absolute; left: 0; top: 0; width: var(--cell); height: var(--cell); display: grid; place-items: center;
}
.hull { width: 88%; height: 88%; transition: transform calc(0.2s * var(--speed)) ease-out; }
.hull svg { width: 100%; height: 100%; display: block; overflow: visible; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.35)); }
.hull-body { fill: var(--c); stroke: rgba(0, 0, 0, 0.25); stroke-width: 2; stroke-linejoin: round; }
.hull-flap { fill: color-mix(in srgb, var(--c) 55%, #fff); }
.hull-ridge { fill: none; stroke: rgba(0, 0, 0, 0.22); stroke-width: 2; stroke-linejoin: round; }
.hull-bow { fill: none; stroke: rgba(255, 255, 255, 0.9); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.buoy-ring { fill: var(--c); stroke: #fff; stroke-width: 7; stroke-dasharray: 16 12; }
.buoy-top { fill: color-mix(in srgb, var(--c) 45%, #fff); stroke: rgba(0, 0, 0, 0.2); stroke-width: 2; }
.buoy .hull { animation: buoyBob 2s ease-in-out infinite; }
@keyframes buoyBob { 50% { transform: scale(0.93); } }
.sym { position: absolute; font-size: calc(var(--cell) * 0.22); font-weight: 900; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); pointer-events: none; }
.buoy .sym { margin-top: 0; }
.badge { position: absolute; font-size: calc(var(--cell) * 0.26); filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4)); }
.badge.lock { right: 0; bottom: 0; }
.badge.crown-b { left: 50%; top: -4px; transform: translate(-50%, -30%); }
.boat.crown .hull svg { filter: drop-shadow(0 0 5px #ffe07a) drop-shadow(0 3px 2px rgba(0, 0, 0, 0.35)); }
.boat.turning .hull { transform-origin: 50% 50%; }
.boat.aiming .hull svg { filter: drop-shadow(0 0 6px #fff) drop-shadow(0 3px 2px rgba(0, 0, 0, 0.35)); }
.boat.hinted .hull svg { animation: hintGlow 0.9s ease-in-out infinite; }
@keyframes hintGlow { 50% { filter: drop-shadow(0 0 8px var(--gold)) drop-shadow(0 0 3px var(--gold)); } }
.boat.bad, .buoy.bad { animation: shake 0.3s; }
@keyframes shake { 25% { margin-left: -4px; } 75% { margin-left: 4px; } }

/* 미리보기 */
.ghost { opacity: 0.55; }
.ghost .hull svg { filter: none; }
.ghost .hull-body { stroke: #fff; stroke-width: 4; stroke-dasharray: 8 6; }
.wake { position: absolute; height: 0; border-top: 3px dotted rgba(255, 255, 255, 0.85); transform-origin: 0 50%; }
.sink-mark {
  position: absolute; width: var(--cell); height: var(--cell); display: grid; place-items: center; z-index: 4;
  color: #ffe07a; font-weight: 900; font-size: calc(var(--cell) * 0.5); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  animation: pulse 0.8s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(0.85); } }
.hint-arrow { position: absolute; font-size: calc(var(--cell) * 0.5); color: var(--gold); font-weight: 900; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); animation: pulse 0.8s ease-in-out infinite; }

/* 가라앉을 때 물보라 */
.splash {
  position: absolute; width: calc(var(--cell) * 0.4); height: calc(var(--cell) * 0.4); margin: calc(var(--cell) * -0.2) 0 0 calc(var(--cell) * -0.2);
  border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--c);
  animation: splash calc(0.9s * var(--speed)) ease-out forwards;
}
@keyframes splash { to { transform: scale(3.2); opacity: 0; } }

/* ── 아래 버튼 ── */
.prompt { margin: 10px 0 4px; min-height: 44px; text-align: center; font-size: 14px; color: var(--ink-soft); }
.prompt b { color: var(--ink); }
.flow-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.flow-btn {
  border: 0; border-radius: 14px; padding: 11px 8px; font-weight: 800; font-size: 15px; color: #fff;
  background: linear-gradient(180deg, var(--water-3), var(--water)); box-shadow: 0 4px 0 var(--water-2);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.flow-btn span { font-size: 18px; }
.flow-btn:active { transform: translateY(3px); box-shadow: none; }
.flow-btn:disabled { opacity: 0.4; cursor: default; }
.flow-btn.pulse { animation: btnPulse 1s ease-in-out infinite; }
@keyframes btnPulse { 50% { box-shadow: 0 4px 0 var(--water-2), 0 0 0 5px rgba(242, 178, 51, 0.7); } }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
.act {
  border: 0; border-radius: 12px; padding: 8px 6px; background: var(--paper); box-shadow: 0 3px 0 rgba(18, 52, 64, 0.2);
  font-weight: 700; font-size: 13px; display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.act span { font-size: 18px; line-height: 1; }
.act:active { transform: translateY(3px); box-shadow: none; }
.act:disabled { opacity: 0.4; cursor: default; }

/* ── 겹창 ── */
.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(10, 36, 46, 0.5); animation: fadeIn 0.2s; }
@keyframes fadeIn { from { opacity: 0; } }
.card {
  position: relative; width: min(360px, 100%); padding: 24px 20px 18px; border-radius: 20px; text-align: center;
  background: var(--paper); box-shadow: 0 20px 40px rgba(10, 36, 46, 0.4); animation: cardIn 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes cardIn { from { transform: translateY(30px) scale(0.9); opacity: 0; } }
.card h2 { margin: 0 0 4px; font-size: 26px; }
.card p { margin: 6px 0; color: var(--ink-soft); }
.card .big { font-size: 54px; line-height: 1.1; margin: 4px 0; }
.card .row { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.btn { border: 0; border-radius: 10px; padding: 11px 18px; font-weight: 800; background: #e4eef0; box-shadow: 0 3px 0 #c3d5d9; }
.btn.primary { background: var(--water); color: #fff; box-shadow: 0 3px 0 var(--water-2); }
.btn.gold { background: var(--gold); box-shadow: 0 3px 0 #b8841b; }
.btn:active { transform: translateY(3px); box-shadow: none; }
.result-stars { font-size: 44px; letter-spacing: 6px; margin: 6px 0; }
.result-stars i { display: inline-block; font-style: normal; color: rgba(0, 0, 0, 0.12); }
.result-stars i.on { color: var(--gold); animation: starIn 0.4s cubic-bezier(0.2, 1.6, 0.4, 1) backwards; text-shadow: 0 2px 0 #b8841b; }
@keyframes starIn { from { transform: scale(0) rotate(-40deg); } }
/* 클리어: 종이배 한 척이 잔잔한 물 위로 흘러간다(03 §4) */
.river { position: relative; height: 70px; margin: -6px -20px 4px; overflow: hidden; border-radius: 20px 20px 0 0; background: linear-gradient(180deg, transparent 40%, rgba(42, 136, 161, 0.25) 40%); }
.river .sail { position: absolute; left: 0; top: 16px; width: 54px; height: 38px; animation: sail 3.2s ease-in-out infinite; }
@keyframes sail { from { transform: translateX(-60px) rotate(-3deg); } 50% { transform: translateX(150px) rotate(3deg); } to { transform: translateX(380px) rotate(-3deg); } }
.intro-demo { display: flex; justify-content: center; align-items: center; gap: 8px; margin: 8px 0; font-size: 34px; }
.mini { display: inline-grid; grid-auto-flow: column; gap: 2px; padding: 4px; border-radius: 8px; background: var(--water); }
.mini i { width: 26px; height: 26px; display: grid; place-items: center; font-style: normal; font-size: 18px; color: #fff; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid #e4eef0; text-align: left; }
.setting small { display: block; color: var(--ink-soft); }

.hand { position: fixed; z-index: 15; font-size: 40px; pointer-events: none; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.35)); margin: -6px 0 0 -14px; }
.hand.tap { animation: handTap 1.2s ease-in-out infinite; }
@keyframes handTap { 0%, 100% { transform: translate(0, 10px) scale(1); } 40% { transform: translate(0, 0) scale(0.88); } 60% { transform: translate(0, 0) scale(0.88); } }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 30; transform: translate(-50%, 20px); opacity: 0;
  padding: 10px 16px; border-radius: 999px; background: rgba(23, 49, 59, 0.92); color: #fff; font-size: 14px;
  transition: opacity 0.2s, transform 0.2s; pointer-events: none; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) { .goal { font-size: 14px; gap: 6px; padding: 8px 10px; } .flow-btn { font-size: 14px; } }
@media (max-height: 640px) { .prompt { min-height: 36px; margin: 6px 0 2px; font-size: 13px; } .act { padding: 6px; } .flow-btn { padding: 9px 6px; } .goal { margin: 6px 0 2px; } }
@media (prefers-reduced-motion: reduce) { .lv.current, .board::before, .whirl i, .stream i, .portal i, .buoy .hull, .logo-boat, .river .sail { animation: none; } }
