/* KOKYU TRAINING — 落ち着いたダーク */
:root {
  color-scheme: dark;
  --bg: #0a0f14;
  --surface: rgba(19, 28, 37, .78);
  --surface-solid: #131c25;
  --surface-2: #19242f;
  --line: rgba(255, 255, 255, .08);
  --line-strong: rgba(255, 255, 255, .16);
  --text: #e6edf2;
  --muted: #93a2ae;
  --faint: #66737e;
  --accent: #7fcfc4;
  --accent-ink: #06231f;
  --warn: #f0b48a;
  --current: var(--accent);
  --radius: 20px;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --font-num: "SF Pro Display", "Segoe UI", "Helvetica Neue", "Roboto", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Consolas", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body:not(.controller-mode) .controller-only, body.controller-mode .receiver-only { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  background:
    radial-gradient(110% 55% at 50% -12%, rgba(64, 140, 150, .22) 0%, transparent 62%),
    radial-gradient(80% 40% at 100% 100%, rgba(40, 70, 110, .14) 0%, transparent 70%),
    var(--bg);
  background-attachment: fixed;
}

main {
  width: min(100% - 32px, 520px);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 0 max(40px, env(safe-area-inset-bottom));
}
.controller-mode main { width: min(100% - 32px, 960px); }

h2 { margin: 0 0 6px; font-size: 17px; font-weight: 600; letter-spacing: .02em; }
p { margin: 0; }
a { color: inherit; }

/* ヘッダー */
.topbar { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.wordmark { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-size: 12.5px; font-weight: 600; letter-spacing: .32em; color: var(--text); }
.mark { width: 22px; height: 22px; color: var(--accent); }
.tag { font-size: 12px; color: var(--muted); border: 1px solid var(--line-strong); border-radius: 999px; padding: 1px 10px; }
.connection { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.connection::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.connection[data-state="ok"]::before { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.connection[data-state="error"] { color: var(--warn); }
.connection[data-state="error"]::before { background: var(--warn); }

/* 現在の設定 */
.hero { display: grid; justify-items: center; gap: 18px; padding: 28px 0 18px; text-align: center; }
.controller-mode .hero { padding-top: 20px; }
.controller-mode .hero[data-connected="false"] { display: none; }
.orb {
  position: relative;
  width: min(72vw, 272px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 4px;
  border: 1px solid var(--line-strong);
  background:
    radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--current) 12%, transparent) 0%, transparent 68%),
    rgba(255, 255, 255, .015);
  box-shadow: inset 0 0 0 12px rgba(255, 255, 255, .012), inset 0 0 0 13px var(--line);
  transition: border-color .6s ease, box-shadow .6s ease;
}
.orb[data-playing="true"] {
  border-color: color-mix(in srgb, var(--current) 70%, transparent);
  box-shadow: inset 0 0 0 12px rgba(255, 255, 255, .012), inset 0 0 0 13px color-mix(in srgb, var(--current) 22%, transparent), 0 0 70px -18px var(--current);
}
.controller-mode .orb { width: min(56vw, 210px); }
.hero-label { font-size: 12px; letter-spacing: .28em; color: var(--muted); }
.hero-value { font-family: var(--font-num); font-size: clamp(76px, 23vw, 112px); font-weight: 200; line-height: 1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.controller-mode .hero-value { font-size: clamp(60px, 17vw, 84px); }
.hero-sub { font-size: 16px; font-weight: 500; color: var(--current); min-height: 1.6em; }
.hero-meta { font-size: 12.5px; color: var(--muted); min-height: 1.7em; }

.stage-meter { display: flex; align-items: flex-end; gap: 5px; width: min(100%, 300px); height: 38px; }
.stage-meter span { flex: 1; min-width: 3px; border-radius: 3px; background: rgba(255, 255, 255, .08); transition: background-color .4s ease, opacity .4s ease, box-shadow .4s ease; }
.stage-meter span.reached { background: var(--bar); opacity: .45; }
.stage-meter span.current { background: var(--bar); opacity: 1; box-shadow: 0 0 14px -2px var(--bar); }

/* パネル */
.panel { margin-top: 14px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.lead { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.hint { color: var(--faint); font-size: 12.5px; line-height: 1.65; }
.notice { min-height: 0; font-size: 13.5px; color: var(--accent); text-align: center; }
.notice:not(:empty) { margin: 4px 0 2px; }
.notice.error { color: var(--warn); }

/* フォーム */
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
label:first-child, .inline-form > label { margin-top: 0; }
input, select, textarea, button { font: inherit; }
input:not([type="range"]):not([type="radio"]), select, textarea {
  width: 100%; min-width: 0; min-height: 48px; padding: 11px 14px;
  font-size: 16px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 12px;
}
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 21px, calc(100% - 15px) 21px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 40px; }
select option { background: var(--surface-solid); }
textarea { display: block; resize: vertical; min-height: 9em; font-size: 13.5px; line-height: 1.7; color: var(--muted); }
input[readonly] { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.field-row { display: flex; gap: 10px; align-items: stretch; }
.field-row > input, .field-row > select, .field-row > .code { flex: 1; }
.inline-form + .inline-form { margin-top: 0; }

button { cursor: pointer; border-radius: 999px; min-height: 48px; padding: 0 22px; font-size: 15px; font-weight: 600; letter-spacing: .02em; white-space: nowrap; transition: background-color .2s ease, border-color .2s ease, opacity .2s ease, transform .1s ease; }
button:active:not(:disabled) { transform: scale(.98); }
button:disabled { cursor: default; opacity: .38; }
.primary { color: var(--accent-ink); background: var(--accent); border: 1px solid var(--accent); }
.primary:hover:not(:disabled) { background: #96ddd3; }
.secondary { color: var(--text); background: transparent; border: 1px solid var(--line-strong); }
.secondary:hover:not(:disabled) { border-color: var(--muted); }
.small { min-height: 48px; padding: 0 16px; font-size: 14px; }
.text-button { min-height: 44px; padding: 0; color: var(--muted); background: none; border: 0; text-decoration: underline; text-underline-offset: 4px; font-weight: 500; }

/* 音源モード切替 */
.segmented { display: flex; gap: 4px; margin: 0; padding: 4px; border: 1px solid var(--line); border-radius: 999px; background: rgba(0, 0, 0, .22); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label { flex: 1; margin: 0; min-height: 44px; display: grid; place-items: center; border-radius: 999px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; transition: background-color .25s ease, color .25s ease; }
.segmented input:checked + label { color: var(--text); background: rgba(127, 207, 196, .16); box-shadow: inset 0 0 0 1px rgba(127, 207, 196, .35); }
.segmented input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
.segmented[disabled] label, .segmented input:disabled + label { cursor: default; opacity: .5; }
#mode-hint { margin: 8px 4px 0; }

/* プリロード */
.preload { margin-top: 16px; padding: 14px 16px; border-radius: 14px; background: rgba(0, 0, 0, .2); border: 1px solid var(--line); }
.preload-head { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; }
.preload-count { color: var(--muted); font-variant-numeric: tabular-nums; }
progress { display: block; width: 100%; height: 6px; margin: 10px 0 8px; border: 0; border-radius: 999px; background: rgba(255, 255, 255, .08); overflow: hidden; appearance: none; }
progress::-webkit-progress-bar { background: rgba(255, 255, 255, .08); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; transition: width .3s ease; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
#retry-pack { margin-top: 10px; }

/* 再生 */
.transport { display: flex; gap: 10px; margin-top: 18px; }
.play { flex: 1; min-height: 56px; font-size: 16px; }
.play.playing, .play.playing:hover:not(:disabled) { color: var(--text); background: transparent; border-color: color-mix(in srgb, var(--current) 60%, transparent); }
.audio-status { margin-top: 10px; font-size: 13px; color: var(--muted); text-align: center; min-height: 1.7em; }
.volume { display: grid; grid-template-columns: auto 1fr 3.2em; align-items: center; gap: 14px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.volume label { margin: 0; }
.volume output { font-size: 13px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; min-height: 44px; margin: 0; accent-color: var(--accent); background: transparent; }

/* 参加コード・指示文 */
.code-box { padding: 14px 16px; border-radius: 14px; background: rgba(0, 0, 0, .22); border: 1px solid var(--line); }
.code-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.code { display: flex; align-items: center; min-height: 48px; font-family: var(--font-mono); font-size: 14.5px; color: var(--text); word-break: break-all; line-height: 1.5; }
.fold { margin-top: 12px; border-top: 1px solid var(--line); }
.fold summary { list-style: none; display: flex; justify-content: space-between; align-items: center; min-height: 52px; cursor: pointer; font-weight: 600; font-size: 15px; }
.fold summary::-webkit-details-marker { display: none; }
.fold summary::after { content: ""; width: 8px; height: 8px; margin-right: 4px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg); transition: transform .2s ease; }
.fold[open] summary::after { transform: rotate(-135deg); }
.fold > .hint { margin-bottom: 10px; }
.fold textarea { margin-bottom: 10px; }
.fold .field-row { margin-bottom: 4px; }
.fold > button { width: 100%; margin-bottom: 14px; }

/* 管理画面 */
.mode-note { font-size: 14px; color: var(--text); margin-bottom: 14px; padding: 10px 14px; border-radius: 12px; background: rgba(127, 207, 196, .08); border: 1px solid rgba(127, 207, 196, .2); }
.report { margin: 16px 0 6px; font-size: 13.5px; color: var(--muted); }
#controller-controls .inline-form { margin-bottom: 4px; }

.table-scroll { margin-top: 14px; overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; -webkit-overflow-scrolling: touch; }
table { width: 100%; min-width: 900px; border-collapse: collapse; font-size: 13px; line-height: 1.65; text-align: left; }
th { position: sticky; top: 0; font-weight: 500; font-size: 12px; letter-spacing: .04em; color: var(--muted); background: var(--surface-solid); white-space: nowrap; }
th, td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
td:first-child, th:first-child { position: sticky; left: 0; background: var(--surface-solid); font-variant-numeric: tabular-nums; }
td:first-child { font-weight: 600; text-align: center; }
td:nth-child(2) { font-family: var(--font-mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
td:nth-child(3) { white-space: nowrap; }
td:nth-child(5) { text-align: center; }
td:nth-child(6), td:nth-child(7) { min-width: 230px; }
tr.current-stage td { background: rgba(127, 207, 196, .1); }
tr.current-stage td:first-child { background: #1a3433; color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }

/* フッター */
.footer { margin-top: 28px; padding: 0 4px; display: grid; gap: 8px; font-size: 12px; color: var(--faint); }
.footer .text-button { justify-self: start; font-size: 13px; }

.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; }

@media (max-width: 560px) {
  #controller-join .field-row { flex-wrap: wrap; }
  #controller-join .field-row > * { flex: 1 1 100%; }
}
@media (max-width: 380px) {
  main { width: calc(100% - 24px); }
  .panel { padding: 16px; }
  .field-row { flex-wrap: wrap; }
  .field-row > button { flex: 1; }
}
@media (min-width: 760px) {
  .controller-mode main {
    display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); column-gap: 20px; align-items: start;
    grid-template-areas: "top top" "hero join" "hero controls" "notice notice" "table table" "footer footer";
  }
  .controller-mode main:has(#display[data-connected="false"]) { grid-template-areas: "top top" "join join" "notice notice" "table table" "footer footer"; }
  .controller-mode .topbar { grid-area: top; }
  .controller-mode #join-panel { grid-area: join; }
  .controller-mode .hero { grid-area: hero; align-self: center; }
  .controller-mode #controller-controls { grid-area: controls; }
  .controller-mode .notice { grid-area: notice; }
  .controller-mode #table-panel { grid-area: table; }
  .controller-mode .footer { grid-area: footer; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
