:root {
  --bg: #F3FAF9;
  --surface: #FFFFFF;
  --surface-2: #E2F2EF;
  --text: #0B2F2C;
  --text-muted: #3F5F5B;
  --border: #CDE5E1;
  --primary: #0F766E;
  --primary-hover: #115E59;
  --on-primary: #FFFFFF;
  --accent: #C2410C;
  --accent-hover: #9A3412;
  --on-accent: #FFFFFF;
  --danger: #B91C1C;
  --on-danger: #FFFFFF;
  --live: #C2261B;
  --warning-bg: #FEF3C7;
  --warning-text: #78350F;
  --focus: #1D4ED8;
  --shadow: 0 1px 2px rgb(11 47 44 / 6%), 0 8px 24px rgb(11 47 44 / 8%);
  --radius: 18px;
  --radius-sm: 12px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --font: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --fs-body: 1.125rem;
  --fs-small: 1rem;
  --fs-h1: clamp(1.75rem, 1.2rem + 2.4vw, 2.5rem);
  --fs-h2: clamp(1.35rem, 1.1rem + 1vw, 1.75rem);
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #071A19;
    --surface: #0D2624;
    --surface-2: #143533;
    --text: #E6F6F3;
    --text-muted: #A7C9C4;
    --border: #23504C;
    --primary: #2DD4BF;
    --primary-hover: #5EEAD4;
    --on-primary: #042F2E;
    --accent: #FB923C;
    --accent-hover: #FDBA74;
    --on-accent: #431407;
    --danger: #F87171;
    --on-danger: #2B0A0A;
    --live: #F87171;
    --warning-bg: #422006;
    --warning-text: #FDE68A;
    --focus: #93C5FD;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 35%);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 var(--space-3); text-wrap: balance; }
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: 1.2rem; }
p { margin: 0 0 var(--space-3); }
a { color: var(--primary); text-underline-offset: 3px; }
img { max-width: 100%; display: block; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 6px; }

.skip-link { position: absolute; left: var(--space-3); top: -60px; padding: var(--space-2) var(--space-4); background: var(--surface); border-radius: var(--radius-sm); z-index: 100; }
.skip-link:focus { top: var(--space-3); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.wrap { width: 100%; max-width: 760px; margin: 0 auto; padding: var(--space-5) var(--space-4) var(--space-7); }
.wrap-wide { max-width: 1180px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  padding-top: max(var(--space-3), env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}

.brand { display: flex; align-items: center; gap: var(--space-2); font-weight: 700; font-size: 1.2rem; color: var(--text); text-decoration: none; }
.brand-mark { width: 36px; height: 36px; flex: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-5);
}
.card + .card, .stack > * + * { margin-top: var(--space-4); }

.muted { color: var(--text-muted); }
.small { font-size: var(--fs-small); }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.row-between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }

.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-bg-hover: color-mix(in srgb, var(--surface-2) 80%, var(--text) 8%);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 48px; padding: 8px var(--space-5);
  line-height: 1.25; text-align: center;
  border: 1px solid transparent; border-radius: 999px;
  background: var(--btn-bg); color: var(--btn-fg);
  font: inherit; font-weight: 700; text-decoration: none;
  cursor: pointer; user-select: none;
  transition: background-color 160ms var(--ease), transform 120ms var(--ease), box-shadow 160ms var(--ease);
  touch-action: manipulation;
}
.btn:hover { background: var(--btn-bg-hover); }
.btn:active { transform: scale(.97); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn svg { width: 22px; height: 22px; flex: none; }
.btn-primary { --btn-bg: var(--primary); --btn-fg: var(--on-primary); --btn-bg-hover: var(--primary-hover); }
.btn-accent { --btn-bg: var(--accent); --btn-fg: var(--on-accent); --btn-bg-hover: var(--accent-hover); }
.btn-danger { --btn-bg: var(--danger); --btn-fg: var(--on-danger); --btn-bg-hover: color-mix(in srgb, var(--danger) 85%, black); }
.btn-ghost { --btn-bg: transparent; border-color: var(--border); }
.btn-sm { min-height: 44px; padding: 6px var(--space-4); font-size: var(--fs-small); }
.btn-icon { width: 48px; padding: 0; }
.btn-block { width: 100%; }

.btn-join {
  width: 100%; min-height: 84px; font-size: 1.6rem; border-radius: 24px;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 40%, transparent);
}
.btn-join svg { width: 34px; height: 34px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--text);
  font-size: .95rem; font-weight: 700; white-space: nowrap;
}
.badge-live { background: var(--live); color: #fff; }
.badge-live::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; animation: pulse 1.4s ease-in-out infinite; }
.badge-ok { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--text); }

@keyframes pulse { 50% { opacity: .35; } }

.hello { margin: var(--space-5) 0 var(--space-5); }
.hello h1 { margin-bottom: var(--space-2); }

.event-card { overflow: hidden; padding: 0; }
.event-cover { aspect-ratio: 16 / 7; background: var(--surface-2) center / cover no-repeat; }
.event-body { padding: var(--space-5); }
.event-when { font-weight: 700; color: var(--primary); }

.countdown { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-2); margin: var(--space-4) 0; }
.countdown div { background: var(--surface-2); border-radius: var(--radius-sm); padding: var(--space-3) var(--space-1); text-align: center; }
.countdown strong { display: block; font-size: 1.9rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.countdown span { font-size: .95rem; color: var(--text-muted); }

.live-card { border: 3px solid var(--accent); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) 0; border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }

.replay { display: grid; grid-template-columns: 96px 1fr; gap: var(--space-3); align-items: center; width: 100%; text-align: left; background: none; border: 0; color: inherit; font: inherit; cursor: pointer; padding: var(--space-2); border-radius: var(--radius-sm); }
.replay:hover { background: var(--surface-2); }
.replay-thumb { width: 96px; aspect-ratio: 16 / 10; border-radius: 10px; background: var(--surface-2) center / cover; display: grid; place-items: center; color: var(--primary); }
.replay-thumb svg { width: 32px; height: 32px; }

.notice { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-4); border-radius: var(--radius-sm); background: var(--warning-bg); color: var(--warning-text); }
.notice svg { flex: none; width: 24px; height: 24px; margin-top: 2px; }

.room {
  position: fixed; inset: 0; z-index: 50; background: #000;
  display: grid; grid-template-rows: auto 1fr;
}
.room-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-2) var(--space-3); padding-top: max(var(--space-2), env(safe-area-inset-top)); background: #111; color: #fff; }
.room-stage { position: relative; min-height: 0; }
.room-frame { position: absolute; inset: 0; border: 0; }
.room-flip {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%); z-index: 5;
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1px solid rgb(255 255 255 / 35%);
  background: rgb(0 0 0 / 55%); color: #fff;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  cursor: pointer; touch-action: manipulation;
  transition: background-color 160ms var(--ease), transform 120ms var(--ease);
}
.room-flip:hover { background: rgb(0 0 0 / 70%); }
.room-flip:active { transform: translateX(-50%) scale(.92); }
.room-flip[disabled] { opacity: .5; }
.room-flip svg { width: 26px; height: 26px; }
.room-frame iframe { width: 100%; height: 100%; border: 0; display: block; }

.player { width: 100%; border-radius: var(--radius-sm); background: #000; aspect-ratio: 16 / 9; }

.field { display: grid; gap: var(--space-1); margin-bottom: var(--space-4); }
.field label, .label { font-weight: 700; }
.field .hint { font-size: var(--fs-small); color: var(--text-muted); }
.field .error { font-size: var(--fs-small); color: var(--danger); font-weight: 700; }
input[type="text"], input[type="email"], input[type="password"], input[type="datetime-local"], input[type="number"], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 96px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; border-color: transparent; }

.check { display: flex; align-items: center; gap: var(--space-3); min-height: 44px; cursor: pointer; }
.check input { width: 24px; height: 24px; accent-color: var(--primary); flex: none; }

fieldset > .switch { display: flex; }
.switch { position: relative; display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; min-height: 44px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 52px; height: 30px; border-radius: 999px; background: var(--danger); position: relative; transition: background-color 160ms var(--ease); flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform 180ms var(--ease); box-shadow: 0 1px 3px rgb(0 0 0 / 30%); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(22px); }
.switch input:focus-visible + .track { outline: 3px solid var(--focus); outline-offset: 2px; }

.tabs { display: flex; gap: var(--space-1); overflow-x: auto; padding: var(--space-1); background: var(--surface-2); border-radius: 999px; margin-bottom: var(--space-5); scrollbar-width: none; }
.tabs button { flex: 1 0 auto; min-height: 44px; padding: 0 var(--space-3); font-size: var(--fs-small); border: 0; border-radius: 999px; background: transparent; color: var(--text); font: inherit; font-weight: 700; cursor: pointer; display: inline-flex; gap: var(--space-2); align-items: center; justify-content: center; }
.tabs button svg { width: 20px; height: 20px; }
@media (max-width: 480px) { .tabs button svg { display: none; } }
.tabs button[aria-selected="true"] { background: var(--surface); box-shadow: var(--shadow); color: var(--primary); }

.modal-bg {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center; padding: var(--space-4);
  background: rgb(7 26 25 / 50%);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade-in 160ms var(--ease);
}
.modal { width: 100%; max-width: 560px; max-height: calc(100dvh - 32px); overflow: auto; background: var(--surface); border-radius: var(--radius); padding: var(--space-5); box-shadow: 0 20px 60px rgb(0 0 0 / 30%); animation: rise 200ms var(--ease); }
.modal h2 { margin-bottom: var(--space-4); }
.modal-actions { display: flex; gap: var(--space-3); justify-content: flex-end; flex-wrap: wrap; margin-top: var(--space-5); }

@keyframes fade-in { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.toast-zone { position: fixed; left: 50%; bottom: max(var(--space-5), env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 90; display: grid; gap: var(--space-2); width: min(92vw, 460px); }
.toast { padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-weight: 700; animation: rise 200ms var(--ease); }
.toast-error { background: var(--danger); color: var(--on-danger); }

.lang-switch { min-height: 44px; }

.empty { text-align: center; padding: var(--space-6) var(--space-4); color: var(--text-muted); }
.empty svg { width: 48px; height: 48px; margin: 0 auto var(--space-3); color: var(--primary); }

.qr { display: grid; place-items: center; padding: var(--space-4); background: #fff; border-radius: var(--radius-sm); }
.qr svg, .qr img { width: 240px; height: 240px; }

.link-box { display: flex; gap: var(--space-2); align-items: center; padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3); border: 1.5px dashed var(--border); border-radius: var(--radius-sm); font-size: var(--fs-small); word-break: break-all; }

.share-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-2); }

.meter { height: 12px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.meter.warn > span { background: var(--danger); }

.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--text-muted); }
.status-dot.on { background: var(--accent); }

.icon { width: 22px; height: 22px; flex: none; }

.splash { min-height: 70dvh; display: grid; place-items: center; text-align: center; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--surface-2); border-top-color: var(--primary); animation: spin 900ms linear infinite; margin: 0 auto var(--space-4); }
@keyframes spin { to { transform: rotate(360deg); } }

.studio-stage {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  background: #000; border-radius: var(--radius-sm); overflow: hidden;
  touch-action: none; user-select: none;
  background-image: linear-gradient(rgb(255 255 255 / 6%) 1px, transparent 1px), linear-gradient(90deg, rgb(255 255 255 / 6%) 1px, transparent 1px);
  background-size: 10% 10%;
}
.studio-item {
  position: absolute; box-sizing: border-box;
  border: 2px solid rgb(255 255 255 / 70%); border-radius: 6px;
  background: color-mix(in srgb, var(--primary) 45%, #000);
  cursor: grab; touch-action: none;
}
.studio-item:active { cursor: grabbing; }
.studio-item.is-selected { border-color: #FB923C; box-shadow: 0 0 0 2px #FB923C; }
.studio-item.is-missing { background: repeating-linear-gradient(45deg, #2a2a2a 0 8px, #333 8px 16px); }
.studio-item:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.studio-name { position: absolute; left: 6px; top: 4px; right: 22px; color: #fff; font-size: .8rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 2px #000; pointer-events: none; }
.studio-handle { position: absolute; right: -2px; bottom: -2px; width: 22px; height: 22px; cursor: nwse-resize; background: linear-gradient(135deg, transparent 50%, #FB923C 50%); border-bottom-right-radius: 6px; }
.studio-empty { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: #A7C9C4; font-size: .95rem; text-align: center; padding: 12px; }

.regie-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: var(--space-4); padding: var(--space-4); min-height: calc(100dvh - 70px); }
@media (max-width: 900px) { .regie-grid { grid-template-columns: 1fr; } }

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

@media (min-width: 720px) {
  .wrap { padding-top: var(--space-6); }
}
