:root {
  --bg: #14161a;
  --bg2: #1c1f25;
  --line: #2c3038;
  --fg: #f2efe8;
  --muted: #8b909a;
  --accent: #ffb547;
  --accent-ink: #231a08;
  --warn: #ff6b5a;
  --ok: #6fd3a0;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body { height: 100dvh; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  display: flex; flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: .6em 1.1em; cursor: pointer; transition: background .15s, border-color .15s, transform .05s;
}
button:hover { border-color: #4a505c; background: #242831; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .35; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
button.primary:hover { background: #ffc46b; }
button.ghost { background: transparent; }
button.icon { padding: .45em .8em; font-size: .9rem; background: transparent; }
input[type=text], input:not([type]), input[type=number] {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .5em .6em; min-width: 0;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
kbd { font-family: inherit; font-size: .8em; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 .35em; }

.topbar { display: flex; align-items: center; gap: .4rem; padding: .45rem .7rem; flex: none; }
#helpBtn { cursor: help; }
.spacer { flex: 1; }
.banner { background: #2b2414; color: var(--accent); border: 1px solid #5a4620; border-radius: 8px; padding: .35em .8em; font-size: .9rem; }

.layout { flex: 1; display: flex; min-height: 0; }
.stage {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: .5rem 1rem 1rem; min-width: 0; min-height: 0; overflow: hidden;
}
.bundle-title { color: var(--muted); font-size: .95rem; letter-spacing: .02em; }
.bundle-title:empty { display: none; }
.step-name { font-size: clamp(1.3rem, min(4vw, 5vh), 2.6rem); font-weight: 700; margin-top: .2rem; text-align: center; word-break: keep-all; }
.clock {
  font-size: clamp(3.5rem, min(20vw, 32vh), 20rem); font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
  margin: .08em 0 .12em; cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: color .2s;
}
.clock.paused { color: #cfcabe; }
.clock.typing { color: var(--accent) !important; }
.clock.typing .dim { color: #4a4f59; }
.clock.typing .sep { color: var(--muted); }
.clock .f { border-radius: .06em; transition: background .15s; }
.clock .f:hover { color: #fff; }
.clock.editing { color: #cfcabe; }
.clock .f.on { color: var(--accent); }
.clock .caret {
  display: inline-block; width: 0; height: .74em; vertical-align: -.02em;
  border-right: .05em solid var(--accent); margin-right: -.05em; animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { border-color: transparent; } }
.key-in { position: fixed; left: -100px; top: 50%; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; font-size: 16px; }
.clock.idle { color: var(--muted); }
.clock.last { color: var(--warn); }
.progress { width: min(900px, 90%); height: 8px; background: var(--bg2); border-radius: 99px; overflow: hidden; }
#bar { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .25s linear; }
.clock.last ~ .progress #bar { background: var(--warn); }
.next-info { color: var(--muted); margin-top: .5rem; font-size: .95rem; }
.next-info:empty { display: none; }

.controls { display: flex; gap: .5rem; margin-top: clamp(.6rem, 2.5vh, 1.4rem); flex-wrap: wrap; justify-content: center; }
.controls button { font-size: 1.05rem; padding: .6em 1.2em; }
.controls #startBtn { min-width: 7em; }
.quick { display: flex; gap: .4rem; margin-top: clamp(.4rem, 1.5vh, .8rem); flex-wrap: wrap; justify-content: center; }
.quick button { font-size: 1rem; font-weight: 600; min-width: 4.6em; padding: .5em .8em; }
.quick button.sm { font-weight: 500; min-width: 0; color: #c9c5bb; background: transparent; }

.chips { list-style: none; padding: 0; margin: clamp(.5rem, 2vh, 1.2rem) 0 0; display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; max-width: 900px; }
.chips li {
  border: 1px solid var(--line); border-radius: 99px; padding: .3em .8em; cursor: pointer; font-size: .9rem;
  background: var(--bg2);
}
.chips li .t { color: var(--muted); margin-left: .4em; font-variant-numeric: tabular-nums; }
.chips li.done { opacity: .45; text-decoration: line-through; }
.chips li.cur { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.chips li.cur .t { color: var(--accent-ink); }

.panel {
  width: 340px; flex: none; border-left: 1px solid var(--line); background: #17191e;
  padding: .6rem .9rem 1rem; overflow-y: auto; min-height: 0;
}
body.no-panel .panel { display: none; }
.panel h2 { margin: 0 0 .5rem; font-size: 1.05rem; }
.panel h3 { margin: 1rem 0 .4rem; font-size: .92rem; color: #d8d4ca; }
.panel button { padding: .45em .8em; }
.sound { margin-top: 1rem; }
.sound .lbl { flex: none; color: var(--muted); font-size: .9rem; }
.muted { color: var(--muted); font-size: .85rem; margin: 0 0 .8rem; line-height: 1.5; }
.wide { width: 100%; }
.row { display: flex; gap: .4rem; margin-top: .5rem; align-items: center; }
.row > * { flex: 1; }
.check { display: flex; gap: .5rem; align-items: center; margin-top: .5rem; font-size: .92rem; cursor: pointer; }
.check input { width: 1.1em; height: 1.1em; accent-color: var(--accent); }

.steps { list-style: none; padding: 0; margin: .5rem 0; display: flex; flex-direction: column; gap: .3rem; }
.steps li { display: grid; grid-template-columns: 1.4em 1fr 3.4em auto 3.2em auto auto; gap: .3rem; align-items: center; font-size: .9rem; }
.steps .no { color: var(--muted); text-align: right; }
.steps input[type=number] { text-align: right; padding: .45em .3em; }
.steps .u { color: var(--muted); font-size: .8rem; }
.steps .tools { display: flex; gap: 2px; }
.steps .tools button { padding: .25em .45em; font-size: .8rem; background: transparent; border-color: transparent; }
.steps .tools button:hover { border-color: var(--line); }
.steps li.cur .no { color: var(--accent); font-weight: 700; }

.saved { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .4rem; }
.saved li { display: flex; gap: .4rem; align-items: center; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: .4rem .4rem .4rem .8rem; }
.saved .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved .sm { color: var(--muted); font-size: .78rem; display: block; }
.saved button { padding: .35em .7em; font-size: .85rem; }
.saved .empty { color: var(--muted); font-size: .85rem; background: none; border: none; padding: 0; }
input[type=range] { accent-color: var(--accent); }

.overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(20, 22, 26, .55); cursor: pointer; z-index: 10;
}
.overlay[hidden] { display: none; }
.overlay-box { background: var(--accent); color: var(--accent-ink); border-radius: 22px; padding: 2rem 3rem; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.ov-title { font-size: clamp(2rem, 6vw, 4.5rem); font-weight: 800; }
.ov-sub { font-size: clamp(1.1rem, 2.6vw, 1.8rem); margin-top: .4rem; font-weight: 600; }
.ov-hint { font-size: .85rem; margin-top: 1rem; opacity: .7; }
body.ringing { animation: flash .6s steps(2) infinite; }
@keyframes flash { 0% { background: var(--bg); } 50% { background: #3a2a10; } }

/* 전체화면: 시계만 크게 */
body.fs .panel, body.fs #helpBtn { display: none; }
body.fs .clock { font-size: clamp(4rem, min(25vw, 42vh), 30rem); }
body.fs .topbar { position: fixed; top: 0; right: 0; left: 0; z-index: 5; pointer-events: none; }
body.fs .topbar > * { pointer-events: auto; }
body.fs #panelBtn { display: none; }
body.fs #fsBtn { opacity: .55; transition: opacity .2s; }
body.fs #fsBtn:hover { opacity: 1; }

/* 좁은 화면: 묶음 패널은 화면 위에 덮는 서랍 (페이지는 스크롤 없음) */
@media (max-width: 860px) {
  .panel { position: fixed; top: 2.8rem; right: 0; bottom: 0; width: min(360px, 100%); z-index: 6; box-shadow: -10px 0 30px rgba(0,0,0,.5); }
}

/* 소리 설정 */
.snd { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; margin-top: .5rem; }
.snd.off .snd-name, .snd.off .snd-btns { opacity: .4; }
.snd-head { display: flex; align-items: center; justify-content: space-between; font-size: .92rem; }
.snd-name { color: var(--muted); font-size: .8rem; margin: .25rem 0 .45rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snd-btns { display: flex; gap: .3rem; flex-wrap: wrap; }
.snd-btns button, .snd-btns .btn { padding: .3em .65em; font-size: .82rem; }
.btn {
  display: inline-block; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: #4a505c; background: #242831; }
.toggle { position: relative; display: inline-block; width: 2.6em; height: 1.45em; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle span { position: absolute; inset: 0; background: #3a3f49; border-radius: 99px; transition: background .2s; }
.toggle span::after {
  content: ''; position: absolute; left: .18em; top: .18em; width: 1.09em; height: 1.09em; border-radius: 50%;
  background: #f2efe8; transition: transform .2s;
}
.toggle input:checked + span { background: var(--accent); }
.toggle input:checked + span::after { transform: translateX(1.15em); }
.toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.modal { position: fixed; inset: 0; z-index: 20; background: rgba(10, 11, 14, .7); display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal[hidden] { display: none; }
.modal-box { width: min(680px, 100%); background: #1b1e24; border: 1px solid var(--line); border-radius: 16px; padding: 1.1rem 1.2rem; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-box h3 { margin: 0 0 .3rem; }
.modal-box .muted { margin: 0 0 .5rem; }
.muted.small { font-size: .78rem; margin-top: .4rem; }
#smWave { display: block; width: 100%; height: 120px; background: #121418; border-radius: 10px; cursor: ew-resize; touch-action: none; }
.sm-row { display: flex; align-items: center; gap: .6rem; margin-top: .7rem; flex-wrap: wrap; }
.sm-row label { display: flex; align-items: center; gap: .3rem; font-size: .9rem; }
.sm-row input[type=number] { width: 6em; }
.sm-row input[type=range] { flex: 1; min-width: 8rem; }
.sm-row .spacer { flex: 1; }
#smGainV { min-width: 3.5em; text-align: right; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; left: 50%; bottom: 2rem; transform: translateX(-50%); z-index: 15;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 1.2rem;
  padding: .6em 1.2em; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast[hidden] { display: none; }
