:root {
  color-scheme: dark;
  --bg: #141414;
  --bg-soft: #1f2224;
  --panel: rgba(24, 26, 28, 0.9);
  --panel-solid: #202326;
  --text: #f6f2ea;
  --muted: #aeb8b2;
  --line: rgba(255, 255, 255, 0.14);
  --accent: #52d6b8;
  --accent-strong: #2fb698;
  --danger: #f16f6f;
  --wood-a: #c39761;
  --wood-b: #7b5631;
  --wood-c: #4a3322;
  --flap-a: #111111;
  --flap-b: #050505;
  --digit: #f9f6eb;
  --shadow: 0 32px 80px rgba(0, 0, 0, 0.44);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    radial-gradient(circle at 20% 0%, rgba(82, 214, 184, 0.1), transparent 28rem),
    linear-gradient(135deg, #111111, #1d2020 48%, #111111);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

.app {
  min-height: 100svh;
  display: block;
}

.display-stage {
  position: relative;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 3vw, 3rem);
  overflow: hidden;
}

.ambient-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, transparent, #000 12%, #000 78%, transparent);
  pointer-events: none;
}

.ticker-device {
  --digit-count: 7;
  width: min(100%, 1220px);
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius);
  padding: clamp(1rem, 2.2vw, 2rem);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.1), transparent 14%, rgba(0, 0, 0, 0.16) 36%, transparent 62%, rgba(255, 255, 255, 0.08)),
    repeating-linear-gradient(92deg, rgba(255, 255, 255, 0.06) 0 2px, transparent 2px 16px),
    linear-gradient(135deg, var(--wood-a), var(--wood-b) 54%, var(--wood-c));
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transform: translateZ(0);
}

.ticker-device::before,
.ticker-device::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.34);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.55);
}

.ticker-device::before {
  left: clamp(0.6rem, 1.5vw, 1.2rem);
}

.ticker-device::after {
  right: clamp(0.6rem, 1.5vw, 1.2rem);
}

.device-topbar,
.device-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-mark {
  display: flex;
  gap: 0.36rem;
  align-items: center;
}

.brand-mark span {
  width: clamp(0.5rem, 0.9vw, 0.75rem);
  height: clamp(0.5rem, 0.9vw, 0.75rem);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18);
}

.platform-pill {
  min-width: 8.75rem;
  padding: 0.45rem 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
  color: #fff;
  font-size: clamp(0.76rem, 1.2vw, 0.98rem);
  font-weight: 800;
  letter-spacing: 0;
  text-align: center;
  text-transform: uppercase;
}

.live-dot {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 16px rgba(82, 214, 184, 0.82);
}

.live-dot.is-error {
  background: var(--danger);
  box-shadow: 0 0 16px rgba(241, 111, 111, 0.7);
}

.flap-window {
  margin: clamp(0.85rem, 2vw, 1.4rem) 0;
  padding: clamp(0.58rem, 1.4vw, 1rem);
  border-radius: calc(var(--radius) + 2px);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.58), rgba(0, 0, 0, 0.78));
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: inset 0 18px 38px rgba(0, 0, 0, 0.78);
}

.flap-row {
  display: grid;
  grid-template-columns: repeat(var(--digit-count), minmax(0, 1fr));
  gap: clamp(0.28rem, 0.85vw, 0.8rem);
  align-items: stretch;
}

.digit-card {
  position: relative;
  min-width: 0;
  aspect-ratio: 0.66;
  border-radius: calc(var(--radius) - 1px);
  overflow: hidden;
  perspective: 740px;
  background: var(--flap-b);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 12px 22px rgba(0, 0, 0, 0.42);
}

.digit-half,
.digit-flip {
  position: absolute;
  left: 0;
  right: 0;
  display: grid;
  place-items: center;
  height: 50%;
  overflow: hidden;
  color: var(--digit);
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.035), transparent),
    linear-gradient(180deg, var(--flap-a), var(--flap-b));
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: clamp(2.8rem, 12vw, 11.5rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.45);
  user-select: none;
}

.digit-half::after,
.digit-flip::after {
  content: attr(data-value);
  transform: translateY(var(--offset));
}

.digit-top,
.digit-flip-top {
  top: 0;
  align-items: end;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  --offset: 25%;
}

.digit-bottom,
.digit-flip-bottom {
  bottom: 0;
  align-items: start;
  border-top: 1px solid rgba(0, 0, 0, 0.8);
  --offset: -25%;
}

.digit-card::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: calc(50% - 1px);
  height: 2px;
  background: rgba(0, 0, 0, 0.82);
  box-shadow: 0 -1px 0 rgba(255, 255, 255, 0.08), 0 1px 0 rgba(255, 255, 255, 0.05);
  z-index: 5;
}

.digit-flip {
  z-index: 4;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  opacity: 0;
}

.digit-card.is-flipping .digit-flip {
  opacity: 1;
}

.digit-card.is-flipping .digit-flip-top {
  transform-origin: bottom;
  animation: flipTop 280ms cubic-bezier(0.32, 0.02, 0.56, 0.98) forwards;
}

.digit-card.is-flipping .digit-flip-bottom {
  transform-origin: top;
  transform: rotateX(90deg);
  animation: flipBottom 280ms 250ms cubic-bezier(0.18, 0.64, 0.35, 1) forwards;
}

@keyframes flipTop {
  to {
    transform: rotateX(-90deg);
  }
}

@keyframes flipBottom {
  to {
    transform: rotateX(0);
  }
}

.device-footer {
  min-height: clamp(2.9rem, 5vw, 5rem);
}

.follow-copy,
.handle {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1;
  letter-spacing: 0;
}

.follow-copy {
  color: rgba(255, 255, 255, 0.86);
  font-size: clamp(1rem, 2.2vw, 2rem);
  font-weight: 900;
  text-transform: uppercase;
}

.handle {
  color: #fff;
  font-size: clamp(1.2rem, 3vw, 2.7rem);
  font-weight: 900;
  text-align: right;
}

.display-actions {
  position: fixed;
  left: clamp(1rem, 2vw, 1.5rem);
  bottom: clamp(1rem, 2vw, 1.5rem);
  display: flex;
  gap: 0.5rem;
  align-items: center;
  z-index: 30;
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(390px, calc(100vw - 1rem));
  max-height: 100svh;
  overflow: auto;
  padding: 1rem;
  background: var(--panel);
  border-left: 1px solid var(--line);
  backdrop-filter: blur(18px);
  transform: translateX(0);
  transition: transform 180ms ease, opacity 180ms ease;
  z-index: 40;
}

.settings-panel:not(.is-open) {
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
  margin-bottom: 1rem;
}

.panel-header h1 {
  margin: 0;
  font-size: 1.4rem;
  line-height: 1.1;
}

.panel-header p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.control-form {
  display: grid;
  gap: 0.8rem;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
}

legend {
  padding: 0 0.35rem;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}

label {
  display: grid;
  gap: 0.4rem;
  min-width: 0;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 760;
}

label + label,
.inline-grid,
.api-controls,
.theme-grid,
.toggle-row {
  margin-top: 0.72rem;
}

input,
select {
  width: 100%;
  min-height: 2.55rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  padding: 0.55rem 0.68rem;
  color: var(--text);
  background: rgba(0, 0, 0, 0.36);
  outline: none;
}

input:focus,
select:focus,
button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(82, 214, 184, 0.18);
}

.inline-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(5.5rem, 0.38fr);
  gap: 0.65rem;
}

.stepper,
.panel-actions,
.theme-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.stepper {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 0.7rem;
}

.stepper button,
.text-button,
.icon-button {
  min-height: 2.55rem;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--text);
  background: rgba(255, 255, 255, 0.09);
  cursor: pointer;
  transition: transform 130ms ease, background 130ms ease, border-color 130ms ease;
}

.stepper button:hover,
.text-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.14);
}

.text-button.primary,
.icon-button.primary {
  color: #071512;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 900;
}

.text-button.primary:hover,
.icon-button.primary:hover {
  background: #6fe3ca;
}

.icon-button {
  width: 2.55rem;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 1.25rem;
}

.icon-button.ghost {
  background: transparent;
}

.display-actions .text-button {
  padding: 0 0.8rem;
  backdrop-filter: blur(12px);
}

.display-actions .icon-button {
  backdrop-filter: blur(12px);
}

.theme-option {
  position: relative;
  display: grid;
  grid-template-columns: 1.6rem minmax(0, 1fr);
  align-items: center;
  gap: 0.5rem;
  min-height: 2.7rem;
  padding: 0.55rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.22);
  color: var(--text);
  cursor: pointer;
}

.theme-option input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.theme-option:has(input:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(82, 214, 184, 0.15);
}

.theme-swatch {
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.theme-swatch.walnut {
  background: linear-gradient(135deg, #c39761, #111);
}

.theme-swatch.graphite {
  background: linear-gradient(135deg, #889097, #0c1012);
}

.theme-swatch.studio {
  background: linear-gradient(135deg, #52d6b8, #e35f9f 52%, #111);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.toggle-row input {
  width: 1.35rem;
  min-height: 1.35rem;
  accent-color: var(--accent);
}

.api-controls {
  display: none;
}

.api-controls.is-visible {
  display: block;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 5.2rem;
  max-width: min(30rem, calc(100vw - 2rem));
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius);
  color: #08110f;
  background: var(--accent);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, 1rem);
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
  z-index: 80;
  font-weight: 800;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

body.theme-graphite {
  --wood-a: #858d95;
  --wood-b: #3c4349;
  --wood-c: #15191d;
  --accent: #8bd3ff;
  --accent-strong: #53aee2;
}

body.theme-studio {
  --wood-a: #52d6b8;
  --wood-b: #37556d;
  --wood-c: #e35f9f;
  --accent: #ffe168;
  --accent-strong: #e7bf24;
}

body.is-display-clean .display-actions,
body.is-display-clean .settings-panel {
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app {
    display: block;
    min-height: 100svh;
  }

  .display-stage {
    min-height: 100svh;
    padding: 1rem;
  }

  .settings-panel {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: auto;
    max-height: min(82svh, 680px);
    border-left: 0;
    border-top: 1px solid var(--line);
    transform: translateY(0);
    border-radius: 14px 14px 0 0;
  }

  .settings-panel:not(.is-open) {
    transform: translateY(100%);
  }

  .display-actions {
    left: 50%;
    transform: translateX(-50%);
    width: min(100% - 1.5rem, 32rem);
    justify-content: center;
  }
}

@media (max-width: 650px) {
  .ticker-device {
    padding: 0.85rem;
  }

  .device-topbar,
  .device-footer {
    gap: 0.65rem;
  }

  .device-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .handle {
    text-align: left;
    font-size: clamp(1.1rem, 9vw, 2.2rem);
  }

  .follow-copy {
    font-size: clamp(0.9rem, 5.5vw, 1.45rem);
  }

  .platform-pill {
    min-width: 0;
    max-width: 52vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .flap-row {
    gap: 0.22rem;
  }

  .digit-half,
  .digit-flip {
    font-size: clamp(2rem, 15vw, 5.6rem);
  }

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

  .theme-grid,
  .panel-actions {
    grid-template-columns: 1fr;
  }

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

  .display-actions .text-button {
    flex: 1;
    padding: 0 0.55rem;
  }
}

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