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

:root {
  --bg: #0b0d10;
  --fg: #f4f6f8;
  --muted: #8a94a3;
  --accent: #4cc2ff;
  --done: #ff4d4f;
  --panel: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.14);
  color-scheme: dark;
}

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

body {
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

/* The current timer style (see styles-core.js), applied through custom properties. */
body.styled {
  background: var(--style-bg);
}

body.styled .stage {
  color: var(--style-fg);
}

body.styled .display {
  font-family: var(--style-font);
  font-weight: var(--style-weight);
  text-shadow: var(--style-shadow);
}

body.styled .status {
  color: var(--style-fg);
  opacity: 0.85;
}

/* Strobe effect (see effects-core.js): a white layer that inverts every color
   beneath it, shown for the first half of each second. */
body.effect-strobe::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 2;
  background: #fff;
  mix-blend-mode: difference;
  pointer-events: none;
  animation: strobe 1s step-end infinite;
}

@keyframes strobe {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

.stage {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2vh 2vw 9rem;
}

.display {
  /* Sized so the readout fits the width whatever its length (set from JS),
     scaled by the current style and shrunk further if a font runs wide. */
  --chars: 5;
  --fit: 1;
  max-width: 100%;
  font-size: calc(min(calc(150vw / (var(--chars) + 0.4)), var(--max-height, 70vh)) * var(--style-scale, 1) * var(--fit));
  white-space: nowrap;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  user-select: none;
  transition: color 0.3s;
}

.status {
  min-height: 1.3em;
  margin: 0 0 2vh;
  font-size: clamp(1.1rem, 3.5vw, 2.5rem);
  color: var(--muted);
  text-align: center;
}

/* The schedule summary card, shown on the Inactive screen while waiting.
   It replaces the status line and leaves the readout less of the height. */
.summary {
  margin: 0 0 3vh;
  padding: clamp(0.75rem, 2.5vh, 1.75rem) clamp(1rem, 4vw, 3rem);
  text-align: center;
  font-size: clamp(1rem, 3.2vh, 2rem);
  line-height: 1.3;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
}

body.styled .summary {
  color: var(--style-fg);
}

.summary p {
  margin: 0;
}

.summary-when {
  font-size: 1.5em;
  font-weight: 700;
}

.summary-countdown {
  margin-top: 0.75em !important;
  font-variant-numeric: tabular-nums;
}

body.show-summary .status {
  display: none;
}

body.show-summary .display {
  --max-height: 40vh;
}

body[data-state="waiting"] .status {
  color: var(--accent);
}

body[data-state="paused"] .display {
  opacity: 0.55;
}

body.overtime:not(.styled) .display {
  color: var(--done);
}

.controls {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem 1.5rem;
  width: max-content;
  max-width: calc(100vw - 2rem);
  padding: 0.75rem 1rem;
  background: rgba(10, 12, 16, 0.55);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  backdrop-filter: blur(6px);
  transition: opacity 0.4s;
}

body.controls-hidden .controls,
body.controls-hidden .config-button {
  opacity: 0;
  pointer-events: none;
}

body.controls-hidden {
  cursor: none;
}

.group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

label {
  color: var(--muted);
  font-size: 0.9rem;
}

input,
button {
  font: inherit;
  color: inherit;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  padding: 0.4rem 0.7rem;
}

input[type="number"] {
  width: 5rem;
}

button {
  cursor: pointer;
}

button:hover,
button:focus-visible {
  border-color: var(--accent);
}

button[type="submit"],
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #001826;
  font-weight: 600;
}

.config-button {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  padding: 0;
  border-radius: 50%;
  background: rgba(10, 12, 16, 0.55);
  color: #c3cad3;
  transition: opacity 0.4s, color 0.2s;
}

.config-button:hover,
.config-button:focus-visible {
  color: var(--fg);
}

.config-dialog {
  width: min(36rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 1.5rem;
  color: var(--fg);
  background: #161a20;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
}

.config-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.config-dialog h2 {
  margin: 0 0 1.25rem;
  font-size: 1.4rem;
}

.field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
}

.field input,
.field select {
  width: 100%;
  min-width: 0;
}

.hint,
.error {
  margin: 0;
  font-size: 0.85rem;
}

.hint {
  color: var(--muted);
}

.error {
  color: var(--done);
}

input[aria-invalid="true"] {
  border-color: var(--done);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.section-header {
  flex-wrap: wrap;
  gap: 0.5rem;
}

.section-header select {
  width: auto;
}

.style-list {
  display: grid;
  gap: 0.4rem;
  margin: 0.25rem 0 0;
  padding: 0;
  list-style: none;
}

.style-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.style-item.is-disabled .style-row {
  opacity: 0.5;
}

.style-row {
  flex: 1;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  text-align: left;
}

.style-swatch,
.style-preview {
  background: var(--style-bg);
  color: var(--style-fg);
  font-family: var(--style-font);
  font-weight: var(--style-weight);
  text-shadow: var(--style-shadow);
  font-variant-numeric: tabular-nums;
}

.style-swatch {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2rem;
  border-radius: 0.3rem;
  font-size: 1.2rem;
  line-height: 1;
}

.style-start {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.effect-list {
  display: grid;
  gap: 0.5rem;
  margin: 0.25rem 0 0;
  padding: 0;
  list-style: none;
}

.effect-list:empty::before {
  content: "No effects.";
  color: var(--muted);
  font-size: 0.85rem;
}

.effect-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.9rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
}

.effect-item.is-disabled .effect-name {
  opacity: 0.5;
}

.effect-name {
  flex: 1 0 100%;
  font-weight: 600;
}

.effect-item label:not(.checkbox) {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.effect-item input[type="number"] {
  width: 5rem;
}

.effect-item .remove-effect {
  margin-left: auto;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

.checkbox input {
  width: auto;
}

.style-preview {
  display: grid;
  place-items: center;
  height: 8rem;
  margin-bottom: 1.25rem;
  overflow: hidden;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
}

.style-preview-clock {
  font-size: calc(5rem * var(--style-scale, 1));
  line-height: 1;
}

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

.inline input[type="number"],
.inline #style-start {
  width: 9rem;
}

.inline .grow {
  flex: 1 1 10rem;
  width: auto;
}

.field > .inline + .inline {
  margin-top: 0.25rem;
}

.hint code {
  font-size: 0.95em;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  column-gap: 1rem;
}

.field-grid .field {
  margin-bottom: 1rem;
}

.field input[type="color"] {
  height: 2.4rem;
  padding: 0.2rem;
}

.field.checkboxes {
  align-content: end;
}

select {
  font: inherit;
  color: inherit;
  background: #22272e;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  padding: 0.4rem 0.5rem;
}

.dialog-actions .spacer {
  flex: 1;
}

button.danger {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: #ffb3b4;
  border-color: rgba(255, 77, 79, 0.5);
}

button.armed {
  color: #ffb3b4;
  border-color: var(--done);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

[hidden] {
  display: none !important;
}
