:root {
  --bg: #0e1116;
  --panel: #171c24;
  --panel-2: #1e242e;
  --text: #e8edf4;
  --muted: #8b95a5;
  --accent: #f97316;
  --danger: #ef4444;
  --radius: 14px;
  --phase: #f59e0b;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.brand {
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.topbar-actions button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--panel-2);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  font-size: 18px;
  cursor: pointer;
}

.topbar-actions button[aria-pressed="false"] {
  opacity: 0.4;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
}

.view[hidden] {
  display: none;
}

h2 {
  font-size: 1.1rem;
  margin: 24px 0 12px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field span {
  font-size: 0.9rem;
  color: var(--muted);
}

.field small {
  color: var(--muted);
  opacity: 0.8;
}

.field input,
.field textarea,
.field select {
  background: var(--panel);
  border: 1px solid var(--panel-2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 1.05rem;
  font-family: inherit;
  width: 100%;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field textarea {
  resize: vertical;
  min-height: 96px;
}

.btn {
  border: 1px solid var(--panel-2);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius);
  min-height: 52px;
  padding: 0 18px;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #14110d;
}

.btn-danger {
  background: transparent;
  border-color: color-mix(in srgb, var(--danger) 60%, transparent);
  color: var(--danger);
}

.btn-block {
  display: block;
  width: 100%;
  margin-top: 12px;
}

.btn-small {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.85rem;
}

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

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.history-item .date {
  font-weight: 700;
  font-size: 0.95rem;
}

.history-item .meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2px;
}

.history-item .delete {
  border: none;
  background: transparent;
  color: var(--danger);
  font-size: 1.2rem;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}

.history-item .replay {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 1.2rem;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}

.history-item .replay:hover,
.history-item .delete:hover {
  filter: brightness(1.3);
}

#view-timer {
  --phase: #f59e0b;
  text-align: center;
  padding-top: 12px;
}

#view-timer[data-phase="work"] {
  --phase: #22c55e;
}

#view-timer[data-phase="rest"] {
  --phase: #f97316;
}

#view-timer[data-phase="cycleRest"] {
  --phase: #a855f7;
}

#view-timer[data-phase="prep"] {
  --phase: #38bdf8;
}

#view-timer[data-phase="done"] {
  --phase: #a855f7;
}

#view-timer {
  user-select: none;
}

.phase-label {
  color: var(--phase);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 1rem;
}

.time {
  font-size: clamp(4.5rem, 26vw, 9rem);
  font-weight: 800;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  margin: 4px 0 8px;
}

.progress {
  height: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--phase);
  border-radius: 999px;
  transition: width 0.15s linear;
}

.total-time {
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  margin-top: 12px;
  text-align: center;
}

.progress-total {
  height: 6px;
  margin-top: 6px;
}

.progress-total .progress-fill {
  background: #60a5fa;
}

.exercise {
  margin-top: 16px;
  font-size: 1.35rem;
  font-weight: 700;
  min-height: 1.6em;
}

.round {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}

.cycle {
  color: var(--phase);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 10px;
  letter-spacing: 0.04em;
}

.cycle[hidden] {
  display: none;
}

.controls {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.controls .btn {
  flex: 1;
  min-height: 60px;
}

.summary-card {
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: var(--radius);
  padding: 8px 16px;
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--panel-2);
}

.summary-row:last-child {
  border-bottom: none;
}

.summary-row span {
  color: var(--muted);
}

.summary-row strong {
  font-variant-numeric: tabular-nums;
}

.credits {
  margin-top: 32px;
  text-align: center;
}

.credits summary {
  color: var(--muted);
  opacity: 0.5;
  font-size: 0.75rem;
  cursor: pointer;
  list-style: none;
}

.credits summary::-webkit-details-marker {
  display: none;
}

.credits[open] summary {
  margin-bottom: 8px;
}

.credits p {
  color: var(--muted);
  opacity: 0.55;
  font-size: 0.72rem;
  line-height: 1.5;
  margin: 8px 0 0;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

.credits a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.update-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.update-banner[hidden] {
  display: none;
}

.update-text {
  flex: 1;
  font-size: 0.95rem;
}

.update-dismiss {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
}

@media (max-width: 360px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .topbar {
    padding-top: 8px;
  }

  .time {
    font-size: clamp(3rem, 18vh, 6rem);
  }

  .exercise {
    margin-top: 8px;
  }

  .controls {
    margin-top: 12px;
  }
}
