:root {
  color-scheme: dark;
  --bg: #000000;
  --panel: #0a0a0a;
  --panel-2: #111111;
  --line: #242424;
  --line-strong: #444444;
  --ink: #ffffff;
  --muted: #888888;
  --accent: #ffffff;
  --accent-ink: #000000;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body, #app { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
body { min-height: 100dvh; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; }
button, a, input { touch-action: manipulation; }

button {
  cursor: pointer;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 6px;
  min-height: 42px;
  padding: 9px 14px;
  transition: background .12s, border-color .12s, opacity .12s;
}
button:hover { background: #1a1a1a; border-color: var(--line-strong); }
button:active { opacity: .82; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 1.5px solid #ffffff;
  outline-offset: 2px;
}
button:disabled { cursor: not-allowed; opacity: .35; }

.primary { background: #ffffff; border-color: #ffffff; color: #000000; font-weight: 600; }
.primary:hover { background: #e5e5e5; border-color: #e5e5e5; }
.danger { background: #000000; border-color: #666666; color: #ffffff; font-weight: 600; }
.danger:hover { background: #1a1a1a; border-color: #ffffff; }
.estop-btn {
  width: 100%;
  min-height: 54px;
  font-size: .95rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  background: #ffffff;
  border: 2px solid #ffffff;
  color: #000000;
  font-weight: 800;
}
.estop-btn:hover { background: #d9d9d9; }

a { color: #ffffff; text-underline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.5rem, 4vw, 2.2rem); letter-spacing: -.03em; font-weight: 600; }
h2 { font-size: .92rem; letter-spacing: .04em; text-transform: uppercase; font-weight: 600; }
.eyebrow { font-size: .66rem; letter-spacing: .16em; font-weight: 600; text-transform: uppercase; color: var(--muted); }
.muted, .help { color: var(--muted); font-size: .8rem; line-height: 1.5; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1rem; letter-spacing: .06em; text-transform: uppercase; }
.brand-mark {
  display: inline-block; width: 20px; height: 16px;
  border: 1.5px solid #ffffff; border-radius: 3px; position: relative;
}
.brand-mark:after {
  content: ''; position: absolute; width: 2.5px; height: 6px; border-radius: 1px;
  background: #ffffff; top: 4px; left: 4px; box-shadow: 7px 0 #ffffff;
}
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 4px;
  padding: 5px 9px; font-size: .68rem; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); white-space: nowrap;
}
.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.pill.online { color: #ffffff; border-color: #ffffff; background: #141414; }
.pill.online .dot { background: #ffffff; }
.error { color: #d4d4d4; font-size: .78rem; line-height: 1.45; }
.hidden, [hidden] { display: none !important; }

.icon-btn { width: 38px; height: 38px; padding: 0; display: grid; place-items: center; flex-shrink: 0; }
.icon-btn svg { width: 16px; height: 16px; display: block; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ================= IPAD ROBOT FACE (PURE FACE ONLY) ================= */
.robot { position: fixed; inset: 0; background: #000000; overflow: hidden; display: flex; flex-direction: column; }
.face {
  position: absolute; inset: 0; display: grid; place-items: center;
  user-select: none; -webkit-user-select: none;
  transition: height .28s ease;
}
.robot.split-mode .face { height: 44%; bottom: auto; }
.face-art {
  width: min(86vw, 1200px); height: 84%; overflow: visible;
  color: #ffffff;
  transition: transform .25s ease;
}
.robot.split-mode .face-art { height: 92%; width: min(62vw, 680px); }
.eyes { transform-origin: 500px 200px; animation: blink 6.4s infinite; }
.eye { fill: currentColor; transition: transform .2s ease; }
.eye-left { transform-origin: 285px 200px; }
.eye-right { transform-origin: 715px 200px; }
.mouth {
  fill: none; stroke: currentColor; stroke-width: 22;
  stroke-linecap: round; stroke-linejoin: round; transform-origin: 500px 385px;
}

.eye-happy, .eye-love, .eye-sleepy, .eye-dizzy, .tear, .think-dots { display: none; }
.face[data-emotion=happy] .eye-normal,
.face[data-emotion=love] .eye-normal,
.face[data-emotion=sleepy] .eye-normal,
.face[data-emotion=dizzy] .eye-normal { display: none; }
.face[data-emotion=happy] .eye-happy,
.face[data-emotion=love] .eye-love,
.face[data-emotion=sleepy] .eye-sleepy,
.face[data-emotion=dizzy] .eye-dizzy { display: block; }
.face[data-emotion=thinking] .think-dots { display: block; animation: pulseDots 1.2s infinite ease-in-out; }
.face[data-emotion=thinking] .eye { transform: translate(16px, -18px) scale(.94); }

.eye-happy, .eye-sleepy, .eye-dizzy { fill: none; stroke: currentColor; stroke-width: 46; stroke-linecap: round; }
.eye-dizzy { stroke-width: 28; animation: spinDizzy 1.8s linear infinite; transform-origin: center; }
.eye-love { fill: #ffffff; }
.face[data-emotion=angry] .eye-left { transform: rotate(17deg) scaleY(.65); }
.face[data-emotion=angry] .eye-right { transform: rotate(-17deg) scaleY(.65); }
.face[data-emotion=sad] .eye-left { transform: rotate(-12deg) scaleY(.75); }
.face[data-emotion=sad] .eye-right { transform: rotate(12deg) scaleY(.75); }
.face[data-emotion=sad] .tear { display: block; fill: #d4d4d4; animation: tear 3s infinite; }
.face[data-emotion=smirk] .eye-right { transform: scaleY(.4); }
.face[data-emotion=surprised] .eye { transform: scale(1.14); }
.face.speaking .mouth { animation: talk .22s infinite alternate; }
.face.dancing .face-art { animation: dance .65s ease-in-out infinite alternate; }

/* ================= INTERACTIVE STAGE (ONLY WHEN TRIGGERED FROM /admin) ================= */
.face-stage {
  position: absolute; z-index: 6; left: 50%; transform: translateX(-50%);
  bottom: max(28px, env(safe-area-inset-bottom));
  width: min(92vw, 720px); max-height: 52dvh; overflow: auto;
  background: #0a0a0a; border: 1px solid #333333; border-radius: 10px;
  padding: 18px 20px;
}
.stage-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 8px; }
.stage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.big-choice { min-height: 56px; font-size: .95rem; font-weight: 600; background: #111111; border-color: #2c2c2c; }
.big-choice.correct { background: #ffffff; border-color: #ffffff; color: #000000; }
.big-choice.wrong { background: #1a1a1a; border-color: #666666; color: #888888; text-decoration: line-through; }

.qr-card { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; justify-content: center; }
.qr-box { width: 168px; height: 168px; background: #ffffff; border-radius: 6px; padding: 8px; display: grid; place-items: center; flex-shrink: 0; }
.qr-box img { width: 100%; height: 100%; object-fit: contain; }
.qr-copy { max-width: 340px; }
.qr-handle { font-size: 1.4rem; font-weight: 700; color: #ffffff; margin: 4px 0; }

.photo-frame {
  position: fixed; inset: 16px; z-index: 7; pointer-events: none;
  border: 2px solid #ffffff; border-radius: 8px;
  display: flex; flex-direction: column; justify-content: space-between; padding: 20px;
}
.photo-badge {
  align-self: flex-start; background: #000000; border: 1px solid #ffffff;
  color: #ffffff; padding: 6px 12px; border-radius: 4px; font-weight: 700; letter-spacing: .1em; font-size: .78rem;
}
.photo-count { align-self: center; font-size: 5rem; font-weight: 800; color: #ffffff; }
.photo-flash { position: fixed; inset: 0; z-index: 12; background: #ffffff; animation: flash .5s ease-out forwards; pointer-events: none; }

.reaction-pad { width: 100%; min-height: 130px; border-radius: 8px; font-size: 1.15rem; font-weight: 700; border: 1px solid #444; }
.reaction-pad.wait { background: #141414; border-color: #666; color: #aaa; }
.reaction-pad.go { background: #ffffff; border-color: #ffffff; color: #000000; }
.wheel-result { padding: 16px; border-radius: 6px; background: #000000; border: 1px solid #333; text-align: center; font-size: 1.1rem; font-weight: 600; color: #ffffff; margin-bottom: 10px; }

/* ================= MINIMAL START OVERLAY & HIDDEN SETTINGS DRAWER ================= */
.start-overlay {
  position: fixed; inset: 0; z-index: 20; background: #000000e8;
  display: grid; place-items: center; padding: 20px;
}
.welcome {
  width: min(360px, 100%); text-align: center; border: 1px solid #262626;
  background: #0a0a0a; border-radius: 10px; padding: 30px 24px;
}
.welcome .brand { justify-content: center; margin-bottom: 18px; }
.welcome h1 { font-size: 1.6rem; margin-bottom: 10px; }
.welcome p { margin: 0 0 20px; color: var(--muted); font-size: .84rem; line-height: 1.5; }
.welcome .primary { width: 100%; margin-bottom: 10px; }

.drawer {
  position: fixed; z-index: 15; right: 14px; top: 14px; bottom: 14px;
  width: min(390px, calc(100% - 28px)); overflow: auto;
  border: 1px solid #2a2a2a; border-radius: 8px;
  background: #080808; padding: 20px;
}
.drawer > section { padding: 16px 0; border-bottom: 1px solid #1e1e1e; }
.drawer h2 { margin-bottom: 10px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .22em; font-size: 1.7rem; color: #ffffff; margin: 8px 0; }
.field { display: grid; gap: 6px; margin: 11px 0; }
.field label, .setting { font-size: .8rem; color: #d4d4d4; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 12px 0; }
.setting input[type=checkbox] { width: 34px; height: 18px; accent-color: #ffffff; }
input[type=range] { width: 100%; accent-color: #ffffff; }
input[type=number], input[type=text], input[type=password], select, textarea {
  background: #000000; border: 1px solid #2b2b2b; border-radius: 6px;
  min-height: 40px; color: #ffffff; padding: 8px 11px; width: 100%;
}
.setting input[type=number] { width: 76px; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ================= MINIMAL BLACK & WHITE ADMIN PANEL (/admin) ================= */
.remote { max-width: 880px; margin: 0 auto; padding: 14px 14px 86px; }
.remote-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 14px;
}
.status-strip { display: flex; gap: 6px; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.card + .card { margin-top: 12px; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 8px; }
.section-title .eyebrow { font-size: .64rem; }

.tab-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 12;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  padding: 8px 10px max(10px, env(safe-area-inset-bottom));
  background: #000000; border-top: 1px solid var(--line);
}
.tab-btn {
  display: flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 6px 4px; border-radius: 6px;
  background: transparent; border: 1px solid transparent;
  color: var(--muted); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; font-weight: 600;
}
.tab-btn.active { background: #ffffff; border-color: #ffffff; color: #000000; }

/* Minimal Monochrome Joystick */
.joystick-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; margin: 10px 0; }
.joystick-pad {
  position: relative; width: 204px; height: 204px; border-radius: 50%;
  background: #050505; border: 1.5px solid #3a3a3a;
  touch-action: none; user-select: none; display: grid; place-items: center;
}
.joystick-pad:before, .joystick-pad:after { content: ''; position: absolute; background: #1e1e1e; pointer-events: none; }
.joystick-pad:before { width: 1px; height: 84%; }
.joystick-pad:after { height: 1px; width: 84%; }
.joystick-knob {
  width: 62px; height: 62px; border-radius: 50%;
  background: #ffffff; border: 2px solid #000000;
  pointer-events: none; transition: transform .04s linear;
}

.expression-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.emotion-button {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 11px 4px; font-size: .68rem; letter-spacing: .04em; text-transform: uppercase;
  background: #0d0d0d; border-color: #242424;
}
.emotion-button[aria-pressed=true] { border-color: #ffffff; background: #ffffff; color: #000000; }
.emotion-button[aria-pressed=true] .mini-face { --eye: #000000; }

.mini-face { display: block; width: 38px; height: 20px; position: relative; --eye: #ffffff; }
.mini-face:before, .mini-face:after { content: ''; position: absolute; top: 2px; width: 10px; height: 14px; background: var(--eye); border-radius: 3px; left: 4px; }
.mini-face:after { left: auto; right: 4px; }
.mini-face.happy:before, .mini-face.happy:after { height: 8px; border-radius: 8px 8px 0 0; top: 6px; }
.mini-face.angry:before { transform: rotate(-20deg); height: 10px; }
.mini-face.angry:after { transform: rotate(20deg); height: 10px; }
.mini-face.sad:before { transform: rotate(15deg); height: 12px; }
.mini-face.sad:after { transform: rotate(-15deg); height: 12px; }
.mini-face.love:before, .mini-face.love:after { clip-path: polygon(50% 100%, 0 35%, 0 15%, 25% 0, 50% 20%, 75% 0, 100% 15%, 100% 35%); }
.mini-face.smirk:after, .mini-face.sleepy:before, .mini-face.sleepy:after { height: 3px; top: 9px; }
.mini-face.surprised:before, .mini-face.surprised:after { border-radius: 50%; height: 16px; }
.mini-face.dizzy:before, .mini-face.dizzy:after { border-radius: 50%; background: transparent; border: 2.5px solid var(--eye); height: 13px; }
.mini-face.thinking:before, .mini-face.thinking:after { top: 0; height: 11px; }

.phrase-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); gap: 6px; }
.phrase-button {
  text-align: left; padding: 10px 11px; background: #0d0d0d; font-size: .76rem;
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
}
.phrase-button.selected { border-color: #ffffff; background: #ffffff; color: #000000; }

.pair-form { display: flex; gap: 8px; margin: 8px 0; }
.pair-form input { text-transform: uppercase; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .16em; min-width: 0; }
.status-box { display: flex; align-items: center; gap: 12px; margin-top: 10px; padding: 11px; border-radius: 6px; background: #000000; border: 1px solid #1f1f1f; }
.status-copy { font-size: .78rem; line-height: 1.45; }
.status-copy strong { display: block; color: #ffffff; font-weight: 600; }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat-box { background: #0a0a0a; border: 1px solid var(--line); border-radius: 6px; padding: 12px; text-align: center; }
.stat-num { font-size: 1.4rem; font-weight: 700; color: #ffffff; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.stat-lbl { font-size: .64rem; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; margin-top: 2px; }
.visitor-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 6px; background: #000000; border: 1px solid #1f1f1f; margin-top: 8px;
}
.visitor-meta { font-size: .76rem; color: var(--muted); }
.visitor-actions { display: flex; gap: 6px; flex-shrink: 0; }
.small-btn { min-height: 32px; padding: 4px 9px; font-size: .72rem; border-radius: 4px; }

.live-note { min-height: 1.2em; margin-top: 8px; font-size: .78rem; color: #d4d4d4; }
.volume-label { display: flex; justify-content: space-between; font-size: .8rem; }
.stop { width: 100%; background: #000000; margin-top: 10px; color: #ffffff; border-color: #444444; }

@keyframes blink { 0%, 43%, 47%, 93%, 97%, 100% { transform: scaleY(1); } 45%, 95% { transform: scaleY(.055); } }
@keyframes talk { from { transform: scaleY(.52); } to { transform: scaleY(1.35); } }
@keyframes tear { 0%, 15% { opacity: 0; transform: translateY(-6px); } 30% { opacity: .9; } 100% { opacity: 0; transform: translateY(70px); } }
@keyframes dance { from { transform: rotate(-4deg) translateY(-8px); } to { transform: rotate(4deg) translateY(8px); } }
@keyframes spinDizzy { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes pulseDots { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }
@keyframes flash { 0% { opacity: .95; } 100% { opacity: 0; } }

@media (max-width: 640px) {
  .expression-grid { grid-template-columns: repeat(5, 1fr); gap: 5px; }
  .emotion-button { padding: 8px 2px; font-size: .62rem; }
}
@media (orientation: portrait) {
  .robot .face-art { width: 118vw; height: 58%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *:before, *:after { animation: none !important; transition: none !important; }
}
