:root {
  color-scheme: light;
  --ink: #243238;
  --muted: #66757b;
  --paper: #fbf8ee;
  --panel: #fffdf7;
  --line: #d8d0bd;
  --teal: #2f9a91;
  --gold: #d99122;
  --coral: #d95f4c;
  --green: #5f9d54;
  --blue: #3879b8;
  --shadow: 0 18px 48px rgba(45, 52, 54, 0.16);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(251, 248, 238, 0.96), rgba(244, 239, 225, 0.94)),
    repeating-linear-gradient(90deg, rgba(47, 154, 145, 0.08) 0 1px, transparent 1px 64px);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

button {
  font: inherit;
}

.app {
  width: min(1080px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.game-shell,
.result-screen {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.game-shell {
  display: grid;
  grid-template-rows: auto auto auto auto 1fr;
  min-height: calc(100vh - 56px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px 16px;
}

.kicker {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(32px, 7vw, 64px);
  line-height: 0.95;
  letter-spacing: 0;
}

.round-pill {
  min-width: 118px;
  border: 1px solid var(--line);
  background: #f3ead4;
  padding: 10px 12px;
  text-align: center;
  font-weight: 800;
}

.stage-band {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #e7f0e7;
}

#workshopCanvas {
  display: block;
  width: 100%;
  height: min(48vw, 420px);
  min-height: 320px;
}

.speech {
  position: absolute;
  left: 28px;
  bottom: 22px;
  max-width: min(560px, calc(100% - 56px));
  background: rgba(255, 253, 247, 0.94);
  border: 1px solid var(--line);
  padding: 16px 18px;
  font-size: 20px;
  line-height: 1.45;
}

.meter-band {
  display: grid;
  grid-template-columns: 1fr 1fr 220px;
  gap: 18px;
  padding: 18px 28px;
  align-items: end;
}

.meter-label {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-weight: 800;
  font-size: 14px;
  margin-bottom: 8px;
}

.meter-track {
  height: 14px;
  border: 1px solid #c9bfa9;
  background: #eee4cf;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0;
  transition: width 420ms ease;
}

.meter-fill.progress {
  background: var(--green);
}

.meter-fill.spark {
  background: var(--gold);
}

.state-panel {
  border-left: 4px solid var(--blue);
  background: #edf4f8;
  padding: 12px 14px;
  min-height: 62px;
}

.state-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 4px;
}

#stateText {
  font-size: 20px;
}

.choice-band {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 0 28px 20px;
}

.choice-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 74px;
  border: 2px solid transparent;
  color: #fff;
  cursor: pointer;
  font-size: 24px;
  font-weight: 900;
  transition: transform 140ms ease, filter 140ms ease;
}

.choice-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.choice-btn:active {
  transform: translateY(1px);
}

.choice-btn.repair {
  background: var(--teal);
}

.choice-btn.ignite {
  background: var(--coral);
}

.choice-mark {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 3px solid currentColor;
}

.ignite .choice-mark {
  border-radius: 50%;
}

.log-band {
  border-top: 1px solid var(--line);
  padding: 18px 28px 24px;
  background: #f7f1e2;
}

.log-band h2 {
  font-size: 16px;
  color: var(--muted);
  margin-bottom: 10px;
}

#logList {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 24px;
}

#logList li {
  line-height: 1.45;
}

.result-screen {
  min-height: calc(100vh - 56px);
  padding: 32px;
}

.result-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(420px, 1.15fr);
  gap: 28px;
  align-items: start;
}

.result-main {
  padding: 10px 0;
}

.result-main h2 {
  font-size: clamp(34px, 6vw, 62px);
  line-height: 1;
  margin-bottom: 16px;
}

#resultCopy {
  color: var(--ink);
  font-size: 20px;
  line-height: 1.55;
}

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

.stat {
  border: 1px solid var(--line);
  background: #f8f1df;
  padding: 12px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stat strong {
  font-size: 28px;
}

.reset-btn {
  border: 0;
  background: var(--ink);
  color: white;
  cursor: pointer;
  padding: 14px 20px;
  font-weight: 900;
  font-size: 18px;
}

.matrix {
  border-left: 1px solid var(--line);
  padding-left: 28px;
}

.matrix h3 {
  margin-bottom: 14px;
  font-size: 24px;
}

.matrix-grid {
  display: grid;
  grid-template-columns: 0.8fr 1fr 1fr;
  border: 1px solid var(--line);
}

.matrix-cell {
  min-height: 92px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 14px;
  display: grid;
  place-items: center;
  text-align: center;
  font-weight: 800;
  line-height: 1.35;
}

.matrix-cell:nth-child(3n) {
  border-right: 0;
}

.matrix-cell:nth-last-child(-n + 3) {
  border-bottom: 0;
}

.matrix-cell.head {
  background: #ede3cc;
  color: #4c473d;
}

.matrix-cell.good {
  background: #e2f0df;
}

.matrix-cell.weak {
  background: #f6e8d5;
}

.matrix-cell.great {
  background: #f8e7aa;
}

@media (max-width: 820px) {
  .app {
    width: 100%;
    padding: 0;
  }

  .game-shell,
  .result-screen {
    min-height: 100vh;
    border-left: 0;
    border-right: 0;
  }

  .topbar,
  .meter-band,
  .choice-band,
  .log-band,
  .result-screen {
    padding-left: 16px;
    padding-right: 16px;
  }

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

  .round-pill {
    align-self: stretch;
  }

  .stage-band {
    min-height: 330px;
  }

  #workshopCanvas {
    height: 360px;
  }

  .speech {
    left: 16px;
    right: 16px;
    bottom: 16px;
    max-width: none;
    font-size: 17px;
  }

  .meter-band,
  .choice-band,
  .result-layout {
    grid-template-columns: 1fr;
  }

  .choice-btn {
    min-height: 66px;
    font-size: 22px;
  }

  .matrix {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-left: 0;
    padding-top: 24px;
  }

  .matrix-grid {
    grid-template-columns: 0.72fr 1fr 1fr;
  }

  .matrix-cell {
    min-height: 86px;
    padding: 10px;
    font-size: 14px;
  }
}
