:root {
  color-scheme: light;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --surface: rgba(255, 255, 255, 0.9);
  --background: linear-gradient(160deg, #f9fafb 0%, #e2e8f0 40%, #f9fafb 100%);
  --shadow: 0 18px 35px rgba(15, 23, 42, 0.12);
  --hop: #f97316;
  --success: #16a34a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 0 0 2rem;
  background: var(--background);
  color: var(--text-primary);
}

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

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.page {
  width: min(1040px, 100%);
  padding: clamp(2rem, 5vw, 4rem) clamp(1rem, 4vw, 2rem) 3rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2rem;
}

.page__header {
  text-align: center;
  display: grid;
  gap: 0.75rem;
}

.page__header h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3rem);
}

.page__header p {
  margin: 0;
  color: var(--text-secondary);
}

/* ---------- Modes ---------- */

.modes {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  justify-self: center;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.06);
}

.modes button {
  border: none;
  background: none;
  padding: 0.55rem 1.2rem;
  border-radius: 999px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.modes button[aria-selected="true"] {
  background: #fff;
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

.modes button:focus-visible,
.btn:focus-visible,
.clock:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.45);
  outline-offset: 3px;
}

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

/* ---------- Cards & controls ---------- */

.card {
  background: var(--surface);
  border-radius: 24px;
  padding: clamp(1.25rem, 3vw, 2rem);
  box-shadow: var(--shadow);
}

.clock-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.clock-card {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
}

.side-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.25rem;
}

.hint {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: center;
  min-height: 1.3em;
}

.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.65rem 1.2rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 140ms ease, transform 100ms ease;
}

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

.btn--primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.28);
}

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

.btn--ghost {
  background: #fff;
  border-color: var(--border);
  color: var(--text-secondary);
}

.btn--ghost:hover {
  border-color: #cbd5e1;
  color: var(--text-primary);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.6rem 0.75rem;
}

.action-row--start {
  justify-content: flex-start;
}

.settings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem 1rem;
  padding: 1rem;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.03);
}

.settings--top {
  grid-template-columns: 1fr 1fr;
  background: none;
  padding: 0;
}

.settings--top .segmented {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.field--center {
  justify-items: center;
}

.field--inline {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.field select {
  max-width: 100%;
}

.field input,
.field select,
.task__answer input {
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 12px;
  padding: 0.6rem 0.8rem;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.95);
  color: var(--text-primary);
}

.field input:focus,
.field select:focus,
.task__answer input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  cursor: pointer;
}

.check input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
}

.segmented {
  display: inline-flex;
  justify-self: start;
  padding: 4px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.06);
}

.segmented label {
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: block;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.segmented input:checked + span {
  background: #fff;
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

.segmented input:focus-visible + span {
  outline: 3px solid rgba(37, 99, 235, 0.45);
}

/* ---------- Clock ---------- */

.clock {
  width: 100%;
  max-width: 440px;
  height: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.clock--small {
  max-width: 280px;
}

.clock__face {
  fill: #fff;
  stroke: var(--text-primary);
  stroke-width: 4;
}

.clock__tick {
  stroke: var(--text-primary);
  stroke-width: 1.2;
}

.clock__tick--major {
  stroke-width: 3;
}

.clock__number {
  font-size: 19px;
  font-weight: 700;
  text-anchor: middle;
  fill: var(--text-primary);
}

.clock__inner-numbers {
  display: none;
}

.clock.show-inner-numbers .clock__inner-numbers {
  display: inline;
}

.clock__inner-number {
  font-size: 10px;
  font-weight: 600;
  text-anchor: middle;
  fill: #64748b;
}

.clock__minute-number {
  font-size: 10px;
  font-weight: 700;
  text-anchor: middle;
  fill: var(--accent);
}

.clock.hide-minute-numbers .clock__minute-numbers,
.clock--small .clock__minute-numbers {
  display: none;
}

.clock__hand {
  cursor: grab;
}

.clock.is-dragging .clock__hand {
  cursor: grabbing;
}

.clock__hand-hit {
  stroke: transparent;
  stroke-width: 26;
  stroke-linecap: round;
}

.clock__hand-line {
  stroke-linecap: round;
}

.clock__hand--hour .clock__hand-line {
  stroke: var(--text-primary);
  stroke-width: 9;
}

.clock__hand--hour .clock__knob {
  fill: var(--text-primary);
}

.clock__hand--minute .clock__hand-line {
  stroke: var(--accent);
  stroke-width: 5;
}

.clock__hand--minute .clock__knob {
  fill: var(--accent);
}

.clock__center {
  fill: var(--text-primary);
  stroke: #fff;
  stroke-width: 2;
}

.clock.is-static .clock__hand {
  cursor: default;
}

.clock.is-static .clock__knob {
  display: none;
}

/* ---------- Readout ---------- */

.readout {
  display: grid;
  gap: 0.4rem;
  min-height: 5rem;
}

.readout__digital {
  font-size: clamp(3rem, 8vw, 4.6rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.readout__words {
  font-size: clamp(1.3rem, 3vw, 1.7rem);
  font-weight: 600;
  color: var(--accent);
}

/* ---------- Practice ---------- */

.task {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.75rem;
  padding: 1.1rem;
  border-radius: 18px;
  background: rgba(37, 99, 235, 0.05);
}

.task__prompt {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.task__target {
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.task__answer {
  display: flex;
  gap: 0.6rem;
}

.task__answer input {
  flex: 1;
  min-width: 0;
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

#practice-check {
  justify-self: start;
}

.feedback {
  margin: 0;
  min-height: 1.5em;
  font-weight: 600;
}

.feedback.is-right {
  color: var(--success);
}

.feedback.is-wrong {
  color: #dc2626;
}

.feedback.is-hint {
  color: var(--text-secondary);
}

.score {
  margin-left: auto;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ---------- Difference ---------- */

.diff-card {
  display: grid;
  gap: 1.5rem;
}

.diff-question {
  margin: 0;
  text-align: center;
  font-size: clamp(1.3rem, 3.2vw, 1.9rem);
  font-weight: 700;
}

.diff-clocks {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
}

.diff-clock {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
}

.diff-clock h2 {
  margin: 0;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

.diff-clock input {
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
}

.diff-arrow {
  font-size: 2.2rem;
  color: var(--text-muted);
}

.timeline-wrap {
  display: grid;
  gap: 1rem;
}

.timeline {
  position: relative;
  height: 150px;
  margin: 0 clamp(1.25rem, 4vw, 2.5rem);
}

.timeline__axis {
  position: absolute;
  left: 0;
  right: 0;
  top: 96px;
  height: 4px;
  border-radius: 999px;
  background: var(--text-primary);
}

.timeline__tick {
  position: absolute;
  top: -10px;
  width: 2px;
  height: 24px;
  background: var(--text-primary);
  transform: translateX(-50%);
}

.timeline__label {
  position: absolute;
  top: 20px;
  transform: translateX(-50%);
  font-size: clamp(0.8rem, 2vw, 0.95rem);
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.timeline__label.is-from {
  color: var(--accent);
  font-weight: 800;
}

.timeline__label.is-to {
  color: var(--success);
  font-weight: 800;
}

.timeline__point {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: var(--accent);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.25);
  transform: translate(-50%, -50%);
  z-index: 2;
}

.timeline__point.is-to {
  background: var(--success);
}

.hop {
  position: absolute;
  bottom: calc(100% + 2px);
  height: var(--hop-height, 40px);
  pointer-events: none;
}

.hop__arc {
  position: absolute;
  inset: 0;
  border: 3px solid var(--hop);
  border-bottom: none;
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
}

.hop__arc::after {
  content: "";
  position: absolute;
  right: -7px;
  bottom: -2px;
  border-left: 5.5px solid transparent;
  border-right: 5.5px solid transparent;
  border-top: 9px solid var(--hop);
}

.hop__label {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 4px);
  transform: translateX(-50%);
  font-size: clamp(0.75rem, 1.8vw, 0.95rem);
  font-weight: 700;
  color: #c2410c;
  white-space: nowrap;
}

.hop.is-new .hop__arc {
  animation: draw-right 480ms ease-out both;
  animation-delay: var(--delay, 0ms);
}

.hop.is-new .hop__label {
  animation: fade-in 300ms ease both;
  animation-delay: calc(var(--delay, 0ms) + 250ms);
}

@keyframes draw-right {
  from {
    clip-path: inset(-10px 100% -10px -10px);
  }
  to {
    clip-path: inset(-10px -10px -10px -10px);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.diff-total {
  margin: 0;
  text-align: center;
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  font-weight: 700;
  color: var(--success);
}

/* ---------- Notes ---------- */

.notes {
  background: rgba(255, 255, 255, 0.7);
  border-radius: 20px;
  padding: 1.5rem;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
  display: grid;
  gap: 1rem;
}

.notes h2 {
  margin: 0;
  font-size: 1.25rem;
}

.notes ul {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.5rem;
}

.notes li {
  color: var(--text-secondary);
}

/* ---------- Responsive ---------- */

@media (max-width: 800px) {
  .clock-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

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

  .diff-arrow {
    display: none;
  }

  .settings,
  .settings--top {
    grid-template-columns: minmax(0, 1fr);
  }

  .score {
    margin-left: 0;
    flex-basis: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
