/* ───────── 기본 ───────── */
:root {
  --bg: #0e1116;
  --card: #171c24;
  --card-2: #1d242f;
  --line: #2a3340;
  --text: #e8ecf1;
  --muted: #9aa7b4;
  --accent: #a3e635;       /* 라임 */
  --accent-2: #38bdf8;     /* 하늘 */
  --warn: #fb923c;
  --danger: #f87171;
  --radius: 16px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }

.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }
.hidden { display: none !important; }

/* ───────── 홈 ───────── */
.home-header {
  max-width: 1080px; margin: 0 auto; padding: 40px 20px 8px;
  text-align: center;
}
.home-header h1 { font-size: 2rem; letter-spacing: -0.5px; }
.home-header p { color: var(--muted); margin-top: 8px; }
.legend {
  display: flex; gap: 16px; justify-content: center; flex-wrap: wrap;
  margin-top: 16px; font-size: 0.85rem; color: var(--muted);
}
.legend b { color: var(--accent); font-weight: 600; }

.grid {
  max-width: 1080px; margin: 20px auto 40px; padding: 0 20px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(245px, 1fr)); gap: 14px;
}
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; text-align: left; color: var(--text);
  transition: transform .15s ease, border-color .15s ease;
  display: flex; flex-direction: column; gap: 10px;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); }
.card-top { display: flex; gap: 10px; align-items: center; }
.card-emoji { font-size: 1.8rem; }
.card-top h3 { font-size: 1.05rem; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.tags span {
  font-size: 0.7rem; color: var(--accent-2);
  background: rgba(56, 189, 248, .12); padding: 1px 7px; border-radius: 99px;
}
.card-desc { font-size: 0.82rem; color: var(--muted); flex: 1; }
.card-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 0.75rem; }
.diff { color: var(--muted); letter-spacing: 1px; }
.knee-badge {
  color: var(--accent); background: rgba(163, 230, 53, .12);
  padding: 1px 8px; border-radius: 99px; font-size: 0.72rem;
}
.card-times {
  display: flex; gap: 10px; border-top: 1px dashed var(--line); padding-top: 10px;
  font-size: 0.8rem; color: var(--text);
}
.card-times span { background: var(--card-2); border-radius: 8px; padding: 4px 9px; }
.home-footer {
  text-align: center; color: var(--muted); font-size: 0.78rem; padding: 0 20px 36px;
}

/* ───────── 모달 ───────── */
.modal {
  position: fixed; inset: 0; background: rgba(5, 8, 12, .7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 20px;
  width: min(560px, 100%); padding: 26px; position: relative;
}
.modal-close {
  position: absolute; top: 14px; right: 14px; background: none; border: none;
  color: var(--muted); font-size: 1rem;
}
.modal-head { display: flex; gap: 14px; align-items: flex-start; padding-right: 24px; }
.m-emoji { font-size: 2.4rem; line-height: 1; }
.modal-head h3 { font-size: 1.3rem; }
.modal-head p { color: var(--muted); font-size: 0.88rem; margin-top: 4px; }
.knee-note {
  margin-top: 14px; font-size: 0.82rem; color: #fcd34d;
  background: rgba(252, 211, 77, .08); border: 1px solid rgba(252, 211, 77, .25);
  border-radius: 10px; padding: 9px 12px;
}
.mode-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.mode-btn {
  background: var(--card-2); border: 1px solid var(--line); border-radius: 14px;
  color: var(--text); padding: 16px 14px; text-align: left;
  display: flex; flex-direction: column; gap: 4px;
  transition: border-color .15s ease, transform .15s ease;
}
.mode-btn:hover { border-color: var(--accent); transform: translateY(-2px); }
.mode-btn b { font-size: 1rem; }
.mode-time { color: var(--accent); font-weight: 700; font-size: 1.15rem; }
.mode-btn small { color: var(--muted); font-size: 0.74rem; }
.mode-breakdown { margin-top: 2px; }
.m-cam-tip {
  margin-top: 14px; font-size: 0.8rem; color: var(--accent-2);
  background: rgba(56, 189, 248, .08); border-radius: 10px; padding: 9px 12px;
}

/* ───────── 세션 ───────── */
.session-top {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.session-title { display: flex; align-items: center; gap: 8px; }
.session-title h2 { font-size: 1.1rem; }
.mode-badge {
  font-size: 0.7rem; color: var(--bg); background: var(--accent);
  border-radius: 99px; padding: 2px 9px; font-weight: 700; white-space: nowrap;
}
.phasebar { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.phasebar span {
  font-size: 0.72rem; color: var(--muted); border: 1px solid var(--line);
  border-radius: 99px; padding: 2px 10px; transition: all .2s ease;
}
.phasebar span.on { color: var(--bg); background: var(--accent-2); border-color: var(--accent-2); font-weight: 700; }
.phasebar span.done { color: var(--accent); border-color: var(--accent); }
.ghost-btn {
  background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 10px; padding: 6px 12px; font-size: 0.85rem;
}
.ghost-btn:hover { color: var(--text); border-color: var(--muted); }

.session-body {
  display: grid; grid-template-columns: 1fr 350px; gap: 16px;
  padding: 16px 18px; max-width: 1280px; margin: 0 auto;
}
.cam-wrap {
  position: relative; background: #05070a; border-radius: var(--radius);
  overflow: hidden; aspect-ratio: 16 / 9; align-self: start;
  border: 1px solid var(--line);
}
.cam-wrap video, .cam-wrap canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  transform: scaleX(-1);   /* 거울 모드 */
}
.cam-status {
  position: absolute; inset: auto 0 0 0; margin: 0 auto 14px; width: fit-content;
  max-width: 88%; background: rgba(8, 11, 16, .85); border: 1px solid var(--line);
  color: var(--text); font-size: 0.88rem; border-radius: 12px; padding: 9px 16px;
  text-align: center; z-index: 5;
}
.cam-status.error { border-color: var(--danger); color: var(--danger); }
.countdown {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 7rem; font-weight: 800; color: var(--accent);
  text-shadow: 0 0 40px rgba(163, 230, 53, .5); z-index: 6;
  background: rgba(5, 8, 12, .35);
}
.toast {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(251, 146, 60, .94); color: #1c1206; font-weight: 700;
  border-radius: 12px; padding: 10px 18px; font-size: 0.95rem; z-index: 7;
  max-width: 88%; text-align: center;
}
.pause-veil {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(5, 8, 12, .65); font-size: 1.6rem; font-weight: 700; z-index: 8;
}

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 14px; align-self: start;
}
.phase-chip {
  font-size: 0.72rem; color: var(--bg); background: var(--accent-2);
  padding: 2px 10px; border-radius: 99px; font-weight: 700;
}
.step-info h3 { margin-top: 8px; font-size: 1.15rem; }
.step-info p { color: var(--muted); font-size: 0.85rem; margin-top: 4px; min-height: 2.6em; }

.counters { display: flex; justify-content: center; min-height: 130px; align-items: center; }
.big-counter { text-align: center; }
.rep-num { font-size: 4.2rem; font-weight: 800; color: var(--accent); line-height: 1; }
.rep-target { font-size: 1.6rem; color: var(--muted); font-weight: 600; }
.rep-label { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }
.ring-wrap { position: relative; width: 130px; height: 130px; }
.ring-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 9; }
.ring-fg {
  fill: none; stroke: var(--accent); stroke-width: 9; stroke-linecap: round;
  stroke-dasharray: 326.7; stroke-dashoffset: 0; transition: stroke-dashoffset .2s linear;
}
.ring-text {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 800;
}
.set-line { text-align: center; color: var(--muted); font-size: 0.88rem; }

.feedback-log {
  list-style: none; display: flex; flex-direction: column; gap: 6px;
  min-height: 70px; max-height: 130px; overflow-y: auto;
}
.feedback-log li {
  font-size: 0.8rem; color: var(--warn); background: rgba(251, 146, 60, .08);
  border-left: 3px solid var(--warn); border-radius: 6px; padding: 6px 10px;
}
.feedback-log li.praise { color: var(--accent); background: rgba(163, 230, 53, .08); border-left-color: var(--accent); }

.controls { display: flex; gap: 10px; }
.ctl-btn {
  flex: 1; background: var(--card-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 11px 0; font-size: 0.9rem;
}
.ctl-btn:hover { border-color: var(--muted); }

/* ───────── 완료 ───────── */
#screen-complete { display: none; align-items: center; justify-content: center; padding: 30px 16px; }
#screen-complete.active { display: flex; }
.complete-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 22px;
  padding: 40px 34px; width: min(520px, 100%); text-align: center;
}
.complete-emoji { font-size: 3.4rem; }
.complete-card h2 { margin-top: 10px; font-size: 1.6rem; }
.c-exname { color: var(--muted); margin-top: 4px; }
.stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px;
}
.stat {
  background: var(--card-2); border-radius: 14px; padding: 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.stat-label { color: var(--muted); font-size: 0.76rem; }
.stat b { font-size: 1.25rem; color: var(--accent); }
.c-msg { margin-top: 18px; color: var(--text); font-size: 0.95rem; }
.complete-actions { display: flex; gap: 10px; margin-top: 24px; }
.primary-btn {
  flex: 1; background: var(--accent); color: var(--bg); font-weight: 700;
  border: none; border-radius: 12px; padding: 13px 0; font-size: 0.95rem;
}
.primary-btn:hover { filter: brightness(1.1); }
.complete-actions .ctl-btn { flex: 1; }

/* ───────── 반응형 ───────── */
@media (max-width: 900px) {
  .session-body { grid-template-columns: 1fr; }
  .phasebar { display: none; }
}
