:root {
  --bg: #0f1115;
  --bg2: #171a21;
  --bg3: #21252e;
  --fg: #f2f3f5;
  --fg2: #9aa1ad;
  --line: #2b303b;
  --accent: #c8ff3b;
  --accent-ink: #0f1115;
  --danger: #ff5d5d;
  --warn: #ffb648;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  font-size: 16px;
  line-height: 1.35;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-text-size-adjust: 100%;
}
body { touch-action: manipulation; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:active { transform: scale(0.98); }

.num, .remain, .rounds, .count-num, .ov-time, .stat b, .result-rounds, .cur-set span {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* ===== 화면 공통 ===== */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
  padding: calc(var(--sat) + 16px) calc(var(--sar) + 20px) calc(var(--sab) + 16px) calc(var(--sal) + 20px);
  gap: 16px;
}
.screen.active { display: flex; }

.label {
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--fg2);
  font-weight: 600;
}
.sub { margin: 0; color: var(--fg2); font-size: 14px; }

/* ===== 준비 화면 ===== */
.ready-head h1 {
  margin: 8px 0 4px;
  font-size: 44px;
  letter-spacing: .08em;
  font-weight: 900;
  color: var(--accent);
}

.settings {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.setting-row { display: flex; flex-direction: column; gap: 8px; }

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--bg3);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.seg button {
  padding: 10px 0;
  border-radius: 9px;
  font-weight: 600;
  color: var(--fg2);
}
.seg button.on { background: var(--accent); color: var(--accent-ink); }

.toggles { flex-direction: row; gap: 8px; }
.toggle {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 8px;
  border-radius: 12px;
  background: var(--bg3);
  border: 1px solid transparent;
  font-weight: 600;
  color: var(--fg2);
  font-size: 14px;
}
.toggle[aria-pressed="true"] { color: var(--fg); border-color: var(--accent); }

.btn-huge {
  width: 100%;
  padding: 22px;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 26px;
  font-weight: 900;
  letter-spacing: .1em;
}

.history { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.history-head { display: flex; justify-content: space-between; align-items: center; }
.link { color: var(--fg2); font-size: 13px; text-decoration: underline; }
#history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
#history-list li {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 14px;
}
#history-list .d { color: var(--fg2); }
#history-list .r { font-weight: 800; font-size: 18px; }
#history-list .r small { font-size: 12px; font-weight: 500; color: var(--fg2); margin-left: 2px; }
#history-list .p { font-size: 12px; color: var(--fg2); }
#history-list .x { color: var(--fg2); padding: 4px 6px; font-size: 16px; }
.empty { margin: 0; color: var(--fg2); font-size: 14px; text-align: center; padding: 16px 0; }

/* ===== 카운트다운 ===== */
#screen-countdown { justify-content: center; align-items: center; }
.count-num {
  font-size: 40vh;
  line-height: 1;
  font-weight: 900;
  color: var(--accent);
}

/* ===== 운동 화면 ===== */
#screen-workout { position: relative; gap: 0; }

.top { display: flex; flex-direction: column; gap: 10px; }
.remain-wrap { display: flex; align-items: baseline; justify-content: space-between; }
.remain { font-size: 40px; font-weight: 800; line-height: 1; }
.remain.warn { color: var(--warn); }
.remain.crit { color: var(--danger); }
.progress { height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden; }
.bar { height: 100%; width: 0%; background: var(--accent); transition: width .25s linear; }

.mid {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 120px;
}
.rounds {
  font-size: min(34vh, 160px);
  line-height: 1;
  font-weight: 900;
}
.cur-set { color: var(--fg2); font-size: 15px; }
.cur-set span { color: var(--fg); font-weight: 700; }

.btn-set {
  width: 100%;
  min-height: 34vh;
  border-radius: 24px;
  background: var(--accent);
  color: var(--accent-ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 14px;
  box-shadow: 0 0 0 0 rgba(200,255,59,.6);
}
.btn-set .big { font-size: 34px; font-weight: 900; letter-spacing: .04em; }
.btn-set .small { font-size: 13px; font-weight: 600; opacity: .7; }
.btn-set.hit { animation: hit .3s ease-out; }
@keyframes hit {
  0%   { background: #fff; box-shadow: 0 0 0 0 rgba(200,255,59,.7); }
  100% { background: var(--accent); box-shadow: 0 0 0 24px rgba(200,255,59,0); }
}

.bottom { display: grid; grid-template-columns: 1fr 1.4fr .8fr 1fr; gap: 8px; }
.ctl {
  padding: 14px 6px;
  border-radius: 14px;
  background: var(--bg2);
  border: 1px solid var(--line);
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}
.ctl.primary { background: var(--bg3); }
.ctl.danger { color: var(--danger); }
.ctl:disabled { opacity: .35; }

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(15,17,21,.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  z-index: 10;
  text-align: center;
}
.overlay[hidden] { display: none; }
.ov-title { font-size: 26px; font-weight: 800; }
.ov-time { font-size: 56px; font-weight: 800; color: var(--fg2); }
.ov-actions { display: flex; gap: 10px; width: 100%; max-width: 360px; }
.ov-actions .ctl { flex: 1; padding: 16px; }

.flash {
  position: absolute; inset: 0;
  background: var(--accent);
  opacity: 0;
  pointer-events: none;
  z-index: 20;
}
.flash.on { animation: flash .5s ease-out; }
@keyframes flash { 0% { opacity: .55; } 100% { opacity: 0; } }

/* ===== 결과 화면 ===== */
#screen-result { gap: 18px; }
.result-head { text-align: center; padding-top: 8px; }
.result-rounds { font-size: 96px; font-weight: 900; line-height: 1; color: var(--accent); }
.result-rounds small { font-size: 22px; color: var(--fg); margin-left: 8px; font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}
.stat b { font-size: 22px; }

.chart-wrap { display: flex; flex-direction: column; gap: 8px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; }
.chart-avg { font-size: 13px; color: var(--fg2); }
#chart { width: 100%; height: auto; aspect-ratio: 2 / 1; display: block; }
#chart .bar-r { fill: var(--accent); }
#chart .bar-r.slow { fill: var(--warn); }
#chart .bar-r.partial { fill: var(--fg2); opacity: .5; }
#chart .avg { stroke: var(--fg2); stroke-width: 1; stroke-dasharray: 4 4; }
#chart text { fill: var(--fg2); font-size: 10px; font-family: inherit; }
#chart text.val { fill: var(--fg); font-weight: 700; }

.rpe { display: flex; flex-direction: column; gap: 10px; }
.rpe-head { display: flex; justify-content: space-between; align-items: baseline; }
.rpe-desc { font-size: 13px; color: var(--fg2); }
.rpe-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.rpe-grid button {
  padding: 14px 0;
  border-radius: 12px;
  background: var(--bg2);
  border: 1px solid var(--line);
  font-weight: 800;
  font-size: 18px;
  color: var(--fg2);
}
.rpe-grid button.on { color: var(--accent-ink); border-color: transparent; }

.result-actions { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.result-actions .ctl { padding: 14px; }

@media (max-height: 640px) {
  .rounds { font-size: 28vh; }
  .btn-set { min-height: 30vh; }
  .btn-set .big { font-size: 28px; }
}

/* ===== 공개판 추가: 하단 안내 · 피드백 ===== */
.app-foot {
  margin-top: auto;
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}
.feedback-btn {
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--fg);
  font-weight: 600;
  font-size: 14px;
  width: 100%;
}
.privacy, .ver { margin: 0; font-size: 12px; color: var(--fg2); }
.ver { opacity: .6; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15,17,21,.85);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px calc(var(--sar) + 16px) calc(var(--sab) + 16px) calc(var(--sal) + 16px);
}
.modal[hidden] { display: none; }
.sheet {
  width: 100%;
  max-width: 440px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sheet .ov-title { font-size: 22px; }
.fb-info {
  background: var(--bg3);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.fb-info ul { margin: 0; padding-left: 18px; font-size: 13px; color: var(--fg); -webkit-user-select: text; user-select: text; }
.fb-info li { word-break: break-all; }
.fb-note { margin: 0; font-size: 12px; color: var(--fg2); }
.fb-consent { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; font-weight: 600; cursor: pointer; }
.fb-consent input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.fb-consent small { display: block; font-size: 12px; font-weight: 400; color: var(--fg2); margin-top: 2px; }
.fb-info ul.off { opacity: .35; text-decoration: line-through; }
.fb-warn { margin: 0; font-size: 13px; color: var(--warn); }
.fb-go { text-align: center; text-decoration: none; color: var(--accent-ink); background: var(--accent) !important; border-color: transparent; }
.fb-go[aria-disabled="true"] { opacity: .35; pointer-events: none; }
.ov-actions .ctl { max-width: none; }

/* ===== 앱 내부 브라우저 안내 배너 ===== */
.inapp {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--warn);
  color: var(--accent-ink);
  padding: calc(var(--sat) + 10px) 16px 10px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.inapp[hidden] { display: none; }
.inapp p { margin: 0; }
.inapp-actions { display: flex; gap: 8px; justify-content: flex-end; }
.inapp-open, .inapp-close {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-ink);
  text-decoration: none;
  border: 1px solid rgba(15,17,21,.35);
}
.inapp-open { background: var(--accent-ink); color: var(--warn); }
.inapp:not([hidden]) ~ .screen { padding-top: 16px; }
