:root {
  color-scheme: light;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #203546;
  background: #e7edee;
  --ink: #203546;
  --muted: #506578;
  --blue: #153f73;
  --paper: #fffdf5;
  --rule: #d6dfe7;
  --red: #a73532;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background-image: linear-gradient(#7193ae24 1px, transparent 1px), linear-gradient(90deg, #7193ae24 1px, transparent 1px);
  background-size: 22px 22px;
}
main { width: min(72rem, calc(100% - 2rem)); margin: auto; padding: clamp(1.3rem, 4vw, 3.2rem) 0; }
.masthead { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.3rem; }
.chapter, .eyebrow { letter-spacing: .13em; color: var(--blue); font-weight: 750; font-size: .85rem; margin: 0 0 .45rem; }
h1 { font-size: clamp(2.35rem, 8vw, 5.15rem); line-height: .98; margin: 0; letter-spacing: -.065em; color: var(--blue); }
h1 span { color: var(--red); margin-left: .15em; display: inline-block; transform: rotate(-8deg); }
.progress { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: 1rem; font-size: .8rem; }
.progress span { padding: .3rem .6rem; background: #edf3f5; border: 1px solid #bdcbd4; border-radius: .25rem; color: var(--muted); }
.progress .current { background: #f7df91; color: #352600; border-color: #ba9b42; font-weight: 750; }
.layout { display: grid; grid-template-columns: minmax(0, 1.85fr) minmax(0, 1fr); gap: .95rem; align-items: start; }
.paper { background: var(--paper); border: 1px solid #91a2ad; box-shadow: 4px 4px 0 #b6c3cb; border-radius: .45rem; padding: clamp(.95rem, 3vw, 1.65rem); }
.arena { border-top: 5px solid var(--blue); }
h2, h3 { margin: 0; }
.arena h2 { font-size: clamp(1.5rem, 4vw, 2.45rem); }
.story { color: var(--muted); line-height: 1.65; }
.fighters, .reveal { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; margin: 1rem 0; }
.fighter { background: #edf4fc; border: 1px solid #9eb7cb; border-radius: .35rem; padding: clamp(.6rem, 2vw, .95rem); }
.rival { background: #fff0e1; border-color: #d4b69c; }
.fighter h3 { font-size: 1rem; overflow-wrap: anywhere; }
.stats { display: flex; flex-wrap: wrap; gap: .25rem .65rem; margin-top: .55rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.health { color: #912b36; }
.energy { color: var(--blue); }
.inventory, .boost { color: var(--muted); font-size: .8rem; margin: .45rem 0 0; line-height: 1.45; }
.boost { color: #684400; font-weight: 750; }
.reveal div { border: 1px dashed #566c84; padding: .55rem; text-align: center; font-weight: 750; border-radius: .3rem; background: #fff4cb; }
.reveal:not([hidden]) { animation: reveal .18s ease-out; }
@keyframes reveal { from { opacity: .5; transform: translateY(.25rem); } }
.actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; }
button { min-height: 44px; border: 1px solid var(--blue); border-radius: .35rem; font: inherit; font-weight: 750; padding: .6rem .8rem; cursor: pointer; color: var(--ink); background: #f4f7fb; }
@media (hover: hover) {
  button:hover:not(:disabled) { box-shadow: 0 2px 0 var(--blue); }
}
button:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
button:focus-visible, summary:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; }
button:disabled { cursor: default; background: #e7eaec; border-color: #a3acb1; color: #536470; }
.primary { grid-column: 1 / -1; justify-self: start; background: var(--blue); color: white; }
.outline { flex: none; background: var(--paper); font-size: .8rem; }
.move, .reward { text-align: left; }
.reward { grid-column: 1 / -1; background: #fff4d0; border-color: #997a24; }
.note { display: block; color: var(--muted); margin-top: .28rem; font-weight: 500; line-height: 1.45; }
.log h2 { font-size: 1.15rem; margin-bottom: .7rem; }
.log #history { max-height: 23rem; overflow-y: auto; }
.log details { border-top: 1px solid var(--rule); padding: .55rem .1rem; }
.log details p, .log ul, .empty { color: var(--muted); line-height: 1.55; font-size: .88rem; }
.log ul { padding-left: 1.15rem; margin: .4rem 0 0; }
.log summary { cursor: pointer; font-weight: 750; }
.log .card, .log .outcome { color: var(--red); font-weight: 750; }
@media (max-width: 47rem) {
  .layout { grid-template-columns: 1fr; }
}
@media (max-width: 26rem) {
  .masthead { align-items: start; flex-direction: column; }
  .actions { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .reveal { animation: none !important; }
}

.lab-title { font-size: clamp(2rem, 7vw, 4rem); }
a { color: var(--blue); text-underline-offset: .2em; }
a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
#scenario fieldset { min-width: 0; margin: 0; }
#scenario-inputs { padding: .75rem; border: 1px solid var(--rule); }
#scenario legend { font-weight: 750; }
.lab-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
#scenario input[type="number"], #scenario select { display: block; width: 100%; padding: .4rem; font: inherit; }
#scenario input[name="round"] { width: 8rem; }
.check { display: inline-flex; align-items: center; min-height: 32px; margin-right: .5rem; }
.lab-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.lab-trace { margin-top: 1rem; }
.lab-trace details { border-top: 1px solid var(--rule); padding: .65rem 0; }
.lab-trace li { margin: .35rem 0; }
@media (max-width: 38rem) {
  #lab-fighters { grid-template-columns: 1fr; }
}

.personality { color: var(--blue); font-size: .87rem; margin: .65rem 0; line-height: 1.5; }
.reveal .delta { display: block; color: var(--muted); font-size: .85rem; margin-top: .25rem; font-variant-numeric: tabular-nums; }
.reveal .card-feedback { grid-column: 1 / -1; color: #792b29; background: #f8e8e3; border-left: .2rem solid var(--red); padding: .45rem .65rem; margin: 0; font-size: .88rem; font-weight: 750; }
.arena h2:focus-visible { outline: 2px solid var(--red); outline-offset: 4px; }
@media (max-width: 26rem) {
  .reveal-card { overflow-wrap: anywhere; }
}

.run-summary { grid-column: 1 / -1; margin: 0; padding: .8rem; background: #fff4cb; border: 1px dashed #997a24; }
.run-summary dt { font-weight: 750; margin-top: .5rem; }
.run-summary dd { margin: .15rem 0; overflow-wrap: anywhere; }
.build-cards { margin-top: .5rem; font-size: .83rem; }
.build-cards summary { cursor: pointer; color: var(--blue); }

body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
button, summary, a { touch-action: manipulation; }
.save-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; }
#save-status:empty { display: none; }
#save-status { font-size: .88rem; color: var(--muted); }

@media (pointer: coarse) {
  .log summary, .build-cards summary, .lab-trace summary { align-content: center; min-height: 44px; }
  .check, #scenario input[type="number"], #scenario select { min-height: 44px; }
}
@media (orientation: landscape) and (max-height: 32rem) and (pointer: coarse) {
  main { padding-block: .75rem; }
  .masthead { margin-bottom: .75rem; }
  .masthead h1 { font-size: clamp(1.9rem, 6vw, 3rem); }
  .layout { grid-template-columns: minmax(0, 2fr) minmax(12rem, 1fr); }
}
@media (orientation: landscape) and (max-height: 32rem) and (max-width: 39rem) {
  .layout { grid-template-columns: 1fr; }
}
