:root {
  --bg: #050505;
  --panel: #0b0b0b;
  --line: #252525;
  --line-soft: #1a1a1a;
  --red: #ff2c1a;
  --red-off: #240705;
  --text: #ededed;
  --muted: #7d7d7d;
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", "Segoe UI", sans-serif;
}

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

html {
  color-scheme: dark;
}

body {
  min-width: 280px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

.svg-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   Top bar
   -------------------------------------------------------------------------- */

.topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(20px, 4vw, 46px);
  pointer-events: none;
}

.brand,
.top-actions {
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.brand-mark {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-end;
  gap: 3px;
  height: 22px;
}

.brand-mark i {
  display: block;
  width: 3px;
  background: var(--red);
}

.brand-mark i:nth-child(1) {
  height: 11px;
}

.brand-mark i:nth-child(2) {
  height: 22px;
}

.brand-mark i:nth-child(3) {
  height: 16px;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand-copy b {
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.24em;
  line-height: 1;
}

.brand-copy span {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.19em;
  line-height: 1;
}

.top-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 9px;
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--text);
  transition: background-color 0.12s linear, border-color 0.12s linear, color 0.12s linear;
}

.icon-button svg {
  width: 17px;
  height: 17px;
}

.icon-button:hover {
  border-color: #3a3a3a;
  background: #171717;
  color: #ffffff;
}

.icon-button.small {
  width: 32px;
  height: 32px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.icon-button.small:hover {
  background: #171717;
  color: var(--text);
}

.play-button {
  width: 42px;
  height: 42px;
  border-color: var(--red);
  background: var(--red);
  color: #060606;
}

.play-button:hover {
  border-color: #ff4a3b;
  background: #ff4a3b;
  color: #060606;
}

.play-button svg {
  width: 19px;
  height: 19px;
}

.play-button .icon-pause {
  display: none;
}

.play-button.is-playing .icon-play {
  display: none;
}

.play-button.is-playing .icon-pause {
  display: block;
}

/* --------------------------------------------------------------------------
   Stage
   -------------------------------------------------------------------------- */

.stage {
  display: flex;
  min-height: 100vh;
  min-height: 100svh;
  align-items: center;
  justify-content: center;
  padding: 104px 24px 56px;
}

.clock {
  display: flex;
  width: 100%;
  flex-direction: column;
  align-items: center;
}

/* --------------------------------------------------------------------------
   Seven-segment display
   -------------------------------------------------------------------------- */

.time-display {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.035em;
  font-size: clamp(58px, min(20vw, 32vh), 300px);
  line-height: 1;
}

.digit-group,
.number {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.035em;
}

.digit {
  position: relative;
  display: block;
  flex: 0 0 auto;
  width: 0.56em;
  height: 1em;
}

.seg {
  position: absolute;
  display: block;
  background: var(--red-off);
  transition: background-color 0.06s linear;
}

.seg.on {
  background: var(--red);
}

.seg-h {
  left: 0.07em;
  width: 0.42em;
  height: 0.09em;
  clip-path: polygon(8% 0, 92% 0, 100% 50%, 92% 100%, 8% 100%, 0 50%);
}

.seg-v {
  width: 0.09em;
  height: 0.41em;
  clip-path: polygon(0 8%, 50% 0, 100% 8%, 100% 92%, 50% 100%, 0 92%);
}

.seg-a {
  top: 0;
}

.seg-b {
  top: 0.055em;
  right: 0;
}

.seg-c {
  right: 0;
  bottom: 0.055em;
}

.seg-d {
  bottom: 0;
}

.seg-e {
  bottom: 0.055em;
  left: 0;
}

.seg-f {
  top: 0.055em;
  left: 0;
}

.seg-g {
  top: 50%;
  transform: translateY(-50%);
}

.colon {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.22em;
  width: 0.115em;
  height: 1em;
  padding: 0.03em 0;
}

.colon i {
  display: block;
  width: 0.115em;
  height: 0.09em;
  background: var(--red);
}

.meridiem {
  position: absolute;
  top: 0.06em;
  right: -0.6em;
  display: none;
  color: var(--red);
  font-family: var(--mono);
  font-size: clamp(9px, 0.07em, 14px);
  font-weight: 600;
  letter-spacing: 0.1em;
  line-height: 1;
}

.time-display.is-12h .meridiem {
  display: block;
}

/* --------------------------------------------------------------------------
   Date line
   -------------------------------------------------------------------------- */

.date-line {
  display: flex;
  max-width: 100%;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35em 0.6em;
  margin-top: clamp(28px, 4.6vh, 46px);
  color: var(--red);
  font-size: clamp(16px, min(3.9vw, 6vh), 55px);
  line-height: 1;
}

.date-part {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.16em;
  white-space: nowrap;
}

.cn {
  font-family: var(--sans);
  font-size: 0.78em;
  font-weight: 500;
  letter-spacing: 0.05em;
}

.unit {
  font-family: var(--mono);
  font-size: 0.58em;
  font-weight: 500;
  letter-spacing: 0;
}

/* --------------------------------------------------------------------------
   Settings dialog
   -------------------------------------------------------------------------- */

.settings-dialog {
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100svh - 32px);
  margin: auto;
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0a0a0a;
  box-shadow: none;
  color: var(--text);
}

.settings-dialog::backdrop {
  background: rgba(0, 0, 0, 0.76);
}

.settings-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 22px 16px;
  border-bottom: 1px solid var(--line-soft);
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.18em;
}

.settings-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.settings-body {
  padding: 0 22px 10px;
}

.settings-section {
  padding: 19px 0 4px;
  border-bottom: 1px solid var(--line-soft);
}

.settings-section:last-child {
  border-bottom: 0;
}

.section-title {
  margin: 0 0 12px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.16em;
}

.section-note {
  margin: -4px 0 13px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 0 14px;
  cursor: pointer;
}

.setting-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.setting-copy b {
  font-size: 13px;
  font-weight: 500;
}

.setting-copy small {
  color: var(--muted);
  font-size: 10px;
}

.setting-row input[type="checkbox"] {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--red);
  cursor: pointer;
}

.setting-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 2px 0 16px;
}

.setting-pair > label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
}

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

.input-row input {
  width: 100%;
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #121212;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
}

.input-row b {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.settings-foot {
  display: flex;
  justify-content: flex-end;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--line-soft);
}

.done-button {
  padding: 8px 22px;
  border: 1px solid var(--red);
  border-radius: 4px;
  background: var(--red);
  color: #060606;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  transition: background-color 0.12s linear;
}

.done-button:hover {
  background: #ff4a3b;
}

/* --------------------------------------------------------------------------
   Feedback
   -------------------------------------------------------------------------- */

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  z-index: 30;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #111111;
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
  transform: translateX(-50%);
  visibility: hidden;
}

.toast.is-visible {
  visibility: visible;
}

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

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  margin: 0;
  place-items: center;
  background: var(--bg);
  color: var(--text);
}

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

@media (max-width: 700px) {
  .topbar {
    padding: 19px 18px;
  }

  .brand-copy span {
    display: none;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  .play-button {
    width: 40px;
    height: 40px;
  }

  .stage {
    padding: 88px 16px 40px;
  }

  .date-line {
    gap: 0.45em 0.55em;
    margin-top: 27px;
  }

  .meridiem {
    top: -0.85em;
    right: 0;
    font-size: clamp(9px, 0.15em, 12px);
  }
}

@media (max-width: 390px) {
  .topbar {
    padding: 17px 14px;
  }

  .brand {
    gap: 10px;
  }

  .brand-copy b {
    font-size: 10px;
    letter-spacing: 0.17em;
  }

  .top-actions {
    gap: 6px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
  }

  .play-button {
    width: 38px;
    height: 38px;
  }

  .stage {
    padding: 82px 12px 32px;
  }

  .date-line {
    font-size: clamp(15px, 4.3vw, 18px);
    gap: 0.55em 0.48em;
  }

  .settings-body,
  .settings-head {
    padding-left: 18px;
    padding-right: 18px;
  }

  .settings-foot {
    padding-right: 18px;
  }
}

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