@font-face {
  font-family: "Bebas Neue";
  src: url("../fonts/bebas-neue.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

:root {
  --bg: #262626;
  --bg-2: #1f1f1f;
  --line: #3a3a3a;
  --text: #ffffff;
  --muted: #5c5c5c;
  --ink: #0a0a0a;

  --yellow: #fcff45;
  --green: #9dff46;
  --red: #ff5a4e;
  --blue: #3fb1ea;
  --purple: #b98cff;
  --accent: #9dff46;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tabbar-h: 64px;
}

html.pale {
  --yellow: #f2f3a6;
  --green: #c8efa3;
  --red: #f1aaa4;
  --blue: #a9d5ec;
  --purple: #d5c2f5;
  --accent: #c8efa3;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Bebas Neue", "Oswald", "Impact", "Arial Narrow", sans-serif;
  letter-spacing: 0.01em;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  text-transform: uppercase;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-transform: inherit;
  letter-spacing: inherit;
}

svg { display: block; }

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

#views {
  position: relative;
  flex: 1;
  min-height: 0;
}

.view {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}
.view.active { display: flex; }

/* ---------- Tab bar ---------- */
.tabbar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  gap: 6px;
  background: var(--bg-2);
  padding: 8px calc(10px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(10px + var(--safe-left));
}
.tab {
  flex: 1;
  max-width: 130px;
  height: var(--tabbar-h);
  border-radius: 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 14px;
  color: #e9e9e9;
  transition: background 0.2s;
}
.tab svg { width: 28px; height: 28px; }
.tab.active { background: #3d3d3d; color: #fff; }
.tab.active svg circle:first-child { fill: currentColor; }
.tab.active svg .hand { stroke: #3d3d3d; fill: #3d3d3d; }

/* ---------- Top bar ---------- */
.topbar {
  position: relative;
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: center;
  min-height: 92px;
  padding: 4px 8px;
  background: var(--bg);
  z-index: 2;
}
.topbar.simple { min-height: 70px; border-bottom: 1px solid var(--line); }
.topbar h1 {
  grid-column: 2;
  margin: 0;
  text-align: center;
  font-weight: 400;
  font-size: 30px;
}
.icon-btn {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: var(--yellow);
  justify-self: center;
}
.icon-btn svg { width: 32px; height: 32px; }
.title-block {
  text-align: center;
  color: var(--yellow);
  line-height: 1;
}
.title-block .title { font-size: 30px; }
.title-block .subtitle { font-size: 38px; margin-top: 4px; }

/* ---------- Interval stage ---------- */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.panel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  background: var(--yellow);
  overflow: hidden;
  transition: background-color 0.25s;
  width: 100%;
}
.panel.current { flex: 1; min-height: 0; padding-top: min(5vw, 3vh); }
.panel.next { flex: 0 0 auto; padding: 1.4vh 0 1.8vh; }
.panel[data-phase="prepare"] { background: var(--yellow); }
.panel[data-phase="work"] { background: var(--green); }
.panel[data-phase="rest"] { background: var(--red); }
.panel[data-phase="cyclerest"] { background: var(--blue); }
.panel[data-phase="done"] { background: var(--purple); }
.panel[data-phase="none"] { background: #3a3a3a; color: #9a9a9a; }

.phase-label {
  line-height: 1;
  white-space: nowrap;
}
.panel.current .phase-label { font-size: min(24vw, 11.5vh); }
.panel.next .phase-label { font-size: min(11vw, 4.6vh); margin-bottom: 0.3vh; }

.phase-time {
  line-height: 0.85;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.panel.current .phase-time {
  font-size: calc(min(46vw, 24vh) * var(--fit, 1));
  margin-top: 0.06em;
}
.panel.next .phase-time {
  font-size: calc(min(36vw, 10vh) * var(--fit, 1));
}
.panel .sub-info {
  position: absolute;
  top: 10px;
  left: 16px;
  text-align: left;
  font-size: min(6vw, 3vh);
  opacity: 0.6;
}

.progress {
  position: absolute;
  left: 0; bottom: 0;
  height: 6px;
  width: 100%;
  background: rgba(0, 0, 0, 0.12);
}
.progress > div {
  height: 100%;
  width: 0;
  background: rgba(0, 0, 0, 0.45);
}

.reset-btn {
  position: absolute;
  top: calc(-1 * min(9vw, 38px));
  right: 11%;
  width: min(18vw, 76px);
  height: min(18vw, 76px);
  border-radius: 50%;
  background: var(--bg);
  border: 4px solid var(--yellow);
  color: var(--yellow);
  display: grid;
  place-items: center;
  z-index: 3;
}
.reset-btn svg { width: 46%; height: 46%; }

.panel.current, .panel.next { cursor: pointer; }

/* ---------- Controls row ---------- */
.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  padding: 14px 10px 10px;
  background: var(--bg);
  min-height: min(25vh, 210px);
}
.stat { text-align: center; line-height: 1; }
.stat-value {
  font-size: min(24vw, 12vh);
  font-variant-numeric: tabular-nums;
}
.stat-value.blue { color: var(--blue); }
.stat-value.yellow { color: var(--yellow); }
.stat-value.white { color: #fff; }
.stat-value.time { font-size: min(13vw, 7.5vh); line-height: 1.6; }
.stat-label {
  font-size: min(7.6vw, 4.2vh);
  margin-top: 0.15em;
  white-space: nowrap;
}

.start-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 6px;
}
.start-btn {
  width: min(27vw, 15vh);
  height: min(27vw, 15vh);
  border-radius: 50%;
  background: var(--yellow);
  display: grid;
  place-items: center;
  position: relative;
  transition: transform 0.1s;
}
.start-btn::after {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  border: 3px solid var(--bg);
}
.start-btn:active { transform: scale(0.95); }
.start-btn svg { width: 38%; height: 38%; color: var(--bg); }
.start-label {
  color: var(--yellow);
  font-size: min(9vw, 4.6vh);
  line-height: 1;
}
.start-btn.secondary {
  width: min(20vw, 11vh);
  height: min(20vw, 11vh);
  background: #3d3d3d;
  color: #fff;
}
.start-btn.secondary::after { display: none; }
.start-btn.secondary svg { color: #fff; }

/* ---------- Landscape ---------- */
@media (orientation: landscape) and (max-height: 600px) {
  :root { --tabbar-h: 44px; }
  .tab { flex-direction: row; gap: 8px; }
  .tab svg { width: 22px; height: 22px; }
  .interval-view { display: none; }
  .interval-view.active {
    display: grid;
    grid-template-columns: 62% 38%;
    grid-template-rows: auto 1fr auto;
  }
  .interval-view .topbar { grid-column: 1 / 3; min-height: 54px; }
  .interval-view .title-block { display: flex; gap: 12px; justify-content: center; align-items: baseline; }
  .interval-view .title-block .title,
  .interval-view .title-block .subtitle { font-size: 26px; margin: 0; }
  .interval-view .stage { grid-column: 1 / 3; flex-direction: row; }
  .interval-view .panel.current { flex: 2.2; }
  .interval-view .panel.next { flex: 1; }
  .panel.current .phase-label { font-size: 13vh; }
  .panel.current .phase-time { font-size: calc(min(30vw, 42vh) * var(--fit, 1)); }
  .panel.next .phase-label { font-size: 8vh; }
  .panel.next .phase-time { font-size: calc(min(14vw, 20vh) * var(--fit, 1)); }
  .interval-view .controls { grid-column: 1 / 3; min-height: 0; padding: 6px 10px; }
  .stat { display: flex; align-items: baseline; gap: 10px; justify-content: center; }
  .stat-value { font-size: 12vh; }
  .stat-label { font-size: 6vh; }
  .start-wrap { flex-direction: row; }
  .start-btn { width: 16vh; height: 16vh; }
  .start-label { font-size: 6vh; }
  .reset-btn { top: -28px; width: 56px; height: 56px; }
}

/* ---------- Stopwatch ---------- */
.sw-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 8px 0;
  flex: 0 0 auto;
}
.sw-time {
  font-size: calc(min(30vw, 18vh) * var(--fit, 1));
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: #fff;
  white-space: nowrap;
}
.sw-time .cs { color: var(--yellow); }
.sw-lap-time {
  font-size: min(10vw, 5vh);
  color: #9a9a9a;
  font-variant-numeric: tabular-nums;
  min-height: 1.1em;
}
.sw-laps {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 10px 0 0;
  padding: 0 20px;
  list-style: none;
  border-top: 1px solid var(--line);
}
.sw-laps li {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 26px;
  font-variant-numeric: tabular-nums;
}
.sw-laps li span:nth-child(2) { text-align: center; }
.sw-laps li span:last-child { text-align: right; color: #9a9a9a; }
.sw-laps li.best span:nth-child(2) { color: var(--green); }
.sw-laps li.worst span:nth-child(2) { color: var(--red); }
.sw-empty { text-align: center; color: var(--muted); font-size: 24px; padding: 30px 0; border: 0 !important; display: block !important; }
.sw-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  justify-items: center;
  padding: 14px 10px 12px;
}

/* ---------- More ---------- */
.list {
  list-style: none;
  margin: 0;
  padding: 0 18px;
  overflow-y: auto;
  flex: 1;
}
.list li { border-bottom: 1px solid var(--line); }
.list-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 2px;
  font-size: 28px;
  text-align: left;
}
.list-item .ico {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #2f2f2f;
  display: grid;
  place-items: center;
  flex: 0 0 46px;
}
.list-item .ico svg { width: 26px; height: 26px; }
.list-item .label { flex: 1; }
.list-item .chev { color: #8a8a8a; width: 16px; height: 26px; }
.more-footer { text-align: center; color: var(--yellow); font-size: 22px; padding: 20px; }

/* ---------- Sheets ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  visibility: hidden;
}
.sheet.open { transform: translateY(0); visibility: visible; }
.sheet-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.sheet-header h2 { margin: 0; font-weight: 400; font-size: 30px; }
.done-btn { justify-self: end; color: var(--accent); font-size: 30px; }
.sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 20px calc(30px + var(--safe-bottom));
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 0;
  border-bottom: 1px solid var(--line);
  min-height: 92px;
}
.row-text { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.row-label { font-size: 30px; line-height: 1; }
.row-note { font-size: 19px; color: var(--muted); line-height: 1.1; }
.row-note a { color: var(--accent); }

.switch {
  position: relative;
  width: 68px;
  height: 36px;
  flex: 0 0 68px;
}
.switch input {
  position: absolute;
  opacity: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}
.switch .track {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  background: #4e4e4e;
  transition: background 0.2s;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 40px;
  height: 30px;
  border-radius: 16px;
  background: #2b2b2b;
  transition: transform 0.2s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(22px); }

.select-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font-size: 28px;
  max-width: 55%;
}
.select-wrap .value { text-align: right; line-height: 1.05; }
.select-wrap svg { width: 12px; height: 22px; color: #8a8a8a; flex: 0 0 12px; }
.select-wrap select {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  font-size: 16px;
}

.volume-row { gap: 14px; }
.volume-row svg { width: 30px; height: 30px; flex: 0 0 30px; }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 36px;
  background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: #5a5a5a; }
input[type="range"]::-moz-range-track { height: 2px; background: #5a5a5a; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 32px;
  height: 32px;
  margin-top: -15px;
  border-radius: 50%;
  background: var(--accent);
}
input[type="range"]::-moz-range-thumb {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
}

.version { text-align: center; color: var(--yellow); font-size: 22px; padding-top: 20px; }

/* Editor */
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #353535;
  font-size: 30px;
  line-height: 1;
  display: grid;
  place-items: center;
  color: var(--accent);
  touch-action: manipulation;
}
.stepper button:active { background: #4a4a4a; }
.stepper .val {
  min-width: 96px;
  text-align: center;
  font-size: 34px;
  font-variant-numeric: tabular-nums;
}
.editor-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin-right: 10px;
  vertical-align: 2px;
}
.presets { display: flex; flex-wrap: wrap; gap: 10px; padding: 18px 0 6px; }
.chip {
  padding: 10px 16px;
  border-radius: 22px;
  background: #353535;
  font-size: 22px;
}
.chip.active { background: var(--accent); color: var(--ink); }
.section-title { color: var(--muted); font-size: 20px; padding-top: 20px; }
.total-row { justify-content: center; font-size: 28px; color: var(--yellow); border-bottom: 0; }
.wide-btn {
  display: block;
  width: 100%;
  margin-top: 18px;
  padding: 16px;
  border-radius: 14px;
  background: #353535;
  font-size: 24px;
}

.info-body { font-family: -apple-system, system-ui, sans-serif; text-transform: none; font-size: 17px; line-height: 1.5; color: #ddd; -webkit-user-select: text; user-select: text; }
.info-body h3 { font-family: "Bebas Neue", sans-serif; text-transform: uppercase; font-weight: 400; font-size: 28px; color: #fff; margin: 24px 0 6px; letter-spacing: 0.02em; }
.info-body ol, .info-body ul { padding-left: 22px; }
.info-body li { margin: 6px 0; }
.info-body b { color: #fff; }

/* Flash & toast */
#flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 50;
}
#flash.on { animation: flash 0.6s ease-out; }
@keyframes flash {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(110px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #444;
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 22px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
