:root {
  color-scheme: light;
  --bg: #f5f6f2;
  --ink: #1f2933;
  --muted: #64707d;
  --line: #d9ddd3;
  --panel: #ffffff;
  --panel-strong: #eef4f7;
  --green: #28795a;
  --blue: #315f99;
  --orange: #b05c21;
  --red: #b23a48;
  --purple: #6b4fa3;
  --shadow: 0 12px 30px rgba(32, 42, 54, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    "Microsoft JhengHei",
    "PingFang TC",
    "Noto Sans TC",
    system-ui,
    sans-serif;
  letter-spacing: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(49, 95, 153, 0.09), transparent 260px),
    var(--bg);
}

button {
  font: inherit;
}

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

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 0 18px;
}

.title-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

.school-mark {
  width: 58px;
  height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem, 2.4vw, 2rem);
  line-height: 1.1;
}

.title-block p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.95rem;
}

.top-actions,
.modal-choices {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.game-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 310px;
  gap: 14px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stats-panel,
.play-panel,
.log-panel {
  padding: 14px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-heading h2 {
  font-size: 1.05rem;
}

.phase-badge,
#slotText,
#modeText {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--blue);
  font-weight: 700;
  font-size: 0.88rem;
}

.stats-grid {
  display: grid;
  gap: 9px;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fcfcfa;
}

.stat-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 7px;
}

.stat-name {
  font-weight: 700;
}

.stat-value {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.bar-track {
  height: 9px;
  overflow: hidden;
  border-radius: 8px;
  background: #e8e9e0;
}

.bar-fill {
  height: 100%;
  width: 0%;
  background: var(--green);
  transition: width 160ms ease;
}

.stat-card[data-tone="blue"] .bar-fill {
  background: var(--blue);
}

.stat-card[data-tone="orange"] .bar-fill {
  background: var(--orange);
}

.stat-card[data-tone="red"] .bar-fill {
  background: var(--red);
}

.stat-card[data-tone="purple"] .bar-fill {
  background: var(--purple);
}

.stat-desc {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.meta-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 8px;
  background: #f8faf8;
}

.meta-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.meta-grid strong {
  display: block;
  margin-top: 2px;
  font-size: 1.05rem;
}

.scene-strip {
  min-height: 94px;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6f2e9;
}

.scene-strip img {
  width: 130px;
  max-width: 42%;
  height: 70px;
  object-fit: contain;
}

.scene-strip div {
  display: grid;
  gap: 7px;
}

.scene-strip strong {
  font-size: 1.25rem;
}

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

.choice-button,
.ghost-button,
.danger-button {
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease;
}

.choice-button {
  min-height: 76px;
  padding: 12px;
  color: #fff;
  background: var(--blue);
  text-align: left;
}

.choice-button strong {
  display: block;
  font-size: 1rem;
  line-height: 1.25;
}

.choice-button span {
  display: block;
  margin-top: 6px;
  font-size: 0.8rem;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.84);
}

.choice-button[data-tone="green"] {
  background: var(--green);
}

.choice-button[data-tone="orange"] {
  background: var(--orange);
}

.choice-button[data-tone="red"] {
  background: var(--red);
}

.choice-button[data-tone="purple"] {
  background: var(--purple);
}

.choice-button:hover,
.ghost-button:hover,
.danger-button:hover {
  transform: translateY(-1px);
}

.choice-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

.ghost-button,
.danger-button {
  min-height: 36px;
  padding: 7px 12px;
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.danger-button {
  color: #fff;
  background: var(--red);
  border-color: var(--red);
}

.compact {
  min-height: 30px;
  padding: 4px 9px;
  font-size: 0.85rem;
}

.log-panel {
  max-height: calc(100vh - 112px);
  position: sticky;
  top: 12px;
  overflow: hidden;
}

.log-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 178px);
  margin: 0;
  padding: 0 2px 0 22px;
  overflow: auto;
}

.log-list li {
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbf8;
  font-size: 0.88rem;
  line-height: 1.45;
}

.log-list time {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.76rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(18, 24, 31, 0.55);
  z-index: 20;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-box {
  width: min(560px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 20px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

.modal-kicker {
  color: var(--blue);
  font-weight: 700;
  font-size: 0.9rem;
}

.modal-box h2 {
  margin-top: 4px;
  font-size: 1.38rem;
}

.modal-box p {
  margin-top: 12px;
  line-height: 1.65;
  color: #303942;
}

.modal-result {
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.5;
  white-space: pre-wrap;
}

.modal-choices {
  margin-top: 16px;
}

.modal-choice {
  min-height: 42px;
  padding: 9px 13px;
  border: 1px solid var(--blue);
  border-radius: 8px;
  color: #fff;
  background: var(--blue);
  cursor: pointer;
}

.setup-allocator {
  display: grid;
  gap: 14px;
  color: var(--ink);
}

.setup-values {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.setup-values div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf8;
}

.setup-values span,
.setup-slider span {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
}

.setup-values strong {
  display: block;
  margin-top: 3px;
  font-size: 1.5rem;
}

.setup-slider {
  display: grid;
  gap: 8px;
}

.setup-slider input {
  width: 100%;
  accent-color: var(--purple);
}

.setup-presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.setup-presets button {
  min-height: 34px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

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

  .log-panel {
    max-height: none;
    position: static;
  }

  .log-list {
    max-height: 320px;
  }
}

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

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

  .top-actions {
    width: 100%;
  }

  .top-actions button {
    flex: 1;
  }

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

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