*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  color-scheme: dark;
  --bg: #0d0e12;
  --surface: #13151c;
  --surface2: #1a1d27;
  --border: #252836;
  --text: #e8e9f0;
  --muted: #72778b;
  --accent: #f4a14a;
  --accent2: #e06030;
  --green: #4ade80;
  --red: #f87171;
  --blue: #60a5fa;
  --glow-warm: rgba(244, 161, 74, 0.06);
  --glow-cool: rgba(96, 165, 250, 0.04);
  --marker: rgba(255, 255, 255, 0.5);
  --marker-strong: rgba(255, 255, 255, 0.9);
  --toast-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 20px rgba(244, 161, 74, 0.1);
}

body[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface2: #edf1f5;
  --border: #d7dde5;
  --text: #17202a;
  --muted: #677283;
  --accent: #d97706;
  --accent2: #c2410c;
  --green: #15803d;
  --red: #dc2626;
  --blue: #2563eb;
  --glow-warm: rgba(217, 119, 6, 0.1);
  --glow-cool: rgba(37, 99, 235, 0.08);
  --marker: rgba(23, 32, 42, 0.28);
  --marker-strong: rgba(23, 32, 42, 0.72);
  --toast-shadow: 0 12px 30px rgba(23, 32, 42, 0.12);
}

body {
  min-height: 100vh;
  padding: 40px 20px;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "DM Mono", monospace;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  background:
    radial-gradient(ellipse 60% 40% at 20% 10%, var(--glow-warm) 0%, transparent 60%),
    radial-gradient(ellipse 40% 50% at 80% 90%, var(--glow-cool) 0%, transparent 60%);
  pointer-events: none;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 24px;
  align-items: start;
  width: 100%;
  max-width: 1060px;
  margin: 0 auto;
}

.timer-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 38px;
  margin-bottom: 4px;
}

.title-group {
  display: inline-flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.header h1 {
  color: var(--text);
  font-family: "Syne", sans-serif;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0;
}

.gauge-wrapper,
.config-panel {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
}

.gauge-wrapper {
  padding: 28px;
  overflow: hidden;
}

.gauge-wrapper::before,
.config-panel::before {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 1px;
  content: "";
  border-radius: 20px 20px 0 0;
}

.gauge-wrapper::before {
  background: linear-gradient(90deg, transparent, rgba(244, 161, 74, 0.3), transparent);
}

.config-panel::before {
  background: linear-gradient(90deg, transparent, rgba(96, 165, 250, 0.2), transparent);
}

.timer-display {
  padding: 24px 0 16px;
  text-align: center;
}

.timer-big {
  color: var(--accent);
  font-family: "Syne", sans-serif;
  font-size: 72px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
  text-shadow: 0 0 40px rgba(244, 161, 74, 0.3);
  transition: color 0.5s;
}

.timer-big.done {
  color: var(--green);
  text-shadow: 0 0 40px rgba(74, 222, 128, 0.3);
}

.timer-remaining {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 1px;
}

.next-milestone {
  min-height: 18px;
  margin-top: 12px;
  color: var(--blue);
  font-size: 12px;
  opacity: 0.85;
  transition: opacity 0.3s;
}

.progress-bar-wrap {
  height: 4px;
  margin-top: 4px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--surface2);
}

.gauge-progress {
  margin-bottom: 20px;
}

.progress-bar-fill {
  width: 0%;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  box-shadow: 0 0 8px rgba(244, 161, 74, 0.5);
  transition: width 0.25s linear;
}

.gauge-container {
  display: flex;
  align-items: stretch;
  gap: 20px;
}

.gauge-bar-area {
  position: relative;
  width: 56px;
  flex-shrink: 0;
}

.gauge-track {
  position: relative;
  width: 100%;
  height: 420px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
}

.gauge-fill {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 0%;
  border-radius: 0;
  background: linear-gradient(to top, var(--accent2), var(--accent), #fde68a);
  box-shadow: 0 0 30px rgba(244, 161, 74, 0.4);
  transition: height 0.25s linear;
}

.gauge-fill::after {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 8px;
  content: "";
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.25);
  filter: blur(2px);
}

.milestone-marker {
  position: absolute;
  right: -2px;
  left: -2px;
  z-index: 10;
  height: 2px;
  background: var(--marker);
  transition: background 0.3s;
}

.milestone-marker.passed {
  background: var(--marker-strong);
  box-shadow: 0 0 6px var(--marker);
}

.milestone-marker-dot {
  position: absolute;
  top: 50%;
  right: -6px;
  width: 10px;
  height: 10px;
  border: 2px solid var(--marker);
  border-radius: 50%;
  background: var(--surface);
  transform: translateY(-50%);
  transition: border-color 0.3s, box-shadow 0.3s;
}

.milestone-marker.passed .milestone-marker-dot {
  border-color: var(--marker-strong);
  box-shadow: 0 0 8px var(--marker);
}

.gauge-labels {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 420px;
}

.milestone-label {
  position: absolute;
  left: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 18px);
  transform: translateY(50%);
  transition: opacity 0.3s;
}

.milestone-label-line {
  width: 10px;
  height: 1px;
  flex: 0 0 auto;
  background: var(--muted);
}

.milestone-label.passed .milestone-label-line {
  background: rgba(255, 255, 255, 0.7);
}

.milestone-label-text {
  max-width: 210px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.milestone-label.passed .milestone-label-text {
  color: var(--text);
}

.milestone-label-time {
  margin-left: 4px;
  color: var(--muted);
  font-size: 10px;
  opacity: 0.7;
}

.gauge-time-end,
.gauge-time-start {
  position: absolute;
  left: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

.gauge-time-end {
  top: -8px;
}

.gauge-time-start {
  bottom: -8px;
}

.gauge-time-end span,
.gauge-time-start span {
  display: inline-block;
  width: 10px;
  height: 1px;
  background: var(--muted);
}

.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.btn {
  min-height: 42px;
  padding: 12px 24px;
  border: none;
  border-radius: 10px;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #0d0e12;
  font-weight: 500;
}

.btn-primary:hover {
  background: #fbbf6a;
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-ghost {
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
}

.btn-ghost:hover {
  border-color: var(--muted);
  color: var(--text);
}

.theme-toggle {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 8px 12px;
  font-size: 10px;
}

.config-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-top: 62px;
  padding: 24px;
  position: sticky;
  top: 40px;
}

.config-section {
  display: grid;
  gap: 10px;
}

.section-title {
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 2px;
  text-transform: uppercase;
}

#milestonesCount {
  opacity: 0.55;
}

.duration-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.duration-field {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
}

.field-label {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 1px;
}

input[type="number"],
input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: var(--surface2);
  color: var(--text);
  font-size: 20px;
  font-weight: 500;
  padding: 10px 12px;
  text-align: center;
  transition: border-color 0.2s;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

input[type="number"]:focus,
input[type="text"]:focus {
  border-color: var(--accent);
}

input[type="text"] {
  font-size: 13px;
  text-align: left;
}

.separator {
  flex-shrink: 0;
  padding-top: 18px;
  color: var(--muted);
  font-size: 24px;
}

.milestone-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.milestone-time-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.milestone-time-row input[type="number"] {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  font-size: 16px;
}

.milestone-time-row .sep {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 16px;
}

.btn-add {
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.5px;
  text-align: center;
  transition: all 0.15s;
}

.btn-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.milestones-list {
  display: flex;
  max-height: 260px;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.milestones-list::-webkit-scrollbar {
  width: 4px;
}

.milestones-list::-webkit-scrollbar-track {
  background: transparent;
}

.milestones-list::-webkit-scrollbar-thumb {
  border-radius: 2px;
  background: var(--border);
}

.milestone-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  transition: border-color 0.3s;
}

.milestone-item.active-milestone {
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(244, 161, 74, 0.15);
}

.milestone-time-badge {
  flex-shrink: 0;
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent);
  font-size: 11px;
  white-space: nowrap;
}

.milestone-note {
  flex: 1;
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.milestone-delete {
  flex-shrink: 0;
  padding: 2px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  transition: color 0.15s;
}

.milestone-delete:hover {
  color: var(--red);
}

.empty-milestones {
  padding: 12px 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
}

.notif {
  position: fixed;
  top: 24px;
  left: 50%;
  z-index: 100;
  max-width: 360px;
  padding: 14px 24px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: var(--surface2);
  color: var(--accent);
  box-shadow: var(--toast-shadow);
  font-size: 13px;
  text-align: center;
  transform: translateX(-50%) translateY(-80px);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.notif.show {
  transform: translateX(-50%) translateY(0);
}

.system-version {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  margin: 0;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  background: color-mix(in srgb, var(--surface2) 86%, transparent);
  box-shadow: var(--toast-shadow);
  color: var(--accent);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  pointer-events: none;
}

.done-badge {
  display: none;
  padding: 10px;
  border: 1px solid rgba(74, 222, 128, 0.2);
  border-radius: 12px;
  margin-top: 20px;
  background: rgba(74, 222, 128, 0.08);
  color: var(--green);
  font-size: 13px;
  letter-spacing: 1px;
  text-align: center;
}

.done-badge.show {
  display: block;
}

@media (max-width: 940px) {
  body {
    padding: 28px 18px;
  }

  .app {
    grid-template-columns: 1fr;
  }

  .config-panel {
    position: static;
    margin-top: 0;
  }
}

@media (max-width: 640px) {
  body {
    padding: 18px 12px;
  }

  .header,
  .controls {
    align-items: stretch;
    flex-direction: column;
  }

  .title-group {
    justify-content: space-between;
  }

  .theme-toggle,
  .btn {
    width: 100%;
  }

  .gauge-wrapper,
  .config-panel {
    padding: 18px;
  }

  .timer-big {
    font-size: 52px;
  }

  .gauge-container {
    gap: 14px;
  }

  .gauge-bar-area {
    width: 46px;
  }

  .gauge-track,
  .gauge-labels {
    height: 320px;
  }

  .milestone-label {
    left: 12px;
    gap: 6px;
  }

  .milestone-label-text {
    max-width: 145px;
  }

  .duration-row,
  .milestone-time-row {
    gap: 6px;
  }

  .system-version {
    right: 12px;
    bottom: 12px;
  }
}
