:root {
  color-scheme: light;
  --ink: #18202a;
  --muted: #66717f;
  --paper: #f7f5ef;
  --panel: #ffffff;
  --line: #d9d6cc;
  --teal: #127a78;
  --teal-dark: #075958;
  --coral: #e05b45;
  --sun: #f4b942;
  --night: #263548;
  --shadow: 0 18px 48px rgba(24, 32, 42, 0.14);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(18, 122, 120, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(38, 53, 72, 0.07) 1px, transparent 1px),
    var(--paper);
  background-size: 42px 42px;
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(380px, 520px) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.control-panel {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  gap: clamp(18px, 3vw, 32px);
  padding: clamp(18px, 4vw, 44px);
  background: rgba(255, 255, 255, 0.9);
  border-right: 1px solid var(--line);
  overflow: auto;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.timer-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 54px;
  aspect-ratio: 1;
  border: 3px solid var(--night);
  border-radius: 50%;
  background: var(--panel);
}

.timer-mark::before {
  position: absolute;
  top: -8px;
  width: 24px;
  height: 8px;
  content: "";
  background: var(--coral);
  border-radius: 4px 4px 0 0;
}

.timer-mark span {
  width: 4px;
  height: 20px;
  background: var(--teal);
  border-radius: 999px;
  transform-origin: bottom center;
  transform: translateY(-8px) rotate(35deg);
}

.eyebrow,
.sub-display,
.message,
small {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 3px;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.65rem, 4vw, 2.35rem);
  line-height: 1.08;
}

.settings-grid {
  display: grid;
  gap: 16px;
}

fieldset {
  display: grid;
  gap: 14px;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

legend {
  padding: 0 6px;
  font-weight: 800;
}

label {
  display: grid;
  gap: 7px;
  font-weight: 700;
}

.field-row {
  display: grid;
  gap: 12px;
}

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

.unit-input {
  display: grid;
  grid-template-columns: minmax(2.4rem, 1fr) auto;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf6;
}

.unit-input input {
  min-width: 0;
  width: 100%;
  border: 0;
  padding: 12px 10px;
  background: transparent;
  color: var(--ink);
  font-weight: 800;
}

.unit-input span {
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.time-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(5rem, 1fr));
  gap: 8px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

.speed-readout {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  font-size: 0.88rem;
  color: var(--muted);
}

.speed-readout strong {
  justify-self: center;
  color: var(--teal-dark);
}

.switch-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
}

.switch-row span {
  display: grid;
  gap: 3px;
}

.switch-row input {
  width: 46px;
  height: 26px;
  accent-color: var(--teal);
}

.reveal-setting {
  transition: opacity 160ms ease;
}

.reveal-setting.is-disabled {
  opacity: 0.52;
}

.reveal-setting input:disabled {
  cursor: not-allowed;
}

.actions {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.3fr);
  gap: 10px;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 850;
}

.primary-button {
  background: var(--teal);
  color: #fff;
  box-shadow: 0 10px 26px rgba(18, 122, 120, 0.24);
}

.secondary-button,
.ghost-button {
  background: #fff;
  color: var(--night);
  border-color: var(--line);
}

.primary-button:disabled,
.secondary-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.message {
  min-height: 1.35em;
  margin: 0;
  font-weight: 650;
}

.stage {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: clamp(16px, 3vw, 28px);
  padding: clamp(18px, 4vw, 48px);
  min-width: 0;
  overflow: hidden;
}

.stage-topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  color: var(--muted);
  font-weight: 850;
}

.visual-wrap {
  display: grid;
  place-items: center;
  align-content: center;
  gap: clamp(16px, 4vmin, 34px);
  min-height: 0;
}

.dial {
  --turn: 0deg;
  position: relative;
  width: min(44vmin, 340px);
  min-width: 154px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.dial-track {
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  border: 12px solid #e8e2d3;
  border-top-color: var(--coral);
  border-right-color: var(--teal);
  border-bottom-color: var(--sun);
}

.dial-hand {
  position: absolute;
  left: 50%;
  bottom: 50%;
  width: 6px;
  height: 34%;
  border-radius: 999px;
  background: var(--night);
  transform: translateX(-50%) rotate(var(--turn));
  transform-origin: bottom center;
  transition: transform 120ms linear;
}

.dial-center {
  position: absolute;
  inset: 46%;
  border-radius: 50%;
  background: var(--coral);
  border: 4px solid var(--panel);
}

.time-display {
  max-width: 100%;
  font-variant-numeric: tabular-nums;
  font-size: clamp(4rem, 16vmin, 12rem);
  font-weight: 900;
  line-height: 0.9;
  text-align: center;
}

.sub-display {
  margin: 0;
  max-width: 46rem;
  text-align: center;
  font-size: clamp(1rem, 2.3vmin, 1.35rem);
  font-weight: 750;
}

.progress-shell {
  width: min(720px, 100%);
  height: 12px;
  justify-self: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--sun), var(--coral));
  transition: width 180ms linear;
}

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

.icon-button {
  display: grid;
  place-items: center;
  width: 48px;
  aspect-ratio: 1;
  background: #fff;
  color: var(--night);
  border-color: var(--line);
  box-shadow: 0 8px 20px rgba(24, 32, 42, 0.08);
}

.is-focus .control-panel {
  display: none;
}

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

.is-focus .stage {
  min-height: 100vh;
  min-height: 100dvh;
}

.is-shuffling .dial-hand {
  transition-duration: 40ms;
}

.is-finished .time-display {
  color: var(--coral);
}

.is-stress .stage {
  animation: stress-shake var(--stress-duration, 280ms) linear infinite;
}

.is-stress .time-display {
  color: var(--coral);
  text-shadow: 0 0 var(--stress-glow, 8px) rgba(224, 91, 69, 0.28);
}

.is-stress .dial-track {
  border-top-color: var(--coral);
  border-right-color: var(--coral);
}

.is-hidden-countdown .dial {
  background:
    repeating-linear-gradient(
      135deg,
      rgba(18, 122, 120, 0.12) 0,
      rgba(18, 122, 120, 0.12) 10px,
      rgba(255, 255, 255, 0.9) 10px,
      rgba(255, 255, 255, 0.9) 22px
    );
}

.is-hidden-countdown .dial-hand,
.is-hidden-countdown .progress-bar {
  opacity: 0;
}

.is-hidden-countdown .time-display {
  color: var(--night);
  letter-spacing: 0;
}

@media (max-width: 820px), (max-aspect-ratio: 4 / 5) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: visible;
  }

  .stage {
    min-height: 68vh;
    min-height: 68dvh;
  }
}

@container (max-width: 430px) {
  .field-row.two {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .field-row.two,
  .actions {
    grid-template-columns: 1fr;
  }

  .time-pair {
    grid-template-columns: 1fr 1fr;
  }

  fieldset {
    padding: 14px;
  }

  .time-display {
    font-size: clamp(3.5rem, 22vw, 6.4rem);
  }
}

@keyframes stress-shake {
  0% {
    transform: translate(0, 0) rotate(0deg);
  }

  20% {
    transform: translate(var(--stress-neg-distance, 0px), var(--stress-half-distance, 0px))
      rotate(var(--stress-neg-rotation, 0deg));
  }

  40% {
    transform: translate(var(--stress-distance, 0px), var(--stress-neg-half-distance, 0px))
      rotate(var(--stress-rotation, 0deg));
  }

  60% {
    transform: translate(var(--stress-neg-soft-distance, 0px), var(--stress-neg-soft-distance, 0px))
      rotate(var(--stress-neg-soft-rotation, 0deg));
  }

  80% {
    transform: translate(var(--stress-soft-distance, 0px), var(--stress-soft-distance, 0px))
      rotate(var(--stress-soft-rotation, 0deg));
  }

  100% {
    transform: translate(0, 0) rotate(0deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
