:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #5f6b76;
  --line: #d8dee5;
  --accent: #167a72;
  --accent-strong: #0f5f59;
  --accent-soft: #d9f0ec;
  --warn: #b45224;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(25, 38, 54, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 2.5rem;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 700;
  padding: 0.65rem 0.9rem;
}

button:hover {
  background: var(--accent-strong);
}

button.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

button.secondary:hover {
  background: #eef2f4;
}

button.danger {
  color: var(--danger);
}

input,
select,
output {
  width: 100%;
  min-height: 2.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 0.55rem 0.65rem;
}

output {
  display: flex;
  align-items: center;
  background: #eef2f4;
  color: var(--muted);
  font-weight: 800;
}

label,
legend {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

label > input,
label > select,
label > output {
  margin-top: 0.3rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(16px);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 1.8rem);
  letter-spacing: 0;
}

.topbar p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.tabs {
  display: inline-grid;
  grid-template-columns: minmax(5rem, 1fr);
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #eef2f4;
}

.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.2rem;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  padding: 0.45rem 0.7rem;
  text-decoration: none;
  font-weight: 700;
}

.tab:hover {
  background: rgba(255, 255, 255, 0.7);
}

.tab.active {
  background: white;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.timer-panel,
.assignments,
.timeline,
.admin-panel,
.schedule-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.timer-panel {
  padding: clamp(1.1rem, 3vw, 1.6rem);
}

.timer-meta,
.section-head,
.live-actions,
.add-time-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.85rem;
  font-weight: 800;
  padding: 0.35rem 0.7rem;
}

#clockNow,
.section-head span,
.timeline time,
.segment-row small {
  color: var(--muted);
  font-weight: 700;
}

.timer-panel h2 {
  margin: 1.2rem 0 0.3rem;
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  letter-spacing: 0;
}

.countdown {
  font-size: clamp(4rem, 18vw, 10rem);
  line-height: 0.95;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.progress-track {
  height: 0.8rem;
  border-radius: 999px;
  background: #e9edf1;
  overflow: hidden;
  margin: 1rem 0;
}

.progress-bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #5b8fef);
  transition: width 200ms linear;
}

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

.timer-grid div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.8rem;
}

.timer-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.timer-grid strong {
  display: block;
  overflow-wrap: anywhere;
  margin-top: 0.2rem;
  font-size: clamp(1rem, 4vw, 1.35rem);
}

.live-actions {
  justify-content: flex-start;
  margin-top: 1rem;
}

.status-line {
  min-height: 1.25rem;
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

.assignments,
.timeline,
.schedule-editor,
.share-panel {
  margin-top: 1rem;
  padding: 1rem;
}

.section-head {
  margin-bottom: 0.85rem;
}

.section-head h2 {
  margin: 0;
  font-size: clamp(1.05rem, 2vw, 1.25rem);
}

.assignment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 0.75rem;
}

.assignment-card {
  min-height: 7rem;
  border: 1px solid var(--line);
  border-left: 0.45rem solid var(--accent);
  border-radius: 8px;
  padding: 0.9rem;
  background: #fbfcfd;
}

.assignment-card span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.assignment-card strong {
  display: block;
  margin-top: 0.2rem;
  font-size: 1.2rem;
  overflow-wrap: anywhere;
}

.timeline ol,
#timelineList {
  list-style: none;
  margin: 0;
  padding: 0;
}

.timeline li {
  display: grid;
  grid-template-columns: 7.5rem minmax(0, 1fr) auto;
  gap: 0.8rem;
  align-items: center;
  min-height: 3.4rem;
  border-top: 1px solid var(--line);
  padding: 0.75rem 0;
}

.timeline li:first-child {
  border-top: 0;
}

.timeline li.active {
  color: var(--accent-strong);
  font-weight: 800;
}

.timeline strong {
  overflow-wrap: anywhere;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(18rem, 0.7fr);
  gap: 1rem;
}

.admin-panel {
  padding: 1rem;
}

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

.form-grid label:nth-child(3),
.form-grid label:nth-child(4),
.form-grid label:nth-child(5) {
  grid-column: span 2;
}

.add-time-row {
  align-items: end;
  justify-content: flex-start;
}

.add-time-row > label {
  width: 10rem;
}

.add-time-preview {
  border-top: 1px solid var(--line);
  margin-top: 1rem;
  padding-top: 1rem;
}

.preview-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.preview-summary > div {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.preview-rows {
  display: grid;
  gap: 0.5rem;
}

.preview-row {
  display: grid;
  grid-template-columns: minmax(8rem, 1.2fr) 5rem 5rem minmax(6rem, 0.8fr) 6rem;
  gap: 0.5rem;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 0.65rem;
}

.preview-row span,
.preview-row strong {
  overflow-wrap: anywhere;
}

.preview-row label {
  color: var(--muted);
}

fieldset {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  min-height: 2.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0;
  padding: 0.25rem 0.65rem 0.45rem;
}

.choice {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--ink);
  font-weight: 700;
}

.choice input {
  width: auto;
  min-height: auto;
  margin: 0;
}

.segments-editor {
  display: grid;
  gap: 0.65rem;
}

.segment-row {
  display: grid;
  grid-template-columns: 5.6rem minmax(10rem, 1.4fr) minmax(7.5rem, 0.7fr) 6rem 6rem 6rem 2.6rem;
  gap: 0.6rem;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 0.7rem;
}

.target-check {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.55rem;
  color: var(--ink);
}

.target-check input {
  width: auto;
  min-height: auto;
  margin: 0;
}

.icon-button {
  width: 2.55rem;
  min-width: 2.55rem;
  padding: 0;
  background: #f5e7e5;
  color: var(--danger);
  font-size: 1.35rem;
  line-height: 1;
}

.icon-button:hover {
  background: #f1d2ce;
}

.share-panel input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (max-width: 820px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .tabs {
    width: 100%;
  }

  .timer-grid,
  .admin-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid label:nth-child(3),
  .form-grid label:nth-child(4),
  .form-grid label:nth-child(5) {
    grid-column: auto;
  }

  .timeline li {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }

  .segment-row {
    grid-template-columns: 1fr 1fr;
  }

  .segment-row label:nth-of-type(2),
  .segment-row label:nth-of-type(3) {
    grid-column: span 2;
  }

  .preview-row {
    grid-template-columns: 1fr 1fr;
  }

  .preview-row > span:first-child {
    grid-column: span 2;
  }

  .segment-delete {
    justify-self: end;
  }
}

@media (max-width: 480px) {
  main {
    padding-inline: 0.75rem;
  }

  .countdown {
    font-size: clamp(3.4rem, 22vw, 5.5rem);
  }

  .segment-row {
    grid-template-columns: 1fr;
  }

  .segment-row label:nth-of-type(2),
  .segment-row label:nth-of-type(3) {
    grid-column: auto;
  }

  .preview-row {
    grid-template-columns: 1fr;
  }

  .preview-row > span:first-child {
    grid-column: auto;
  }

  .add-time-row > label,
  .add-time-row button,
  fieldset {
    width: 100%;
  }
}
