:root {
  --paper: #efe9dc;
  --ink: #2b2a27;
  --muted: #77736a;
  --panel: rgba(250, 247, 240, 0.92);
  --rule: #cfc7b5;
  --accent: #8a5a2b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  overflow: hidden;
}

#stage { position: relative; width: 100vw; height: 100vh; user-select: none; touch-action: none; }
#world { display: block; width: 100%; height: 100%; }

#hud {
  position: absolute; top: 16px; left: 16px;
  background: var(--panel); border: 1px solid var(--rule);
  padding: 10px 14px; font: 13px/1.6 ui-monospace, Consolas, monospace;
  min-width: 210px;
}
#hud div { display: flex; justify-content: space-between; gap: 16px; }
#hud .k { color: var(--muted); }

#thought {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  width: min(580px, calc(100vw - 600px));
  background: var(--panel); border: 1px solid var(--rule); color: var(--ink);
  padding: 12px 18px;
  font-style: italic; font-size: 19px; line-height: 1.45; text-align: center;
  opacity: 0; transition: opacity 1.2s; pointer-events: none;
}
#thought.show { opacity: 1; }
#thought[data-label]:not([data-label=""])::before {
  content: attr(data-label); display: block; margin-bottom: 4px;
  font: 11px ui-monospace, Consolas, monospace; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--accent); font-style: normal;
}

#toasts { position: absolute; top: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; width: 260px; }
.toast {
  background: var(--panel); border: 1px solid var(--rule); padding: 8px 12px;
  font-size: 14px; animation: fade 7s forwards;
}
.toast .from { font: 11px ui-monospace, Consolas, monospace; color: var(--muted); text-transform: uppercase; }
@keyframes fade { 0% { opacity: 0; } 6% { opacity: 1; } 85% { opacity: 1; } 100% { opacity: 0; } }

/* The player: a generic white MP3 player with a click wheel, earbud cord trailing off the top. */
#radio {
  --body: #f1f0ec; --body-edge: #cfccc4; --lcd: #c9d1c0; --lcd-ink: #26302a; --lcd-dim: #55615a;
  position: absolute; right: 24px; bottom: 16px; width: 250px;
  padding: 14px 14px 10px;
  background: linear-gradient(160deg, #fbfaf7, var(--body) 55%, #e4e2dc);
  border: 1px solid var(--body-edge); border-radius: 22px;
  box-shadow: 0 6px 16px rgba(40, 36, 28, 0.18), inset 0 1px 0 #fff;
  user-select: none;
}
#radio .cord {
  position: absolute; left: 34px; top: -60px; width: 4px; height: 62px;
  background: #fbfaf7; border: 1px solid var(--body-edge); border-bottom: none; border-radius: 3px 3px 0 0;
}
#radio .screen {
  background: var(--lcd); color: var(--lcd-ink);
  border: 2px solid #9fa79a; border-radius: 6px;
  height: 152px; padding: 6px 9px; overflow: hidden;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.18);
  font-family: Verdana, Geneva, sans-serif;
}
#radio .bar {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 10px; font-weight: bold; border-bottom: 1px solid #9fa79a; padding-bottom: 3px; margin-bottom: 5px;
}
#radio .battery { width: 20px; height: 9px; border: 1px solid var(--lcd-ink); border-radius: 1px; padding: 1px; position: relative; }
#radio .battery::after { content: ''; position: absolute; right: -3px; top: 2px; width: 2px; height: 3px; background: var(--lcd-ink); }
#r-battery { display: block; height: 100%; width: 100%; background: var(--lcd-ink); }
#r-station { font-weight: bold; font-size: 12px; }
#r-sub { color: var(--lcd-dim); font-size: 10px; margin-bottom: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#r-line { font-size: 11px; line-height: 1.35; }
#r-line .who { font-size: 9px; font-weight: bold; text-transform: uppercase; margin-right: 5px; color: var(--lcd-dim); }
#r-list { list-style: none; margin: 0; padding: 0; font-size: 11px; }
#r-list li { padding: 3px 6px; cursor: pointer; display: flex; justify-content: space-between; }
#r-list li.on { background: var(--lcd-ink); color: var(--lcd); }

#radio .wheel {
  position: relative; width: 150px; height: 150px; margin: 14px auto 6px; border-radius: 50%;
  background: radial-gradient(circle, #fdfcfa 0 60%, #ebe9e3 100%);
  border: 1px solid var(--body-edge);
}
#radio .wheel button {
  position: absolute; background: none; border: none; cursor: pointer;
  color: #9a978f; font: bold 11px Verdana, Geneva, sans-serif; letter-spacing: 0.05em; padding: 6px;
}
#radio .wheel button:hover { color: #55524b; }
#radio .w-menu { top: 8px; left: 50%; transform: translateX(-50%); }
#radio .w-play { bottom: 6px; left: 50%; transform: translateX(-50%); font-size: 10px; }
#radio .w-prev { left: 6px; top: 50%; transform: translateY(-50%); font-size: 10px; }
#radio .w-next { right: 6px; top: 50%; transform: translateY(-50%); font-size: 10px; }
#radio .w-center {
  left: 50% !important; top: 50%; transform: translate(-50%, -50%);
  width: 54px; height: 54px; border-radius: 50%;
  background: linear-gradient(160deg, #f6f5f1, #e2e0d9) !important; border: 1px solid var(--body-edge) !important;
}
#radio .model { text-align: center; font: 8px Verdana, Geneva, sans-serif; letter-spacing: 0.15em; color: #a9a69e; }

.overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(239, 233, 220, 0.88); padding: 16px;
}
.overlay[hidden] { display: none; }
.card { max-width: 560px; background: var(--paper); border: 1px solid var(--rule); padding: 28px 32px; }
.card h1 { margin: 0 0 6px; letter-spacing: 0.3em; font-size: 28px; }
.lede { color: var(--muted); margin-top: 0; }
.settings { border-collapse: collapse; font-size: 14px; margin: 16px 0; }
.settings td { padding: 6px 12px 6px 0; vertical-align: top; border-top: 1px solid var(--rule); }
.settings td:first-child { color: var(--muted); white-space: nowrap; }
.settings label { margin-right: 12px; }
.go {
  font-weight: bold; font-size: 22px; text-align: center;
  margin: 22px 0 10px; padding: 14px 12px;
  border: 2px solid var(--ink);
  animation: nudge 2.6s ease-in-out infinite;
}
.go kbd { font-size: 17px; padding: 2px 12px; border-width: 2px; }
@keyframes nudge { 50% { opacity: 0.62; } }
@media (prefers-reduced-motion: reduce) { .go { animation: none; } }
.start-over { text-align: center; font-size: 13px; color: var(--muted); margin: 0; }
.start-over a { color: var(--muted); }
#confirm-over a { color: var(--accent); }
.settings select { font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--rule); padding: 2px 4px; max-width: 100%; }
#h-saved { color: var(--muted); }
kbd { font: 12px ui-monospace, Consolas, monospace; border: 1px solid var(--rule); padding: 1px 5px; background: #fff8; }
a { color: var(--accent); }

@media (max-width: 700px), (max-height: 600px) {
  #radio { transform: scale(0.72); transform-origin: bottom right; right: 16px; }
}

@media (max-width: 700px) {
  #thought { top: 200px; width: calc(100vw - 32px); font-size: 16px; }
  #toasts { display: none; }
}
