:root {
  color-scheme: light;
  --paper: #eee9df;
  --surface: #f8f4ec;
  --ink: #242720;
  --muted: #6b6d64;
  --line: #d2cabd;
  --accent: #9b5c32;
  --accent-dark: #754122;
  --danger: #9a3f34;
  --display: #111513;
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
}

button,
input,
textarea { font: inherit; }

.header-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 16px; }
.logout { border: 0; padding: 8px 0; background: none; color: var(--muted); cursor: pointer; }
.logout:hover { color: var(--ink); }
.login-page { display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(100%, 400px); }
.login-card h1 { margin-top: 40px; font-size: clamp(28px, 6vw, 36px); }
.login-card form { display: grid; gap: 10px; margin-top: 28px; }
.login-card label { font-size: 14px; margin-top: 8px; }
.login-card input { width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fffdf8; color: var(--ink); font-size: 16px; }
.login-card .primary { min-height: 48px; border-radius: 10px; cursor: pointer; }
.login-note { color: var(--muted); font-size: 13px; margin-top: 20px; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
canvas:focus-visible {
  outline: 3px solid rgba(155, 92, 50, 0.3);
  outline-offset: 3px;
}

.shell {
  width: min(100% - 48px, 1280px);
  margin: 0 auto;
  padding: 28px 0 56px;
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: clamp(48px, 8vw, 108px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid #bcb2a3;
  border-radius: 12px;
  background: var(--surface);
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: -0.05em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.brand strong,
.brand small { display: block; }
.brand strong { font-size: 15px; letter-spacing: -0.02em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 12px; }

.connection {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.connection span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #bd8b38;
}

.connection.ready span { background: #56845b; }
.connection.error span { background: var(--danger); }

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 0.86fr) minmax(520px, 1.14fr);
  gap: clamp(48px, 8vw, 120px);
  align-items: start;
}

.editor { max-width: 520px; }

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 { margin: 0; letter-spacing: -0.045em; }
h1 { max-width: 14ch; font-size: clamp(36px, 4vw, 58px); line-height: 0.98; }
h2 { font-size: 32px; line-height: 1; }

.intro {
  max-width: 48ch;
  margin: 24px 0 36px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.65;
}

.mode-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0 0 28px;
  padding: 0;
  border: 0;
}

.mode-picker legend { margin-bottom: 10px; font-size: 13px; font-weight: 700; }

.mode-picker label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
}

.mode-picker label:has(input:checked) { border-color: var(--accent); background: #ead9c9; }
.mode-picker input { accent-color: var(--accent-dark); }
.mode-picker strong,
.mode-picker small { display: block; }
.mode-picker strong { font-size: 13px; }
.mode-picker small { margin-top: 2px; color: var(--muted); font-size: 11px; }

.field { display: grid; gap: 9px; }
.field > label,
.section-label > span { font-size: 13px; font-weight: 700; }

textarea {
  width: 100%;
  min-height: 142px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  color: var(--ink);
  background: var(--surface);
  line-height: 1.55;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

textarea:hover:not(:disabled),
textarea:focus { border-color: #aa927c; }
textarea:disabled { opacity: 0.65; }

.field-meta,
.display-foot,
.section-label {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.field-meta,
.section-label small,
.display-foot,
.preview-note {
  color: var(--muted);
  font-size: 12px;
}

.field-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.formatting {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.screen-settings {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.screen-list { display: grid; gap: 8px; margin-top: 14px; }

.screen-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.screen-setting label { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.screen-setting input[type="checkbox"] { accent-color: var(--accent-dark); }

.screen-setting input[type="number"] {
  width: 64px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 6px;
  color: var(--ink);
  background: #fffdf8;
}

.night-setting {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 13px;
}

.night-setting label { display: flex; align-items: center; gap: 7px; }
.night-help { margin: 0; color: var(--muted); font-size: 12px; }
.night-week { width: 100%; border-collapse: collapse; }
.night-week th { text-align: left; font-size: 12px; font-weight: 500; }
.night-week abbr { display: none; text-decoration: none; }
.night-week td, .night-week th { padding: 5px 0; }
.night-week thead th { padding-bottom: 8px; color: var(--muted); }
.night-week td { text-align: right; }
.night-week thead th:not(:first-child) { text-align: right; }
.night-setting input[type="checkbox"] { accent-color: var(--accent-dark); }
.night-setting input[type="time"] {
  width: 94px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 6px;
  color: var(--ink);
  background: #fffdf8;
}

@media (max-width: 480px) {
  .night-week tbody th span { display: none; }
  .night-week abbr { display: inline; }
}

.save-screens { min-height: 40px; margin-top: 12px; padding: 0 14px; border-radius: 10px; cursor: pointer; }
.save-screens:disabled { cursor: not-allowed; opacity: 0.42; }

.words,
.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.words { margin-top: 14px; }
.palette { margin-top: 18px; }

.word,
.swatch {
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.word {
  border-radius: 999px;
  padding: 7px 11px;
  color: var(--ink);
  font-size: 13px;
}

.word.selected {
  border-color: var(--accent);
  background: #ead9c9;
}

.swatch {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.swatch[aria-checked="true"] {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink);
}

.word:active,
.swatch:active,
.actions button:active { transform: translateY(1px) scale(0.98); }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 30px;
}

.actions button {
  min-height: 44px;
  border-radius: 12px;
  padding: 0 17px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.actions button:disabled { cursor: not-allowed; opacity: 0.42; }
.primary { border: 1px solid var(--accent-dark); color: #fffaf4; background: var(--accent-dark); }
.primary:hover:not(:disabled) { background: #61351e; }
.secondary { border: 1px solid var(--line); color: var(--ink); background: transparent; }
.secondary:hover:not(:disabled) { border-color: #a79c8e; background: rgba(248, 244, 236, 0.55); }

.status { min-height: 20px; margin: 14px 0 0; color: var(--muted); font-size: 13px; }
.status.success { color: #47744c; }
.status.error { color: var(--danger); }

.preview-section { position: sticky; top: 28px; }
.preview-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 20px; }
.preview-heading > span { color: var(--muted); font: 12px ui-monospace, "SFMono-Regular", Consolas, monospace; }

.display-frame {
  border: 1px solid #c9c0b3;
  border-radius: 28px;
  padding: clamp(16px, 2.8vw, 30px);
  background: #dad2c6;
  box-shadow: 0 30px 70px rgba(71, 59, 43, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.display-bezel {
  position: relative;
  overflow: hidden;
  aspect-ratio: 2 / 1;
  border: 12px solid #292d29;
  border-radius: 12px;
  background: var(--display);
  box-shadow: inset 0 0 0 1px #454b45, inset 0 6px 20px rgba(17, 21, 19, 0.8);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.preview-loading {
  position: absolute;
  inset: 0;
  background: #171b18;
  opacity: 1;
  transition: opacity 220ms ease;
}

.preview-loading::after {
  content: "";
  position: absolute;
  inset: 20% 12%;
  background: #202520;
  animation: breathe 1.2s ease-in-out infinite alternate;
}

.preview-loading.done { pointer-events: none; opacity: 0; }

@keyframes breathe {
  from { opacity: 0.45; transform: scaleX(0.97); }
  to { opacity: 0.9; transform: scaleX(1); }
}

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

.display-foot { margin-top: 12px; font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; }
.preview-note { max-width: 52ch; margin: 18px 2px 0; line-height: 1.55; }

@media (max-width: 860px) {
  .shell { width: min(100% - 32px, 680px); padding-top: 18px; }
  .masthead { margin-bottom: 52px; }
  .workspace { grid-template-columns: 1fr; gap: 64px; }
  .editor { max-width: none; }
  .preview-section { position: static; }
  h1 { max-width: 16ch; }
}

@media (max-width: 480px) {
  .connection { font-size: 0; }
  .display-frame { padding: 12px; border-radius: 20px; }
  .display-bezel { border-width: 7px; border-radius: 8px; }
  .preview-heading { align-items: start; }
  .preview-heading > span { white-space: nowrap; text-align: right; }
  .actions { display: grid; grid-template-columns: 1fr; }
  .mode-picker { grid-template-columns: 1fr; }
}
