:root {
  --bg: #f4f0e8;
  --ink: #202523;
  --muted: #68726e;
  --panel: #fffaf0;
  --line: #d8cfbd;
  --green: #21775b;
  --green-dark: #155640;
  --red: #d22d28;
  --red-dark: #a51f1b;
  --amber: #c8871f;
  --blue: #2f6f8e;
  --shadow: 0 18px 48px rgba(35, 38, 33, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family:
    "Yu Gothic UI",
    "Yu Gothic",
    "Meiryo",
    system-ui,
    sans-serif;
  background:
    linear-gradient(180deg, rgba(47, 111, 142, 0.12), transparent 34rem),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 2.4rem;
  line-height: 1.05;
  letter-spacing: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  min-height: 36px;
  padding: 8px 14px;
  color: #fff;
  background: var(--green);
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
}

.loader,
.control-panel {
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.9);
  box-shadow: var(--shadow);
}

.loader {
  padding: 14px;
  margin-bottom: 18px;
  border-radius: 8px;
}

.search-form,
.source-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 116px;
  gap: 10px;
}

.search-form {
  margin-bottom: 10px;
}

.search-form input,
.source-form input,
.admin-grid input[type="number"],
.admin-block select {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  outline: none;
}

.search-form input:focus,
.source-form input:focus,
.admin-grid input[type="number"]:focus,
.admin-block select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 111, 142, 0.18);
}

.search-form button,
.source-form button,
.button-grid button {
  min-height: 48px;
  color: #fff;
  background: var(--green);
  border-radius: 6px;
  font-weight: 700;
}

.search-form button:hover,
.source-form button:hover,
.button-grid button:hover {
  background: var(--green-dark);
}

.message {
  min-height: 22px;
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.message.error {
  color: var(--red);
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
}

.player-panel {
  min-width: 0;
}

.player-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  width: 100%;
  min-height: 270px;
  background: #111;
  border: 1px solid #151515;
  border-radius: 8px;
  box-shadow: var(--shadow);
  touch-action: manipulation;
}

#player,
#player iframe {
  width: 100%;
  height: 100%;
}

.geometry-canvas {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #080b18;
  touch-action: none;
}

.player-frame:has(.geometry-canvas:not(.hidden)) .player-shade {
  z-index: 3;
}

.player-frame.balloon-response-active .player-shade {
  pointer-events: none;
  background: transparent;
}

.geometry-option-row {
  margin-top: 12px;
}

.geometry-option-row input[type="checkbox"] {
  width: 28px;
  height: 28px;
  accent-color: var(--green);
}

.player-frame.blackout-player {
  background: #000;
}

.player-frame.blackout-player #player {
  visibility: hidden;
}

.celebration-overlay {
  position: absolute;
  z-index: 16;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  pointer-events: auto;
  background: radial-gradient(circle at center, rgba(22, 42, 76, 0.46), rgba(4, 8, 24, 0.9));
}

.celebration-message {
  position: relative;
  z-index: 2;
  padding: 0.18em 0.42em;
  color: #fff;
  font-size: clamp(3rem, 11vw, 7.5rem);
  font-weight: 950;
  line-height: 1;
  text-align: center;
  text-shadow: 0 5px 0 rgba(0, 0, 0, 0.2), 0 0 28px rgba(255, 230, 88, 0.95);
  animation: celebration-message 700ms cubic-bezier(0.2, 1.5, 0.5, 1) both;
}

.celebration-particles,
.celebration-particles span {
  position: absolute;
  inset: 0;
}

.celebration-particles span {
  left: var(--x);
  top: var(--y);
  width: 13px;
  height: 13px;
  border-radius: 999px;
  background: hsl(var(--hue) 95% 62%);
  box-shadow: 0 0 18px hsl(var(--hue) 100% 66%);
  animation-delay: var(--delay);
}

.celebration-particles.fireworks span { animation: celebration-firework 1.25s ease-out both; }
.celebration-particles.sparkles span {
  border-radius: 2px;
  transform: rotate(45deg);
  animation: celebration-sparkle 1.15s ease-in-out infinite alternate;
}
.celebration-particles.confetti span {
  width: 10px;
  height: 24px;
  border-radius: 2px;
  animation: celebration-confetti 1.7s ease-in both;
}

@keyframes celebration-message {
  0% { opacity: 0; transform: scale(0.35) rotate(-6deg); }
  70% { opacity: 1; transform: scale(1.08) rotate(2deg); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes celebration-firework {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.1); }
  30% { opacity: 1; transform: translate(-50%, -50%) scale(1.8); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
}
@keyframes celebration-sparkle {
  0% { opacity: 0.2; transform: rotate(45deg) scale(0.35); }
  100% { opacity: 1; transform: rotate(225deg) scale(1.5); }
}
@keyframes celebration-confetti {
  0% { opacity: 0; transform: translateY(-45vh) rotate(0deg); }
  12% { opacity: 1; }
  100% { opacity: 0; transform: translateY(70vh) rotate(720deg); }
}

.player-frame.is-fullscreen,
.player-frame:fullscreen {
  width: 100vw;
  height: 100vh;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: #000;
}

.player-frame.is-fullscreen #player,
.player-frame.is-fullscreen #player iframe,
.player-frame:fullscreen #player,
.player-frame:fullscreen #player iframe {
  pointer-events: none;
}

.exit-fullscreen-button {
  position: absolute;
  z-index: 20;
  top: 12px;
  left: 12px;
  display: none;
  width: 44px;
  height: 44px;
  color: rgba(255, 255, 255, 0.72);
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  font-size: 1.55rem;
  line-height: 1;
  backdrop-filter: blur(4px);
}

.exit-fullscreen-button:hover,
.exit-fullscreen-button:focus {
  color: rgba(255, 255, 255, 0.92);
  background: rgba(0, 0, 0, 0.36);
  outline: 2px solid rgba(255, 255, 255, 0.24);
  outline-offset: 2px;
}

.player-frame.is-fullscreen .exit-fullscreen-button,
.player-frame:fullscreen .exit-fullscreen-button {
  display: grid;
  place-items: center;
}

.player-shade {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #fff;
  background: rgba(7, 9, 8, 0.55);
  transition: opacity 160ms ease;
  pointer-events: auto;
}

.player-shade.hidden {
  opacity: 0;
  pointer-events: none;
}

.shade-text {
  display: inline-grid;
  place-items: center;
  min-width: 128px;
  min-height: 48px;
  padding: 10px 18px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.34);
  font-size: 1.25rem;
  font-weight: 800;
}

.reward-button {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  width: min(42vw, 300px);
  min-width: 168px;
  aspect-ratio: 1;
  color: #fff;
  background: var(--red);
  border: 8px solid rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  box-shadow:
    0 20px 56px rgba(0, 0, 0, 0.36),
    inset 0 -12px 0 rgba(0, 0, 0, 0.14);
}

.reward-button:hover,
.reward-button:focus {
  background: var(--red-dark);
  outline: 4px solid rgba(255, 255, 255, 0.44);
  outline-offset: 4px;
}

.reward-button span {
  font-weight: 900;
  line-height: 1;
}

.reward-icon {
  display: block;
  font-size: 5.6rem;
  line-height: 1;
}

#rewardButtonText {
  font-size: 2rem;
}

.voice-prompt {
  display: grid;
  gap: clamp(8px, 2vh, 14px);
  place-items: center;
  width: min(88vw, 620px);
  max-height: calc(100% - 48px);
  padding: clamp(18px, 4vw, 30px);
  background: rgba(0, 0, 0, 0.42);
  border: 4px solid rgba(255, 255, 255, 0.28);
  border-radius: 24px;
  text-align: center;
}

.voice-cue {
  position: relative;
  display: grid;
  place-items: center;
  width: min(42vw, 46vh, 320px);
  aspect-ratio: 1;
}

.voice-prompt .voice-face {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 78%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow:
    0 22px 54px rgba(0, 0, 0, 0.28),
    inset 0 -10px 0 rgba(0, 0, 0, 0.08);
  font-size: min(20vw, 22vh, 9.5rem);
  line-height: 1;
}

.voice-wave {
  position: absolute;
  inset: 10%;
  border: 9px solid rgba(255, 255, 255, 0.78);
  border-radius: 999px;
  opacity: 0;
  animation: voice-wave 1500ms ease-out infinite;
}

.wave-2 {
  animation-delay: 300ms;
}

.wave-3 {
  animation-delay: 600ms;
}

.voice-prompt #voiceTarget {
  font-size: clamp(2.4rem, 8vw, 5rem);
  line-height: 1;
  color: #fff;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.38);
}

.voice-prompt #voiceStatus {
  font-size: clamp(1.1rem, 3vw, 1.65rem);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.9);
}

.voice-prompt.voice-only {
  width: min(92vw, 680px);
}

.voice-prompt.manual-enter .voice-face {
  font-size: clamp(5.6rem, 16vw, 10rem);
}

@keyframes voice-wave {
  0% {
    opacity: 0.76;
    transform: scale(0.58);
  }
  72% {
    opacity: 0.22;
  }
  100% {
    opacity: 0;
    transform: scale(1.28);
  }
}

.action-prompt {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  overflow: hidden;
  background: #000;
}

.action-prompt-image {
  display: block;
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: contain;
  background: #000;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.action-prompt-placeholder {
  width: 100%;
  height: 100%;
  background: #000;
}

.action-image-picker {
  display: grid;
  gap: 8px;
}

.action-image-picker input {
  width: 100%;
  font-size: 0.86rem;
}

.action-image-preview-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}

.action-image-preview {
  width: 100%;
  max-height: 110px;
  object-fit: contain;
  background: #f4f5f2;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.action-image-preview-row button {
  min-height: 42px;
  padding: 0 12px;
  color: #fff;
  background: #6f3b3b;
  border: 0;
  border-radius: 6px;
  font-weight: 800;
}

.moving-button-prompt {
  position: absolute;
  inset: 0;
  overflow: hidden;
  --moving-button-size: 2cm;
}

.moving-target-button {
  position: absolute;
  width: var(--moving-button-size, 2cm);
  height: var(--moving-button-size, 2cm);
  padding: 0;
  transform: translate(-50%, -50%);
  touch-action: manipulation;
  background: var(--button-color, #f04438);
  border: calc(var(--moving-button-size, 2cm) * 0.08) solid #fff;
  border-radius: 999px;
  box-shadow:
    0 0 0 calc(var(--moving-button-size, 2cm) * 0.04) rgba(0, 0, 0, 0.32),
    0 calc(var(--moving-button-size, 2cm) * 0.11) calc(var(--moving-button-size, 2cm) * 0.275)
      rgba(0, 0, 0, 0.36);
}

.moving-target-button:active {
  transform: translate(-50%, -50%) scale(0.9);
}

.moving-target-button.bursting {
  pointer-events: none;
  animation: moving-button-burst 360ms cubic-bezier(0.2, 0.85, 0.25, 1) forwards;
}

.moving-target-button.bursting::before {
  content: "";
  position: absolute;
  inset: calc(var(--moving-button-size, 2cm) * -0.175);
  border: calc(var(--moving-button-size, 2cm) * 0.08) dotted var(--button-color, #fff);
  border-radius: 999px;
  animation: moving-burst-particles 360ms ease-out forwards;
}

@keyframes moving-button-burst {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  45% { transform: translate(-50%, -50%) scale(1.28); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(0.12) rotate(18deg); opacity: 0; }
}

@keyframes moving-burst-particles {
  0% { transform: scale(0.35); opacity: 0; }
  35% { opacity: 1; }
  100% { transform: scale(1.8) rotate(30deg); opacity: 0; }
}

.multi-button-prompt {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 18px;
  width: min(92vw, 760px);
}

.sequence-button {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 116px;
  color: #fff;
  background: #1f7a5d;
  border: 6px solid rgba(255, 255, 255, 0.86);
  border-radius: 22px;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
  font-size: clamp(3rem, 9vw, 5.8rem);
  font-weight: 900;
}


.sequence-button.unlabeled::after {
  content: "";
  width: 42%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
}

.sequence-button.pressed {
  background: #2f6f8e;
  transform: scale(0.96);
  opacity: 0.72;
}

.sequence-button.wrong {
  background: #8a2b2b;
  transform: scale(0.96);
}

.color-match-prompt {
  --match-shape-size: 150px;
  --match-section-gap: 8px;
  --match-grid-gap: clamp(72px, 14vmin, 120px);
  display: grid;
  gap: var(--match-section-gap);
  width: min(calc(100% - 24px), 820px);
  max-height: calc(100% - 24px);
  justify-items: center;
}

.target-color-wrap {
  display: grid;
  gap: 4px;
  justify-items: center;
}

.target-color-label {
  padding: 6px 14px;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(0, 0, 0, 0.36);
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 800;
}

.target-color.image-match-card,
.color-choice.image-match-card {
  background: #fff;
  border: 7px solid rgba(255, 255, 255, 0.9);
  border-radius: 22px;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

.match-image {
  display: block;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 8%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.match-image.silhouette {
  filter: brightness(0) saturate(100%);
}

.match-shape {
  display: block;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  border: 7px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

.target-color,
.color-choice {
  display: grid;
  place-items: center;
  width: var(--match-shape-size);
  height: var(--match-shape-size);
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.target-color {
  cursor: default;
  opacity: 1;
  filter: none;
  pointer-events: none;
}

.color-choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, var(--match-shape-size));
  justify-content: center;
  gap: var(--match-grid-gap);
  width: 100%;
}

.color-choice {
  cursor: pointer;
}

.image-credit a {
  color: inherit;
  font-weight: 800;
}

.color-choice-grid.locked {
  pointer-events: none;
}

.shape-circle {
  border-radius: 999px;
}

.shape-square {
  border-radius: 22px;
}

.shape-triangle {
  clip-path: polygon(50% 4%, 96% 92%, 4% 92%);
  border-radius: 0;
}

.shape-diamond {
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  border-radius: 0;
}

.shape-star {
  clip-path: polygon(
    50% 0%,
    61% 35%,
    98% 35%,
    68% 57%,
    79% 91%,
    50% 70%,
    21% 91%,
    32% 57%,
    2% 35%,
    39% 35%
  );
  border-radius: 0;
}

.color-choice.wrong {
  outline: 8px solid rgba(255, 255, 255, 0.54);
  outline-offset: 4px;
  filter: grayscale(0.75) brightness(0.78);
}

.hidden {
  display: none !important;
}

.control-panel {
  display: grid;
  gap: 14px;
  padding: 14px;
  border-radius: 8px;
}

.state-block,
.admin-block,
.admin-grid,
.meters > div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.label {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.state-value {
  min-height: 34px;
  color: var(--red);
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1.1;
}

.state-value.playing {
  color: var(--green);
}

.level-options {
  display: grid;
  gap: 8px;
}

.level-options label {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffdf8;
}

.level-options input {
  width: 20px;
  height: 20px;
  accent-color: var(--green);
}

.level-options span {
  font-weight: 800;
}

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: end;
}

.admin-grid label {
  display: grid;
  gap: 6px;
}

.admin-grid input[type="checkbox"] {
  width: 28px;
  height: 28px;
  accent-color: var(--green);
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.button-grid .wide {
  grid-column: 1 / -1;
  background: var(--amber);
}

.button-grid button.active {
  background: var(--blue);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.46);
}

.button-grid .wide:hover {
  background: #a56d16;
}

.meters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.meters strong {
  display: block;
  font-size: 1.35rem;
  line-height: 1.2;
}

.small {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.level-options.compact {
  grid-template-columns: 1fr 1fr;
}

.log-actions {
  margin-bottom: 10px;
}

.log-preview {
  min-height: 84px;
  max-height: 148px;
  margin: 8px 0 0;
  padding: 10px;
  overflow: auto;
  color: #1d2420;
  background: #f6f7f4;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.78rem;
  line-height: 1.35;
  white-space: pre-wrap;
}

.light-burst {
  position: absolute;
  z-index: 8;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border-radius: 999px;
  pointer-events: none;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.98) 0 14%, rgba(255, 225, 84, 0.95) 15% 34%, rgba(64, 194, 255, 0.6) 35% 52%, rgba(255, 255, 255, 0) 66%);
  animation: light-burst 760ms ease-out forwards;
}

@keyframes light-burst {
  0% {
    opacity: 0.98;
    transform: scale(0.4);
  }
  70% {
    opacity: 0.82;
    transform: scale(7.4);
  }
  100% {
    opacity: 0;
    transform: scale(9.2);
  }
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 14px;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
    gap: 12px;
  }

  h1 {
    font-size: 1.9rem;
  }

  .search-form,
  .source-form,
  .admin-grid,
  .meters,
  .level-options.compact {
    grid-template-columns: 1fr;
  }

  .player-frame {
    min-height: 196px;
  }

  .reward-button span {
    font-size: 1.72rem;
  }

  .reward-icon {
    font-size: 4.2rem;
  }

  .voice-prompt strong {
    font-size: 3rem;
  }

  .voice-icon {
    font-size: 6.4rem;
  }

  .multi-button-prompt,
  .color-choice-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .color-choice-grid {
    grid-template-columns: repeat(2, var(--match-shape-size));
    justify-content: center;
  }

  .sequence-button {
    min-height: 92px;
  }
}

/* Independent ABA / DTT mode navigation */
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.mode-link { display: inline-flex; align-items: center; min-height: 40px; padding: 8px 13px; border: 1px solid #2f7f8f; border-radius: 999px; color: #1d6572; background: #e7f4f5; font-weight: 800; text-decoration: none; }
.mode-link:hover { background: #d8edef; }
.mode-link:focus-visible { outline: 3px solid #e3a428; outline-offset: 3px; }
@media (max-width: 620px) { .topbar-actions { align-items: flex-end; flex-direction: column; } .mode-link { min-height: 36px; padding: 6px 10px; font-size: .78rem; } }
