:root {
  color-scheme: light dark;
  --page: #eef2f2;
  --surface: #f8faf9;
  --surface-raised: #e4ebeb;
  --surface-strong: #d1dcdd;
  --text: #14262d;
  --text-soft: #4e6269;
  --line: #afbec1;
  --accent: #177487;
  --accent-strong: #0e5e6f;
  --accent-text: #f6f9f8;
  --wall-high: #e9efef;
  --wall-low: #cbd7d8;
  --floor-high: #52666c;
  --floor-low: #2d4148;
  --wood-top: #785b47;
  --wood-front: #503d32;
  --wood-line: #a48b78;
  --figure: #304851;
  --figure-light: #d6e0df;
  --robe: #1f3036;
  --shadow: rgb(26 53 62 / 0.2);
  --backdrop: rgb(9 24 31 / 0.72);
  --focus: #9d551e;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #111a1e;
    --surface: #182428;
    --surface-raised: #213136;
    --surface-strong: #2d4248;
    --text: #eef4f3;
    --text-soft: #aabbbd;
    --line: #43585d;
    --accent: #55b4c3;
    --accent-strong: #84cbd6;
    --accent-text: #102125;
    --wall-high: #25353b;
    --wall-low: #1b292e;
    --floor-high: #17282e;
    --floor-low: #0e1b20;
    --wood-top: #795c47;
    --wood-front: #49372f;
    --wood-line: #9a806e;
    --figure: #a5b6b8;
    --figure-light: #61777c;
    --robe: #0b1418;
    --shadow: rgb(3 11 14 / 0.46);
    --backdrop: rgb(3 10 13 / 0.78);
    --focus: #e59d62;
  }
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  background: var(--page);
  color: var(--text);
  font-family:
    "Avenir Next",
    Avenir,
    "Segoe UI",
    system-ui,
    -apple-system,
    sans-serif;
  line-height: 1.5;
}

button,
progress {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  border-radius: var(--radius);
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

button:active {
  transform: translateY(1px);
}

.courtroom-app {
  width: min(100%, 1500px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: 18px clamp(14px, 2.5vw, 38px) 28px;
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.title-lockup,
.topbar-actions,
.mode-switch,
.stage-status,
.scene-navigation,
.dialog-head {
  display: flex;
  align-items: center;
}

.title-lockup {
  min-width: 0;
  gap: 12px;
}

.title-lockup h1,
.title-lockup p,
.scene-brief h2,
.scene-brief p,
.sources-dialog h2,
.sources-dialog p {
  margin: 0;
}

.title-lockup h1 {
  font-size: clamp(1.2rem, 2.2vw, 1.75rem);
  font-weight: 650;
  letter-spacing: -0.035em;
  line-height: 1.05;
}

.title-lockup p {
  color: var(--text-soft);
  font-size: 0.82rem;
}

.court-mark {
  width: 46px;
  height: 50px;
  flex: 0 0 46px;
  display: grid;
  place-items: center;
  color: var(--accent-text);
  background: var(--accent);
  clip-path: polygon(50% 0, 92% 19%, 85% 76%, 50% 100%, 15% 76%, 8% 19%);
  font-weight: 700;
  letter-spacing: -0.04em;
}

.topbar-actions {
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-switch {
  padding: 4px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.mode-switch button,
.quiet-button,
.primary-button {
  min-height: 42px;
  border: 1px solid transparent;
  padding: 9px 14px;
  color: var(--text);
  background: transparent;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}

.mode-switch button[data-current="true"] {
  color: var(--accent-text);
  background: var(--accent-strong);
}

.quiet-button {
  border-color: var(--line);
  background: var(--surface);
}

.primary-button {
  color: var(--accent-text);
  background: var(--accent-strong);
}

.quiet-button:hover:not(:disabled),
.mode-switch button:hover:not([data-current="true"]) {
  background: var(--surface-raised);
}

.primary-button:hover:not(:disabled) {
  background: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.experience-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 350px);
  gap: clamp(18px, 2.5vw, 34px);
  align-items: start;
}

.courtroom-stage {
  min-width: 0;
}

.stage-status {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
  color: var(--text-soft);
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.stage-status output {
  font-variant-numeric: tabular-nums;
}

.courtroom-visual {
  position: relative;
  overflow: clip;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 18px 50px var(--shadow);
}

.scene-svg {
  display: block;
  width: 100%;
  height: auto;
}

.scene-svg text {
  fill: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-anchor: middle;
}

.floor-line,
.joinery {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.5;
  opacity: 0.42;
}

.wall-detail rect {
  fill: var(--surface-raised);
  stroke: var(--line);
  stroke-width: 1;
  opacity: 0.32;
}

.wall-detail path {
  fill: none;
  stroke: var(--line);
  stroke-width: 1;
  opacity: 0.32;
}

.seal circle {
  fill: var(--surface-raised);
  stroke: var(--text-soft);
  stroke-width: 2;
}

.seal path {
  fill: var(--text-soft);
}

.wood-top,
.jury-room-table {
  fill: var(--wood-top);
}

.wood-front {
  fill: var(--wood-front);
}

.joinery {
  stroke: var(--wood-line);
}

.seat,
.paper {
  fill: var(--surface-raised);
  stroke: var(--line);
  stroke-width: 1;
}

.person-head {
  fill: var(--figure-light);
}

.person-body {
  fill: var(--figure);
  stroke: var(--figure-light);
  stroke-width: 1;
}

.judge-robe {
  fill: var(--robe);
}

.active-ring {
  fill: none;
  stroke: var(--accent);
  stroke-width: 5;
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
  transition: opacity 220ms ease, transform 220ms ease;
}

[data-actor][data-active="true"] .active-ring {
  opacity: 1;
  transform: scale(1.06);
}

.main-courtroom {
  transition: opacity 260ms ease;
}

.jury-room {
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms ease;
}

.jury-room-wall {
  fill: var(--surface-raised);
  stroke: var(--accent);
  stroke-width: 2;
  opacity: 0.96;
}

.jury-room-title {
  font-size: 14px;
  letter-spacing: 0.08em;
}

.courtroom-app[data-scene="deliberation"] .main-courtroom {
  opacity: 0;
}

.courtroom-app[data-scene="deliberation"] .jury-room {
  opacity: 1;
}

.courtroom-app[data-mode="bench"] [data-actor="jury"] {
  opacity: 0.12;
}

.role-map {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.role-button {
  position: absolute;
  z-index: 1;
  min-height: 40px;
  transform: translate(-50%, -50%);
  border: 1px solid var(--line);
  padding: 7px 10px;
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  box-shadow: 0 8px 24px var(--shadow);
  font-weight: 650;
  cursor: pointer;
  pointer-events: auto;
  white-space: nowrap;
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
}

.role-button:hover {
  background: var(--surface);
}

.role-button[data-active="true"] {
  border-color: var(--accent-strong);
  color: var(--accent-text);
  background: var(--accent-strong);
}

.role-button[data-role="judge"] { left: 50%; top: 22%; }
.role-button[data-role="jury"] { left: 14%; top: 50%; }
.role-button[data-role="witness"] { left: 78%; top: 43%; }
.role-button[data-role="clerk"] { left: 38.5%; top: 49%; }
.role-button[data-role="reporter"] { left: 64%; top: 54%; }
.role-button[data-role="plaintiff"] { left: 35%; top: 72%; }
.role-button[data-role="defendant"] { left: 65%; top: 72%; }
.role-button[data-role="bailiff"] { left: 90%; top: 57%; }
.role-button[data-role="interpreter"] { left: 85%; top: 72%; }
.role-button[data-role="gallery"] { left: 50%; top: 91%; }

@media (min-width: 721px) {
  .courtroom-app[data-scene="deliberation"] .role-button:not([data-role="jury"]) {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
  }

  .courtroom-app[data-scene="deliberation"] .role-button[data-role="jury"] {
    left: 27%;
    top: 32%;
  }
}

.scene-brief {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(220px, 0.8fr);
  gap: 24px;
  padding: 20px 2px 0;
}

.scene-brief h2 {
  margin-bottom: 6px;
  font-size: clamp(1.35rem, 2.6vw, 2.1rem);
  font-weight: 650;
  letter-spacing: -0.035em;
  line-height: 1.06;
}

.scene-brief p {
  max-width: 68ch;
  color: var(--text-soft);
}

.notice-block {
  padding-left: 18px;
  border-left: 3px solid var(--accent);
}

.notice-block strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.control-deck {
  position: sticky;
  top: 18px;
  max-height: calc(100dvh - 36px);
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 18px 50px var(--shadow);
  scrollbar-color: var(--line) transparent;
}

.progress-label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-soft);
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

progress {
  display: block;
  width: 100%;
  height: 8px;
  margin-bottom: 18px;
  border: 0;
  border-radius: var(--radius);
  overflow: hidden;
  accent-color: var(--accent);
  background: var(--surface-strong);
}

progress::-webkit-progress-bar {
  background: var(--surface-strong);
}

progress::-webkit-progress-value {
  background: var(--accent);
}

progress::-moz-progress-bar {
  background: var(--accent);
}

.timeline {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: trial-scene;
}

.timeline li {
  position: relative;
  counter-increment: trial-scene;
  padding-left: 30px;
}

.timeline li::before {
  content: counter(trial-scene);
  position: absolute;
  left: 0;
  top: 9px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text-soft);
  background: var(--surface-raised);
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.timeline li:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 10px;
  top: 31px;
  bottom: -9px;
  width: 2px;
  background: var(--line);
}

.timeline-button {
  width: 100%;
  min-height: 40px;
  border: 0;
  padding: 8px 10px;
  color: var(--text-soft);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.timeline-button:hover {
  color: var(--text);
  background: var(--surface-raised);
}

.timeline-button[data-current="true"] {
  color: var(--accent-strong);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  font-weight: 700;
}

.timeline li:has(.timeline-button[data-current="true"])::before {
  color: var(--accent-text);
  background: var(--accent-strong);
}

.scene-navigation {
  position: sticky;
  bottom: -18px;
  gap: 8px;
  margin: 16px -18px -18px;
  padding: 14px 18px 18px;
  background: linear-gradient(to bottom, transparent, var(--surface) 22%);
}

.scene-navigation button {
  flex: 1 1 0;
}

.sources-dialog {
  width: min(620px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 28px 80px var(--shadow);
}

.sources-dialog::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.dialog-head {
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.sources-dialog h2 {
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.025em;
}

.sources-dialog ul {
  display: grid;
  gap: 10px;
  margin: 0 0 18px;
  padding-left: 22px;
}

.sources-dialog a {
  color: var(--accent-strong);
  font-weight: 650;
}

.sources-dialog p {
  color: var(--text-soft);
}

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

  .control-deck {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .timeline {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px 12px;
  }

  .timeline li::after {
    display: none;
  }

  .scene-navigation {
    position: static;
    margin-top: 16px;
    margin-bottom: 0;
    padding-bottom: 0;
    background: transparent;
  }
}

@media (max-width: 720px) {
  .courtroom-app {
    padding: 12px 12px 24px;
  }

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

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .mode-switch {
    flex: 1 1 auto;
  }

  .mode-switch button {
    flex: 1 1 0;
  }

  .courtroom-visual {
    display: flex;
    flex-direction: column;
    overflow: visible;
    background: transparent;
    box-shadow: none;
  }

  .scene-svg {
    overflow: hidden;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 12px 34px var(--shadow);
  }

  .role-map {
    position: static;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin-top: 10px;
  }

  .role-button {
    position: static;
    transform: none;
    width: 100%;
    min-height: 44px;
    box-shadow: none;
    text-align: left;
  }

  .scene-brief {
    grid-template-columns: 1fr;
    gap: 16px;
    padding-top: 18px;
  }

  .notice-block {
    padding: 12px 0 0;
    border-left: 0;
    border-top: 3px solid var(--accent);
  }

  .control-deck {
    padding: 14px;
  }

  .timeline {
    grid-template-columns: 1fr;
  }

  .scene-navigation {
    margin-left: -14px;
    margin-right: -14px;
    padding-left: 14px;
    padding-right: 14px;
  }
}

@media (max-width: 440px) {
  .court-mark {
    width: 40px;
    height: 44px;
    flex-basis: 40px;
  }

  .topbar-actions .quiet-button {
    flex: 1 1 0;
  }

  .mode-switch {
    flex-basis: 100%;
  }

  .role-map {
    grid-template-columns: 1fr;
  }

  .dialog-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

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

@media (prefers-reduced-transparency: reduce) {
  .role-button,
  .sources-dialog::backdrop {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .role-button {
    background: var(--surface);
  }
}
