:root {
  color-scheme: light;
  --bg: #f4efe4;
  --bg-accent: #e9edf8;
  --panel: rgba(255, 252, 246, 0.84);
  --panel-strong: rgba(255, 255, 255, 0.94);
  --text: #1d2433;
  --muted: #596375;
  --border: rgba(29, 36, 51, 0.1);
  --stroke: rgba(29, 36, 51, 0.12);
  --shadow: 0 24px 60px rgba(25, 34, 56, 0.16);
  --legend-card: rgba(255, 255, 255, 0.78);
  --legend-card-active: rgba(255, 255, 255, 0.98);
  --input-bg: rgba(255, 255, 255, 0.94);
  --code-bg: rgba(37, 50, 74, 0.08);
  --button-bg: #25324a;
  --button-text: #ffffff;
  --button-secondary-bg: rgba(37, 50, 74, 0.12);
  --button-secondary-text: #25324a;
  --error-bg: rgba(199, 84, 84, 0.08);
  --error-text: #8e2c2c;
  --clock-core: rgba(255, 253, 248, 0.88);
  --clock-frame: rgba(255, 255, 255, 0.82);
  --tick: rgba(29, 36, 51, 0.28);
  --hour-hand: #25324a;
  --minute-hand: #355275;
  --second-hand: #c75454;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0f1724;
  --bg-accent: #18253a;
  --panel: rgba(18, 28, 43, 0.84);
  --panel-strong: rgba(21, 31, 48, 0.96);
  --text: #eef3ff;
  --muted: #a3b1c7;
  --border: rgba(183, 197, 225, 0.14);
  --stroke: rgba(183, 197, 225, 0.18);
  --shadow: 0 24px 60px rgba(2, 8, 23, 0.45);
  --legend-card: rgba(25, 37, 57, 0.84);
  --legend-card-active: rgba(31, 45, 69, 0.98);
  --input-bg: rgba(16, 24, 37, 0.95);
  --code-bg: rgba(163, 177, 199, 0.12);
  --button-bg: #dbe6ff;
  --button-text: #152238;
  --button-secondary-bg: rgba(219, 230, 255, 0.12);
  --button-secondary-text: #eef3ff;
  --error-bg: rgba(239, 113, 113, 0.15);
  --error-text: #ffb2b2;
  --clock-core: rgba(18, 28, 43, 0.88);
  --clock-frame: rgba(31, 45, 69, 0.82);
  --tick: rgba(220, 229, 248, 0.34);
  --hour-hand: #eef3ff;
  --minute-hand: #9fc0ff;
  --second-hand: #ff8d8d;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0) 35%),
    linear-gradient(135deg, var(--bg) 0%, var(--bg-accent) 100%);
}

button,
input {
  font: inherit;
}

code,
pre {
  font-family: Consolas, "Courier New", monospace;
}

.display-page {
  overflow: hidden;
}

.settings-gear {
  position: fixed;
  bottom: 1.25rem;
  left: 1.25rem;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border-radius: 999px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
  font-size: 1.35rem;
  line-height: 1;
  backdrop-filter: blur(16px);
}

.settings-gear:hover {
  transform: translateY(-1px);
}

.display-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 360px;
  gap: 1.25rem;
  align-items: stretch;
  height: 100vh;
  padding: 1.25rem;
}

.display-layout.left-collapsed {
  grid-template-columns: 88px minmax(0, 1fr) 360px;
}

.display-layout.right-collapsed {
  grid-template-columns: 320px minmax(0, 1fr) 88px;
}

.display-layout.left-collapsed.right-collapsed {
  grid-template-columns: 88px minmax(0, 1fr) 88px;
}

.clock-stage,
.side-panel,
.settings-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 32px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.clock-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 1rem;
}

.brand-badge {
  position: absolute;
  top: 1rem;
  left: 50%;
  z-index: 2;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.9rem;
  border-radius: 999px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.brand-mark-image {
  display: block;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
}

.brand-wordmark {
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

#clock-svg {
  width: min(78vw, calc(100vh - 4rem));
  max-width: 100%;
  max-height: 100%;
  height: auto;
}

.event-preview {
  position: absolute;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-width: min(420px, calc(100% - 2rem));
  max-width: min(520px, calc(100% - 2rem));
  padding: 0.9rem 1rem;
  border-radius: 20px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.event-preview.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.event-preview.is-pinned {
  border-color: rgba(116, 140, 190, 0.4);
}

.event-preview-swatch {
  flex: 0 0 auto;
  width: 16px;
  height: 58px;
  border-radius: 999px;
  background: rgba(127, 137, 159, 0.24);
}

.event-preview-copy {
  min-width: 0;
}

.event-preview-title,
.event-preview-time {
  margin: 0;
}

.event-preview-title {
  font-size: 1rem;
  font-weight: 700;
}

.event-preview-time {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.94rem;
}

.side-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1.5rem;
}

.side-panel.is-collapsed {
  padding: 1rem 0.7rem;
}

.panel-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.panel-toggle {
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--text);
  box-shadow: var(--shadow);
}

.panel-mini-label {
  display: none;
  margin: auto;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.panel-body {
  min-height: 0;
}

.side-panel.is-collapsed .legend-header,
.side-panel.is-collapsed .panel-body {
  display: none;
}

.side-panel.is-collapsed .panel-header-row {
  justify-content: center;
}

.side-panel.is-collapsed .panel-mini-label {
  display: block;
}

.legend-header {
  margin-bottom: 1rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.74rem;
  color: var(--muted);
}

.legend-heading,
.settings-title,
.legend-title {
  margin: 0;
}

.legend-heading {
  font-size: 1.8rem;
  line-height: 1.1;
}

.legend-list {
  display: grid;
  gap: 0.9rem;
  overflow: auto;
  padding-right: 0.15rem;
}

.current-event-card {
  display: grid;
  grid-template-columns: 12px 84px 1fr;
  gap: 1rem;
  align-items: center;
  padding: 1rem;
  border-radius: 24px;
  background: var(--legend-card);
  border: 1px solid var(--border);
  box-shadow: 0 12px 28px rgba(25, 34, 56, 0.12);
}

.current-event-swatch {
  width: 12px;
  height: 100%;
  min-height: 110px;
  border-radius: 999px;
  background: rgba(127, 137, 159, 0.24);
}

.current-event-image {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 20px;
  background: rgba(127, 137, 159, 0.16);
}

.current-event-image.is-hidden {
  visibility: hidden;
}

.current-event-copy {
  min-width: 0;
}

.current-event-label {
  margin: 0 0 0.35rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.current-event-title,
.current-event-time {
  margin: 0;
}

.current-event-title {
  font-size: 1.45rem;
  line-height: 1.15;
}

.current-event-time {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 1rem;
}

.legend-card {
  display: grid;
  grid-template-columns: 10px 64px 1fr;
  align-items: center;
  gap: 0.9rem;
  padding: 0.9rem;
  border-radius: 22px;
  background: var(--legend-card);
  border: 1px solid var(--border);
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.legend-card.active {
  border-color: rgba(116, 140, 190, 0.4);
  background: var(--legend-card-active);
  box-shadow: 0 12px 28px rgba(25, 34, 56, 0.14);
}

.legend-swatch {
  width: 10px;
  height: 72px;
  border-radius: 999px;
}

.legend-image {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 16px;
  background: rgba(127, 137, 159, 0.16);
}

.legend-copy {
  min-width: 0;
}

.legend-title {
  font-size: 1rem;
  margin-bottom: 0.35rem;
}

.legend-time {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.status-message {
  padding: 1rem;
  border-radius: 18px;
  background: var(--error-bg);
  color: var(--error-text);
}

.settings-status {
  margin: 0;
  padding: 1rem;
  border-radius: 18px;
  background: var(--code-bg);
  color: var(--muted);
}

.settings-status.is-error {
  background: var(--error-bg);
  color: var(--error-text);
}

.settings-status.is-success {
  background: rgba(42, 157, 143, 0.14);
  color: #2a9d8f;
}

.clock-frame {
  fill: var(--clock-frame);
  stroke: rgba(255, 255, 255, 0.24);
  stroke-width: 4;
}

.clock-core {
  fill: var(--clock-core);
  stroke: var(--stroke);
  stroke-width: 2;
}

.slice-path {
  opacity: 0.95;
  stroke: rgba(255, 255, 255, 0.7);
  stroke-width: 2;
  pointer-events: none;
}

.slice-path.am-ring {
  opacity: 0.92;
}

.slice-path.pm-ring {
  opacity: 0.86;
}

.active-slice-path {
  opacity: 0.6;
  stroke: rgba(255, 255, 255, 0.95);
  stroke-width: 2.8;
  filter: url(#activeGlow) saturate(1.24) brightness(1.08);
  transform-origin: 300px 300px;
  animation: active-breathe 0.5s ease-in-out infinite alternate;
  pointer-events: none;
}

.ring-connector {
  fill: none;
  stroke: rgba(255, 255, 255, 0.8);
  stroke-width: 10;
  stroke-linecap: round;
  opacity: 0.7;
}

.event-icon-badge {
  cursor: pointer;
}

.event-icon-hit-area {
  fill: rgba(255, 255, 255, 0.001);
}

.event-icon-marker {
  fill: rgba(36, 42, 56, 0.82);
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.slice-path:focus-visible,
.active-slice-path:focus-visible {
  outline: none;
  stroke: rgba(255, 255, 255, 1);
  stroke-width: 4;
}

@keyframes active-breathe {
  from {
    opacity: 0.42;
    stroke-width: 2.2;
    filter: url(#activeGlow) saturate(1.12) brightness(1.02);
  }

  to {
    opacity: 0.9;
    stroke-width: 4.8;
    filter: url(#activeGlow) saturate(1.38) brightness(1.24);
  }
}

.tick {
  stroke: var(--tick);
  stroke-linecap: round;
}

.tick.major {
  stroke-width: 4;
}

.tick.minor {
  stroke-width: 2;
}

.hour-label {
  fill: var(--hour-label-color, var(--text));
  opacity: 0.8;
  font-size: var(--hour-label-size, 1.2rem);
  font-weight: 700;
}

.digital-time {
  fill: var(--text);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.digital-caption {
  fill: var(--muted);
  font-size: 0.95rem;
}

.hand {
  stroke-linecap: round;
  transform-origin: 300px 300px;
}

.hour-hand {
  stroke: var(--hour-hand);
  stroke-width: 11;
}

.minute-hand {
  stroke: var(--minute-hand);
  stroke-width: 7;
}

.second-hand {
  stroke: var(--second-hand);
  stroke-width: 4;
}

.minute-hand.is-hidden,
.second-hand.is-hidden {
  opacity: 0;
}

.hand-cap {
  fill: var(--hour-hand);
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 4;
}

.settings-page {
  min-height: 100vh;
  padding: 1.5rem;
}

.settings-shell {
  max-width: 960px;
  margin: 0 auto;
}

.settings-card {
  padding: 2rem;
}

.settings-subtitle,
.settings-note {
  color: var(--muted);
  line-height: 1.6;
}

.settings-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.settings-link {
  color: inherit;
  text-decoration: none;
  font-weight: 600;
}

.settings-link:hover {
  text-decoration: underline;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  text-decoration: none;
}

.brand-link .brand-mark-image {
  width: 42px;
  height: 42px;
}

.settings-form {
  display: grid;
  gap: 1.4rem;
  margin-top: 1.5rem;
}

.settings-section {
  display: grid;
  gap: 0.9rem;
  padding: 1rem;
  border-radius: 24px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
}

.settings-section-title {
  margin: 0;
  font-size: 1.05rem;
}

.field-row {
  display: grid;
  gap: 0.5rem;
}

.field-label,
.toggle-option {
  font-weight: 600;
}

.settings-input,
.settings-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0.85rem 0.95rem;
  background: var(--input-bg);
  color: var(--text);
}

.settings-color-input {
  min-height: 3.2rem;
  padding: 0.4rem;
}

.radio-group,
.toggle-grid {
  display: grid;
  gap: 0.75rem;
}

.settings-inline-grid {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: minmax(0, 1fr) 180px;
  align-items: end;
}

.toggle-option,
.radio-option {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 0.95rem;
  border-radius: 16px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
}

.toggle-option input,
.radio-option input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--button-bg);
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.button {
  border: 0;
  border-radius: 16px;
  padding: 0.85rem 1.1rem;
  background: var(--button-bg);
  color: var(--button-text);
  font-weight: 700;
  cursor: pointer;
}

.button.secondary {
  background: var(--button-secondary-bg);
  color: var(--button-secondary-text);
}

.metadata-example {
  margin: 0;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  border-radius: 18px;
  background: var(--code-bg);
  color: var(--text);
  font-size: 0.88rem;
}

.icon-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
}

.icon-card {
  display: grid;
  gap: 0.75rem;
  padding: 0.9rem;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
}

.icon-card-top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.icon-card-image {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 16px;
  background: rgba(127, 137, 159, 0.16);
}

.icon-card-title {
  margin: 0;
  font-size: 1rem;
}

.icon-card-subtitle {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.icon-url-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.7rem 0.8rem;
  background: var(--input-bg);
  color: var(--text);
}

.icon-card-actions {
  display: grid;
  gap: 0.55rem;
}

.icon-card-actions .button {
  width: 100%;
}

@media (max-width: 1100px) {
  .display-page {
    overflow: auto;
  }

  .display-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .display-layout.left-collapsed,
  .display-layout.right-collapsed,
  .display-layout.left-collapsed.right-collapsed {
    grid-template-columns: 1fr;
  }

  #clock-svg {
    width: min(100%, 780px);
  }
}

@media (max-width: 640px) {
  .display-layout,
  .settings-page {
    padding: 1rem;
  }

  .settings-gear {
    bottom: 1rem;
    left: 1rem;
    width: 2.7rem;
    height: 2.7rem;
  }

  .brand-badge {
    top: 0.75rem;
    padding: 0.45rem 0.7rem;
  }

  .brand-badge .brand-mark-image {
    width: 30px;
    height: 30px;
  }

  .brand-badge .brand-wordmark {
    font-size: 1rem;
  }

  .clock-stage,
  .side-panel,
  .settings-card {
    border-radius: 24px;
  }

  .current-event-card,
  .legend-card {
    grid-template-columns: 8px 52px 1fr;
  }

  .current-event-image,
  .legend-image {
    width: 52px;
    height: 52px;
    border-radius: 14px;
  }

  .current-event-swatch,
  .legend-swatch {
    height: 58px;
    min-height: 58px;
  }

  .settings-card {
    padding: 1.25rem;
  }

  .settings-inline-grid {
    grid-template-columns: 1fr;
  }

  .settings-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-nav {
    flex-direction: column;
    align-items: flex-start;
  }

  .event-preview {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    min-width: 0;
    max-width: none;
    transform: none;
  }
}
