:root {
  color-scheme: dark;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  font-synthesis: none;
  --page: #111d19;
  --surface: #1a2923;
  --surface-raised: #25352e;
  --text: #f7f2e7;
  --muted: #c0c9bc;
  --border: #43524a;
  --accent: #e3b777;
  --accent-hover: #f0ce99;
  --accent-ink: #24190d;
  --danger: #ffc3af;
  --content-gap: clamp(1rem, 3vw, 2.5rem);
  background: var(--page);
  color: var(--text);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 0; min-height: 100vh; }
h1, h2, p, figure, fieldset { margin: 0; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled, fieldset:disabled button { cursor: default; }
a { color: inherit; }

:focus-visible {
  outline: 3px solid var(--accent-hover);
  outline-offset: 4px;
}

.view-label {
  color: var(--accent);
  font-size: 0.92rem;
  font-weight: 650;
  line-height: 1.5;
}

.primary-button, .secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  padding: 0.6rem 1rem;
  border: 1px solid transparent;
  border-radius: 0.35rem;
  font-weight: 700;
  text-align: center;
  transition: background-color 140ms ease, opacity 140ms ease;
}

.primary-button { background: var(--accent); color: var(--accent-ink); }
.secondary-button {
  background: var(--surface-raised);
  color: var(--text);
  border-color: var(--border);
}

button:disabled, fieldset:disabled { opacity: 0.56; }
fieldset:disabled button { opacity: 1; }

@media (hover: hover) {
  .primary-button:not(:disabled):hover { background: var(--accent-hover); }
  .secondary-button:not(:disabled):hover { background: #30453a; }
}

.home {
  position: relative;
  display: grid;
  align-items: end;
  min-height: 100vh;
  min-height: 100svh;
  overflow: hidden;
  isolation: isolate;
}

.home-landscape {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: #39493d url("/muscat.webp") center 44% / cover no-repeat;
}

.home-landscape::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(0deg, #0f1c17 2%, rgb(15 28 23 / 88%) 37%, transparent 88%);
}

.home-content {
  display: grid;
  gap: 1.75rem;
  padding: clamp(1.25rem, 6vw, 6.5rem);
  padding-block-start: min(38svh, 17rem);
  max-width: 45rem;
}

.home-copy { display: grid; gap: 0.8rem; }
.home-copy h1 {
  font-size: clamp(3rem, 9vw, 7.75rem);
  line-height: 1.05;
  font-weight: 800;
}

.home-description {
  font-size: clamp(1rem, 1.7vw, 1.3rem);
  max-width: 29rem;
  line-height: 1.7;
  color: var(--muted);
}

.host-form { display: grid; gap: 0.65rem; max-width: 24rem; }
.host-form label { font-weight: 650; }
.host-form label span { color: var(--muted); font-size: 0.875rem; font-weight: 400; }
.host-form input {
  width: 100%;
  min-height: 3rem;
  padding: 0.6rem 0.8rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.35rem;
}

.form-error { color: var(--danger); line-height: 1.6; }

@media (min-width: 48rem) {
  .home { align-items: center; }
  .home-landscape { background-position: center; }
  .home-landscape::after {
    background: linear-gradient(270deg, rgb(14 27 22 / 98%) 2%, rgb(14 27 22 / 87%) 29%, rgb(14 27 22 / 10%) 73%, transparent 100%);
  }
  .home-content { padding-block: clamp(2rem, 6vw, 6rem); }
}

.display-view {
  display: grid;
  align-content: start;
  gap: clamp(0.75rem, 2vw, 1.75rem);
  max-width: 160rem;
  min-height: 100vh;
  min-height: 100svh;
  margin-inline: auto;
  padding: clamp(1rem, 2.5vw, 2.75rem);
}

.view-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

.display-header h1 { font-size: clamp(1.55rem, 3vw, 3.3rem); line-height: 1.25; }

.connection {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.25rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.connection::before {
  content: "";
  flex: none;
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--accent);
}

.connection[data-state="connected"]::before { background: #9fd0a1; }
.connection[data-state="offline"]::before { background: var(--danger); }

.display-layout { display: grid; gap: var(--content-gap); align-items: start; }

.stage {
  position: relative;
  width: 100%;
  min-width: 0;
  aspect-ratio: 16 / 9;
  isolation: isolate;
  overflow: hidden;
  border-radius: 0.45rem;
  outline: 1px solid var(--border);
  outline-offset: -1px;
  background: #607262 url("/muscat.webp") center / 100% 100% no-repeat;
}

.stage-patches, .stage-ink {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.stage-patches { pointer-events: none; }
.stage-patches img {
  display: block;
  object-fit: fill;
  mask-image: linear-gradient(to right, transparent, #000 18%, #000 82%, transparent),
    linear-gradient(to bottom, transparent, #000 18%, #000 82%, transparent);
  mask-composite: intersect;
}
.display-stage .stage-ink { pointer-events: none; }

.pairing {
  display: grid;
  align-content: start;
  justify-items: start;
  gap: 1.1rem;
  padding: clamp(1rem, 2.2vw, 1.75rem);
  border: 1px solid var(--border);
  border-radius: 0.45rem;
  background: var(--surface);
}

.pairing-body { display: grid; gap: 0.45rem; }
.pairing-body h2 { font-size: clamp(1.35rem, 2vw, 2.15rem); line-height: 1.2; }
.pairing-body p { color: var(--muted); line-height: 1.65; }

.pairing-code {
  display: block;
  justify-self: center;
  width: min(100%, 15rem);
  aspect-ratio: 1;
  padding: 0.35rem;
  border-radius: 0.3rem;
  background: #fff;
}

.pairing-code canvas {
  display: block;
  width: 100% !important;
  height: auto !important;
  image-rendering: crisp-edges;
}

.pairing-meta { display: grid; gap: 0.75rem; width: 100%; }
.pairing-meta div {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  border-block-start: 1px solid var(--border);
  padding-block-start: 0.75rem;
}

.pairing-meta span { color: var(--muted); }
.pairing-meta bdi { font-weight: 700; overflow-wrap: anywhere; }

@media (min-width: 40rem) and (max-width: 57.99rem) {
  .pairing { grid-template-columns: minmax(0, 1fr) minmax(8rem, 12rem); }
  .pairing-code { grid-column: 2; grid-row: 1 / span 2; }
}

@media (min-width: 58rem) {
  .display-layout { grid-template-columns: minmax(0, 1fr) clamp(13rem, 21vw, 24rem); }
  .display-stage { width: min(100%, calc((100svh - 11.5rem) * 16 / 9)); }
}

.draw-view {
  display: grid;
  align-content: start;
  gap: 1.15rem;
  width: min(100%, 62rem);
  margin-inline: auto;
  padding: clamp(0.875rem, 3vw, 2rem);
}

.draw-header {
  border-block-end: 1px solid var(--border);
  padding-block-end: 0.85rem;
}

.draw-header h1 { font-size: clamp(1.35rem, 6vw, 2.45rem); line-height: 1.35; }
.drawing { display: grid; gap: 0.7rem; }
.drawing-topline h2 { font-size: 1.1rem; font-weight: 700; }
.draw-stage[data-active="true"] .stage-ink { touch-action: none; cursor: crosshair; }
.draw-stage[data-active="false"] .stage-ink { cursor: default; }
.draw-message { color: var(--muted); min-height: 1.5em; line-height: 1.5; }
.draw-message[data-state="error"] { color: var(--danger); }

.draw-tools {
  display: grid;
  gap: 0.9rem;
  min-width: 0;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.45rem;
  background: var(--surface);
}

.brush-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }
.palette { display: flex; flex-wrap: wrap; gap: 0.15rem; }
.swatch {
  display: grid;
  width: 2.5rem;
  height: 2.75rem;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 0.3rem;
  padding: 0;
  background: transparent;
}

.swatch::after {
  content: "";
  width: 1.45rem;
  height: 1.45rem;
  border: 1px solid rgb(255 255 255 / 36%);
  border-radius: 50%;
  background: var(--swatch);
}

.swatch[aria-pressed="true"], .swatch.is-selected {
  border-color: var(--accent);
  background: var(--surface-raised);
}

.swatch-ink { --swatch: #10241f; }
.swatch-red { --swatch: #b94434; }
.swatch-blue { --swatch: #315f76; }
.swatch-palm { --swatch: #607949; }
.swatch-amber { --swatch: #c38933; }
.swatch-white { --swatch: #fff; }

.brush-size {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 1 1 12rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.brush-size input {
  flex: 1 1 6rem;
  min-width: 6rem;
  max-width: 12rem;
  height: 2.75rem;
  accent-color: var(--accent);
}

.draw-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 0.5rem; }

@media (min-width: 52rem) {
  .draw-tools { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .draw-actions { grid-template-columns: auto auto; }
}

@media (min-width: 34rem) and (max-height: 34rem) and (orientation: landscape) {
  .draw-view { gap: 0.65rem; padding: 0.75rem; }
  .draw-header { padding-block-end: 0.4rem; }
  .draw-header h1 { font-size: 1.25rem; }
  .drawing { grid-template-columns: minmax(0, 1fr) minmax(11rem, 32%); }
  .drawing-topline, .draw-message { grid-column: 1 / -1; }
  .draw-stage {
    align-self: start;
    width: min(100%, calc((100svh - 8rem) * 16 / 9));
  }
  .draw-tools { grid-template-columns: 1fr; }
}

.script-message { padding: 1rem; }

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