:root {
  --paper: #f7f3e9;
  --surface: #fffdf8;
  --ink: #17313a;
  --muted: #62747a;
  --line: #d9d5c9;
  --blue: #287a8b;
  --blue-soft: #e5f2f3;
  --coral: #de654f;
  --coral-soft: #faebe6;
  --green: #257a57;
  --green-soft: #e8f5ee;
  --yellow: #f2c85b;
  --shadow: 0 12px 28px rgba(23, 49, 58, 0.08);
  font-family: "Yu Gothic UI", "Noto Sans JP", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--paper); }
button, input, select { font: inherit; color: inherit; }
button, a, select, input { outline-offset: 3px; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible {
  outline: 3px solid #e3a428;
}

.topbar {
  min-height: 78px;
  padding: 14px clamp(16px, 3vw, 42px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.96);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { margin: 0; font-size: clamp(1.25rem, 2vw, 1.75rem); }
.eyebrow {
  margin: 0 0 2px;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--blue);
}
nav { display: flex; align-items: center; gap: 14px; }
nav a { color: var(--ink); font-weight: 700; text-decoration: none; }
.save-state {
  border: 1px solid #b9d8d7;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 0.78rem;
  background: var(--blue-soft);
  color: #1c636f;
}

.shell {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(420px, 1fr) minmax(300px, 380px);
  gap: 18px;
  align-items: start;
}
@media (max-width: 1240px) {
  .shell { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.panel-title h2 { margin: 0; font-size: 1rem; }
.panel-title small { color: var(--muted); font-size: 0.78rem; }

.fields { display: grid; gap: 12px; }
.fields label { display: grid; gap: 5px; font-size: 0.85rem; font-weight: 700; }
.fields input[type="number"], .fields input[type="text"], .fields input:not([type]) {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  background: #fff;
  font-weight: 500;
}
.fields select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  background: #fff;
  font-weight: 500;
}
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-help { margin: 0; font-size: 0.76rem; color: var(--muted); font-weight: 500; line-height: 1.6; }
label.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 700;
}
label.check input { width: 18px; height: 18px; }

.actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.actions button, .stage-actions button {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 16px;
  background: #fff;
  font-weight: 700;
  cursor: pointer;
}
.actions button.primary, .stage-actions button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.actions button:disabled, .stage-actions button:disabled { opacity: 0.45; cursor: default; }
button.danger { color: var(--coral); border-color: #eebfb4; background: var(--coral-soft); }
button.text { border: 0; background: none; color: var(--blue); font-weight: 700; cursor: pointer; }

.condition-history { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 0.83rem; }
.condition-history .empty { list-style: none; margin-left: -20px; color: var(--muted); }
.condition-history time { color: var(--muted); margin-right: 6px; }

/* ---- 課題面 ---- */
.stage-col { display: grid; gap: 12px; }
.condition-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--blue-soft);
  border: 1px solid #b9d8d7;
  border-radius: 14px;
  padding: 10px 14px;
}
.condition-bar span { font-size: 0.75rem; color: #1c636f; font-weight: 700; display: block; }
.condition-bar strong { font-size: 1.05rem; }
.condition-bar button {
  border: 1px solid var(--blue);
  background: #fff;
  color: var(--blue);
  border-radius: 999px;
  padding: 9px 20px;
  font-weight: 800;
  cursor: pointer;
}

.trial-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.9rem;
}
.trial-toolbar strong { color: var(--blue); }
.trial-toolbar button {
  margin-left: auto;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 7px 14px;
  font-weight: 700;
  cursor: pointer;
}

.stage {
  position: relative;
  min-height: min(60vh, 520px);
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #10222a;
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
}
.stage.idle { background: #1d3540; }
.stage.waiting { background: #10222a; }
.stage.responding { background: #0d1b21; }
.stage-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  color: #cfe3e6;
  font-size: clamp(1rem, 2.4vw, 1.5rem);
  font-weight: 700;
  padding: 24px;
  pointer-events: none;
}
.wait-indicator {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  color: #7fa7b0;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.button-area { position: absolute; inset: 0; --trunk-button-size: 2.5cm; }
.hidden { display: none !important; }

.reach-button {
  position: absolute;
  width: var(--trunk-button-size, 2.5cm);
  height: var(--trunk-button-size, 2.5cm);
  border-radius: 50%;
  border: calc(var(--trunk-button-size, 2.5cm) * 0.08) solid #fff;
  background: #ff5a5f;
  box-shadow: 0 0 0 calc(var(--trunk-button-size, 2.5cm) * 0.04) rgba(0, 0, 0, 0.32),
    0 calc(var(--trunk-button-size, 2.5cm) * 0.11) calc(var(--trunk-button-size, 2.5cm) * 0.275) rgba(0, 0, 0, 0.36);
  transform: translate(-50%, -50%);
  cursor: pointer;
  padding: 0;
}
.reach-button.pressed {
  background: #ffd166;
  transform: translate(-50%, -50%) scale(1.18);
  transition: transform 0.16s ease, opacity 0.16s ease;
}
/* 全部押す設定のとき、押し終わった的は薄く残す（残りが見分けやすい） */
.reach-button.pressed.done { opacity: 0.28; transform: translate(-50%, -50%) scale(0.9); }

.stage-actions { display: flex; gap: 10px; }
.hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.4em;
}
.hint.warn { color: var(--coral); font-weight: 700; }

/* ---- 右カラム ---- */
.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.metrics div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  text-align: center;
}
.metrics span { display: block; font-size: 0.72rem; color: var(--muted); font-weight: 700; }
.metrics strong { font-size: 1.3rem; font-variant-numeric: tabular-nums; }

.table-wrap { max-height: 280px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
th, td { padding: 7px 6px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface); font-size: 0.72rem; color: var(--muted); }
td.empty, p.empty { color: var(--muted); text-align: center; padding: 14px 0; margin: 0; font-size: 0.82rem; }
tr.flying td { background: var(--coral-soft); }
tr.incomplete td { color: var(--muted); }

.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 0.82rem; }
.summary-grid > div {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}
.summary-grid span { display: block; color: var(--muted); font-size: 0.72rem; font-weight: 700; }
.summary-grid b { font-size: 1rem; font-variant-numeric: tabular-nums; }

.segments { display: grid; gap: 10px; }
.segment {
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 10px;
  padding: 10px 12px;
}
.segment h3 { margin: 0 0 5px; font-size: 0.88rem; }
.segment p { margin: 0; font-size: 0.79rem; color: var(--muted); line-height: 1.7; }

.export label { display: grid; gap: 5px; font-size: 0.82rem; font-weight: 700; }
.export select { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff; }
.export .danger { margin-top: 10px; width: 100%; border-radius: 11px; padding: 9px; font-weight: 700; cursor: pointer; }

/* ---- 条件ダイアログ ---- */
dialog {
  border: 0;
  border-radius: 18px;
  padding: 0;
  box-shadow: 0 24px 60px rgba(23, 49, 58, 0.28);
  max-width: min(680px, 94vw);
}
dialog::backdrop { background: rgba(16, 34, 42, 0.44); }
dialog form { padding: 20px; background: var(--surface); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-size: 1.1rem; }
.dialog-head button {
  border: 0;
  background: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}
dialog p { color: var(--muted); font-size: 0.83rem; margin: 8px 0 16px; }
.condition-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.condition-grid button {
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 16px 12px;
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 4px;
  min-height: 84px;
}
.condition-grid button small { color: var(--muted); font-size: 0.75rem; font-weight: 700; }
.condition-grid button strong { font-size: 1.05rem; }
.condition-grid button.active { border-color: var(--blue); background: var(--blue-soft); }

/* 全画面。iPadでネイティブ全画面が使えない時は .is-fullscreen で画面を覆う */
.stage-col:fullscreen,
.stage-col.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 60;
  width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  background: #000;
  padding: 0;
  gap: 0;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}
/* 全画面中は課題面だけ。実施者向けの操作は画面から外す */
.stage-col:fullscreen > .condition-bar,
.stage-col:fullscreen > .trial-toolbar,
.stage-col:fullscreen > .stage-actions,
.stage-col:fullscreen > .hint,
.stage-col.is-fullscreen > .condition-bar,
.stage-col.is-fullscreen > .trial-toolbar,
.stage-col.is-fullscreen > .stage-actions,
.stage-col.is-fullscreen > .hint {
  display: none;
}
.stage-col:fullscreen .stage,
.stage-col.is-fullscreen .stage {
  min-height: 0;
  height: 100%;
  border: 0;
  border-radius: 0;
}
body.fullscreen-lock { overflow: hidden; }

/* 全画面から抜ける唯一の口。子どもの目を引かないよう隅に薄く置く */
.exit-fullscreen-button {
  position: absolute;
  z-index: 30;
  top: 10px;
  left: 10px;
  display: none;
  width: 40px;
  height: 40px;
  padding: 0;
  color: rgba(255, 255, 255, 0.55);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}
.exit-fullscreen-button:hover,
.exit-fullscreen-button:focus {
  color: rgba(255, 255, 255, 0.9);
  background: rgba(0, 0, 0, 0.4);
}
.stage-col:fullscreen .exit-fullscreen-button,
.stage-col.is-fullscreen .exit-fullscreen-button {
  display: grid;
  place-items: center;
}

/* ---- ごほうび動画 ---- */
.inline-form { display: flex; gap: 8px; }
.inline-form input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  background: #fff;
  font-weight: 500;
}
.inline-form button {
  border: 1px solid var(--blue);
  background: #fff;
  color: var(--blue);
  border-radius: 10px;
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}
.inline-form button:disabled { opacity: 0.45; cursor: default; }
label.check.stack { display: grid; gap: 5px; justify-items: start; align-content: start; }
label.check.stack input { margin-top: 4px; }
.field-help.warn { color: var(--coral); font-weight: 700; }

.stage-video { position: absolute; inset: 0; background: #000; }
.stage-video iframe { width: 100%; height: 100%; border: 0; display: block; }
.stage-shade { position: absolute; inset: 0; background: #10222a; }

.trial-toast {
  position: absolute;
  top: calc(14px + var(--toast-offset, 0px));
  right: 14px;
  z-index: 20;
  max-width: 70%;
  padding: 10px 16px;
  color: #fff;
  background: rgba(13, 27, 33, .72);
  border-radius: 14px;
  text-align: right;
  pointer-events: none;
  opacity: 0;
}
.trial-toast.show { animation: trial-toast 2.5s ease forwards; }
.trial-toast strong,
.trial-toast span { display: block; }
.trial-toast strong { font-size: clamp(1rem, 2.2vw, 1.4rem); font-weight: 700; }
.trial-toast span { font-size: clamp(1.4rem, 3.4vw, 2.2rem); font-weight: 700; font-variant-numeric: tabular-nums; }
@keyframes trial-toast {
  0% { opacity: 0; transform: translateY(-6px); }
  14% { opacity: 1; transform: translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}
