:root {
  --bg: #05070d;
  --bg-soft: #0d1220;
  --panel: #121a2b;
  --panel-soft: #1a2338;
  --ink: #f3f6ff;
  --muted: #9da6bb;
  --border: rgba(255, 255, 255, 0.13);
  --accent: #ff6a3d;
  --accent-alt: #3b82f6;
  --work: #15b86a;
  --rest: #f0a817;
  --done: #717c91;
  --radius: 18px;
  --shadow-1: 0 10px 24px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Barlow", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 100% -10%, rgba(59, 130, 246, 0.25), transparent 40%),
    radial-gradient(circle at -10% 110%, rgba(255, 106, 61, 0.22), transparent 38%),
    var(--bg);
}

body.menu-open {
  overflow: hidden;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: "Space Grotesk", "Barlow", sans-serif;
  letter-spacing: 0.01em;
}

p {
  margin: 0;
}

.hidden {
  display: none !important;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  background: rgba(7, 11, 20, 0.78);
}

.brand h1 {
  font-size: 1.08rem;
  line-height: 1;
}

.brand p {
  margin-top: 0.14rem;
  font-size: 0.76rem;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 0.45rem;
}

.container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0.75rem 0.72rem 1rem;
}

.container.compact {
  min-height: calc(100dvh - 54px);
}

.stage {
  display: grid;
  gap: 0.65rem;
}

.panel {
  border-radius: var(--radius);
  padding: 0.8rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0)), var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-1);
}

.panel.soft {
  background: var(--panel-soft);
}

.stack {
  display: grid;
  gap: 0.7rem;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.45rem;
}

.row-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.inline-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.86rem;
  font-weight: 700;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  padding: 0.62rem 0.66rem;
}

textarea {
  resize: vertical;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 0.72rem 0.92rem;
  font-weight: 800;
  color: white;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
}

.btn-dark {
  background: #0d1422;
}

.btn-alt {
  background: var(--accent-alt);
}

.btn-light {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border);
}

.btn.wide {
  width: 100%;
}

.type-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.42rem;
}

.workout-type-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  padding: 0.62rem;
  text-align: left;
  display: grid;
  gap: 0.14rem;
  cursor: pointer;
}

.workout-type-card.active {
  border-color: rgba(255, 106, 61, 0.8);
  background: rgba(255, 106, 61, 0.16);
}

.card-label {
  font-size: 0.88rem;
  font-weight: 800;
}

.card-hint {
  font-size: 0.72rem;
  color: var(--muted);
}

.timer-display {
  border-radius: 20px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(17, 25, 42, 0.8), rgba(10, 14, 23, 0.92));
  padding: 0.82rem;
}

.timer-display.work {
  background: linear-gradient(180deg, rgba(21, 184, 106, 0.22), rgba(11, 18, 20, 0.95));
}

.timer-display.rest {
  background: linear-gradient(180deg, rgba(240, 168, 23, 0.24), rgba(20, 16, 8, 0.95));
}

.timer-display.done {
  background: linear-gradient(180deg, rgba(113, 124, 145, 0.22), rgba(10, 14, 23, 0.95));
}

.timer-header-row,
.timer-meta-row,
.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.45rem;
}

.timer-round-row {
  margin-top: 0.35rem;
}

.round-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border-radius: 999px;
  padding: 0.26rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.round-pill {
  background: rgba(255, 255, 255, 0.12);
}

.status-pill {
  background: rgba(0, 0, 0, 0.26);
}

.clock-wrapper {
  margin-top: 0.52rem;
  border-radius: 16px;
  padding: 0.64rem;
  text-align: center;
  background: rgba(0, 0, 0, 0.5);
}

.clock-label {
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.clock-value {
  margin-top: 0.15rem;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: clamp(3.1rem, 17vw, 5.2rem);
  line-height: 0.96;
  font-weight: 900;
}

.timer-task {
  margin-top: 0.6rem;
  border-radius: 14px;
  padding: 0.7rem;
  background: rgba(255, 255, 255, 0.12);
  font-size: clamp(1.1rem, 4.8vw, 1.65rem);
  font-weight: 800;
  line-height: 1.24;
}

.timer-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.timer-controls .btn {
  min-height: 52px;
  font-size: 0.98rem;
}

.timer-controls .hint {
  display: none;
}

.muted {
  color: var(--muted);
  font-size: 0.8rem;
}

.error {
  color: #ff8f8f;
  min-height: 1.1rem;
  font-size: 0.8rem;
}

.stats-grid {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem 0.6rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  padding: 0.64rem;
}

.stats-grid dt {
  color: var(--muted);
}

.stats-grid dd {
  margin: 0;
  font-weight: 700;
}

.raw-text-box,
.favorite-card,
.history-card,
.coach-lane {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.62rem;
}

.raw-title {
  font-weight: 800;
}

.raw-text-box pre {
  margin: 0.2rem 0 0;
  white-space: pre-wrap;
  font-size: 0.8rem;
  color: var(--muted);
}

.notes-list,
.laps-list {
  margin: 0;
  padding-left: 1.1rem;
}

.favorite-meta,
.history-meta {
  color: var(--muted);
  font-size: 0.74rem;
}

.favorite-actions,
.lane-actions,
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.34rem;
}

.favorite-actions button,
.lane-actions button,
.chip {
  border: none;
  border-radius: 9px;
  padding: 0.34rem 0.56rem;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  color: white;
  background: #111a2a;
}

.favorite-dup {
  background: var(--accent-alt);
}

.favorite-del {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--border);
}

.editor-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
}

.editor-grid.two-cols {
  grid-template-columns: 1fr;
}

.coach-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
}

.lane-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.42rem;
}

.lane-metric {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.42rem;
  background: rgba(0, 0, 0, 0.2);
}

.lane-metric p {
  font-size: 0.72rem;
  color: var(--muted);
}

.lane-metric strong {
  font-size: 1.14rem;
}

.history-note-wrap {
  display: grid;
  gap: 0.35rem;
}

.menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 34;
  background: rgba(0, 0, 0, 0.56);
}

.side-menu {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: 11%;
  z-index: 35;
  overflow-y: auto;
  padding: 0.72rem;
  display: grid;
  gap: 0.62rem;
  border-radius: 22px 22px 0 0;
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(14, 20, 34, 0.98), rgba(8, 12, 21, 0.98));
}

.menu-head {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0.1rem 0.2rem;
  background: transparent;
}

.fullscreen-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  padding: 0.7rem;
}

.fullscreen-inner {
  display: grid;
  gap: 0.6rem;
}

.fullscreen-top {
  display: flex;
  justify-content: flex-end;
}

body[data-theme="light"] {
  --bg: #f2f5fb;
  --bg-soft: #e9edf6;
  --panel: #ffffff;
  --panel-soft: #eef2f8;
  --ink: #0f172a;
  --muted: #5f687b;
  --border: rgba(15, 23, 42, 0.14);
  --work: #14944d;
  --rest: #d79013;
  --done: #6b7280;
}

body[data-theme="light"] .topbar {
  background: rgba(242, 245, 251, 0.88);
}

body[data-theme="light"] .timer-display {
  background: linear-gradient(180deg, rgba(238, 243, 252, 0.92), rgba(250, 252, 255, 0.94));
}

body[data-theme="light"] .clock-wrapper {
  background: #0f172a;
  color: #fff;
}

body[data-theme="light"] .timer-task {
  background: rgba(15, 23, 42, 0.06);
}

body[data-theme="light"] .side-menu {
  background: linear-gradient(180deg, rgba(245, 248, 255, 0.98), rgba(237, 242, 251, 0.98));
}

body[data-theme="high_contrast"] {
  --bg: #000;
  --panel: #000;
  --panel-soft: #0b0b0b;
  --ink: #fff;
  --muted: #e5e5e5;
  --border: rgba(255, 255, 255, 0.95);
  --accent: #ffea00;
  --accent-alt: #00fff0;
  --work: #00ff7f;
  --rest: #ffe600;
  --done: #9ca3af;
}

body[data-theme="high_contrast"] .btn,
body[data-theme="high_contrast"] .chip,
body[data-theme="high_contrast"] .favorite-actions button,
body[data-theme="high_contrast"] .lane-actions button {
  border: 2px solid #fff;
}

body[data-theme="high_contrast"] .btn-dark,
body[data-theme="high_contrast"] .chip,
body[data-theme="high_contrast"] .favorite-load,
body[data-theme="high_contrast"] .lane-actions button {
  color: #000;
  background: #fff;
}

@media (min-width: 768px) {
  .container {
    max-width: 560px;
  }

  .timer-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .editor-grid.two-cols {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .type-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .side-menu {
    left: auto;
    right: 0;
    top: 0;
    bottom: 0;
    width: min(94vw, 540px);
    border-radius: 0;
    border-left: 1px solid var(--border);
    border-top: none;
  }
}
