:root {
  color-scheme: light;
  --canvas: #eadbc1;
  --paper: #fbf2df;
  --plaster: #f0e3ca;
  --ink: #33261d;
  --muted: #6b5746;
  --line: #cbb38e;
  --wood: #473125;
  --dark-wood: #2e201a;
  --ochre: #a27a46;
  --terracotta: #8b402d;
  --green: #3d5640;
  --slate: #3a555f;
  --danger: #8f3025;
  --serif: Georgia, 'Times New Roman', serif;
  --shadow: 0 4px 12px #4a31221a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 48% 0%, #f5ead4, transparent 65%),
    repeating-linear-gradient(115deg, #644d2803 0 1px, transparent 1px 6px),
    var(--canvas);
  color: var(--ink);
  font: 16px/1.5 system-ui, sans-serif;
}

h1, h2, h3, p, dl, dd { margin: 0; }
h1, h2, h3, legend { font-family: var(--serif); line-height: 1.13; }
h1 { font-size: clamp(1.75rem, 4vw, 2.65rem); }
h2 { font-size: clamp(1.15rem, 2.5vw, 1.45rem); }
h3, legend { font-size: 1.04rem; font-weight: 700; }
p + p { margin-top: .7rem; }
a { color: #51391f; font-weight: 650; text-underline-offset: .18em; }
a:hover { color: var(--terracotta); }
:where(a, button, input, select):focus-visible {
  outline: 3px solid #9a6034;
  outline-offset: 3px;
}

.site-header {
  background:
    repeating-linear-gradient(2deg, #ffffff05 0 1px, transparent 1px 7px),
    linear-gradient(90deg, #3b291f, #563d2d 52%, #3b291f);
  border-top: 4px solid var(--dark-wood);
  border-bottom: 5px solid var(--dark-wood);
  box-shadow: 0 2px 0 var(--ochre);
}
.header-inner {
  display: flex;
  align-items: center;
  gap: clamp(14px, 3vw, 40px);
  max-width: 1260px;
  min-height: 72px;
  margin: auto;
  padding: 10px 24px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: #fae8c7;
  text-decoration: none;
  font: 700 1.7rem/1 var(--serif);
}
.brand:hover { color: white; }
.brand-mark {
  position: relative;
  display: block;
  width: 27px;
  height: 28px;
  background: #d8b985;
  clip-path: polygon(0 100%, 0 0, 23% 0, 23% 24%, 38% 24%, 38% 0, 62% 0, 62% 24%, 77% 24%, 77% 0, 100% 0, 100% 100%, 65% 100%, 65% 70%, 57% 58%, 43% 58%, 35% 70%, 35% 100%);
}
#nav {
  display: flex;
  gap: 4px;
  min-width: 0;
  padding: 4px;
  background: var(--dark-wood);
  box-shadow: 0 1px 0 #ac805a;
}
#nav a {
  display: grid;
  place-items: center;
  min-height: 40px;
  padding: 5px clamp(12px, 2vw, 22px);
  background: var(--plaster);
  border: 1px solid #b28f66;
  box-shadow: inset 0 0 0 1px #fff6df;
  color: var(--ink);
  text-decoration: none;
  text-align: center;
  font: 700 1rem/1.13 var(--serif);
}
#nav a:hover { background: #fff1d4; }
#nav a.current {
  background: #e9ce9f;
  box-shadow: inset 0 -3px var(--ochre);
  color: #6b341f;
}
#logout { margin-left: auto; color: #fae8c7; border-color: #b89268; }
#logout:hover { background: #ffffff13; }

main { max-width: 1260px; margin: auto; padding: clamp(18px, 3vw, 34px) 24px 42px; }
.paper {
  min-width: 0;
  background: linear-gradient(140deg, #fff7e7, transparent 60%), var(--paper);
  border: 1px solid var(--line);
  border-top: 3px solid var(--ochre);
  border-radius: 5px;
  box-shadow: var(--shadow);
}
.top, .buttons, .card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  flex-wrap: wrap;
}
.buttons { justify-content: flex-start; }
.muted { color: var(--muted); font-size: .875rem; }
.damage { color: var(--danger); }
.reward {
  background: #e8ebd9;
  border-left: 3px solid #748164;
  padding: 10px 12px;
  font-weight: 650;
}
#error {
  margin-bottom: 14px;
  padding: 10px 14px;
  background: #fae3d7;
  border: 1px solid #bc775f;
  border-radius: 4px;
  color: var(--danger);
}
button {
  background: var(--green);
  border: 1px solid #314432;
  border-radius: 4px;
  padding: 9px 15px;
  min-height: 44px;
  color: #fffaf0;
  font: inherit;
  font-weight: 650;
  line-height: 1.22;
  cursor: pointer;
}
button:hover { background: #314e37; }
button.sub { background: transparent; border-color: #a98e66; color: var(--ink); }
button.sub:hover { background: #f0e1c7; }
button:disabled { opacity: .52; cursor: not-allowed; }
label { display: block; font-size: .9rem; font-weight: 600; }
input, select {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 5px;
  padding: 8px 10px;
  background: #fffaf0;
  border: 1px solid #ac9474;
  border-radius: 4px;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--plaster); border-radius: 4px; }
.auth-tabs button { color: var(--ink); border-color: transparent; background: transparent; }
.auth-tabs button:hover { background: #fff7e6; }
.auth-tabs [aria-pressed="true"] { background: #fff9ec; border-color: var(--line); box-shadow: 0 2px 3px #4a312213; }
#authform label { margin-top: 12px; }
#regFields p { margin-top: 8px; }
#authSubmit, #continue, #create, #allocate, #move { width: 100%; margin-top: 13px; }

.onboarding {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(0, 1fr);
  max-width: 1000px;
  margin: clamp(10px, 4vw, 46px) auto 0;
  overflow: hidden;
}
.onboarding-art, .room-art { display: block; width: 100%; height: 100%; object-fit: cover; }
.onboarding-art { min-height: 380px; object-position: 59% 50%; }
.onboarding-content { align-self: center; padding: clamp(20px, 4vw, 44px); }
.onboarding-content h1 { margin-bottom: 19px; }
.intro-visual {
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(145deg, #e9d5b3, #f1e5cc);
  border-right: 1px solid var(--line);
}
.intro-visual .portrait-frame { width: min(100%, 280px); }
#creation { max-width: 590px; margin: 16px auto; padding: clamp(18px, 4vw, 35px); }
#creation h1 { margin-bottom: 10px; }
#free { margin: 14px 0 3px; color: var(--green); font-weight: 750; }
.statrow { display: flex; align-items: center; gap: 7px; }
.statrow span:first-child { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.statrow strong { min-width: 1.1rem; text-align: center; }
.statrow button {
  flex: 0 0 33px;
  min-height: 36px;
  padding: 0;
  border-color: #bfa683;
  background: #f0e0c3;
  color: var(--ink);
}
.statrow button:hover { background: #e8cea1; }
.statitem { padding: 9px 0; border-bottom: 1px solid var(--line); }
.statitem small { display: block; margin-top: 4px; }

.room-layout {
  display: grid;
  align-items: start;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "center" "profile";
  gap: 16px;
}
.room-layout.has-opponent {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-areas: "center center" "profile opponent";
}
.room-center { grid-area: center; display: grid; gap: 16px; min-width: 0; }
#profile { grid-area: profile; }
#opponent { grid-area: opponent; }
#arena { overflow: hidden; }
.room-art { aspect-ratio: 2.35; height: auto; border-bottom: 3px solid var(--ochre); }
.arena-content { padding: clamp(16px, 3vw, 26px); }
.arena-content .buttons { margin-top: 13px; }
.arena-content p:not(:empty) { margin-top: 9px; }
#roster { padding: 15px 18px; }
#roster .top { margin-bottom: 5px; }
.player-row, .history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px 12px;
  border-bottom: 1px solid #dfcaa7;
  padding: 10px 0;
}
.player-row:last-child, .history-row:last-child { border-bottom: 0; }
.player-row a, .history-row a { overflow-wrap: anywhere; }
.player-row small { flex-shrink: 0; text-align: right; }
#comparePicker { margin-top: 9px; }
#comparePlayer { max-width: 300px; }

.character-card { padding: clamp(10px, 1.8vw, 20px); }
.card-heading { align-items: baseline; gap: 3px 8px; min-width: 0; margin-bottom: 12px; }
.card-heading a, .fighter-name { overflow-wrap: anywhere; }
.card-heading .muted { white-space: nowrap; }
.portrait-frame {
  width: min(100%, 190px);
  margin-inline: auto;
  padding: 4px;
  background: #e6cba0;
  border: 1px solid #a78659;
  box-shadow: inset 0 0 0 2px #f7e3be, 0 2px 5px #62432322;
}
.person { display: block; width: 100%; height: auto; aspect-ratio: 3/4; }
.barlabel, .hp-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px;
  margin: 12px 0;
  font-size: .83rem;
  font-weight: 650;
}
.barlabel span:last-of-type, .hp-line span:last-of-type { text-align: right; font-variant-numeric: tabular-nums; }
progress {
  display: block;
  grid-column: 1/-1;
  appearance: none;
  width: 100%;
  height: 8px;
  overflow: hidden;
  background: #e5d3b1;
  border: 1px solid #b9a181;
  border-radius: 3px;
}
progress::-webkit-progress-bar { background: #e5d3b1; }
progress::-webkit-progress-value { background: #57704e; }
progress::-moz-progress-bar { background: #57704e; }
#xpBar::-webkit-progress-value { background: #a77a3b; }
#xpBar::-moz-progress-bar { background: #a77a3b; }
.statgrid { display: grid; gap: 0; }
.statgrid div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px;
  padding: 5px 0;
  border-bottom: 1px solid #dfcaa7;
  font-size: .89rem;
}
.statgrid dd { flex-shrink: 0; font-weight: 750; font-variant-numeric: tabular-nums; }
.character-card p { margin-top: 9px; }
#levelup { margin-top: 13px; }
#levelup h3 { color: var(--green); }

.page-heading { margin-bottom: 15px; }
.page-panel {
  max-width: 1020px;
  margin-inline: auto;
  padding: clamp(14px, 3vw, 30px);
}
.combat-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-areas: "left right" "move move" "journal journal";
  align-items: start;
  gap: 14px;
}
#fighterLeft { grid-area: left; }
#fighterRight { grid-area: right; }
#fightCenter { grid-area: move; padding: clamp(12px, 3vw, 24px); }
.battle-log { grid-area: journal; padding: clamp(12px, 3vw, 22px); }
.fighter { padding: clamp(9px, 1.7vw, 17px); }
.fighter .portrait-frame { width: min(100%, 146px); }
.fighter h2 { display: flex; gap: 4px 8px; align-items: baseline; flex-wrap: wrap; margin-bottom: 10px; }
.fighter h2 small { font: 650 .75rem/1.2 system-ui, sans-serif; }
.fighter .muted:last-child { margin-top: 8px; }
.round-timer {
  display: flex;
  align-items: center;
  gap: 8px 14px;
  padding: 7px 13px;
  background: var(--paper);
  border: 1px solid #b59a73;
  border-radius: 4px;
  color: var(--ink);
  font-size: .91rem;
}
.round-timer strong { font-size: 1.12rem; font-variant-numeric: tabular-nums; }
.round-timer.urgent { background: #f4ddd0; border-color: #be8878; color: var(--danger); }
#status { margin-bottom: 9px; font-weight: 650; }
#status:last-child { margin-bottom: 0; }
#battleInjury, #finishButtons { margin-top: 12px; }
.action-stack { display: grid; gap: 12px; margin-top: 14px; }
.action-panel {
  min-width: 0;
  margin: 0;
  padding: 8px 10px 11px;
  background: #eddfc533;
  border: 1px solid #c9ae88;
  border-radius: 4px;
}
.action-panel legend { padding: 0 6px; }
.action-panel:first-child legend { color: var(--terracotta); }
.action-panel:last-child legend { color: var(--slate); }
.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.choices button {
  background: #fff8e8;
  border-color: #c3aa85;
  color: var(--ink);
  font-size: .92rem;
}
.choices button:hover { background: #f1e0bf; }
#attacks button.selected { background: var(--terracotta); border-color: #773926; color: white; }
#blocks button.selected { background: var(--slate); border-color: #2d4952; color: white; }
.logs { max-height: 325px; overflow: auto; margin-top: 9px; font-size: .92rem; }
.archive-logs { max-height: none; }
.log { padding: 9px 0; border-top: 1px solid #dfcaa7; }
.log strong { color: #58412b; }
.hitline { margin: 4px 0; overflow-wrap: anywhere; }

#characterDetail { display: grid; gap: 24px; align-items: start; }
.equipment h2 { margin-bottom: 9px; }
.paperdoll {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.45fr) minmax(0, 1fr);
  grid-template-areas: "first figure second";
  gap: 8px;
  align-items: start;
}
.paperdoll .portrait-frame { grid-area: figure; width: min(100%, 200px); }
.slots:first-child { grid-area: first; }
.slots:last-child { grid-area: second; }
.slots { display: grid; gap: 5px; }
.slot {
  display: grid;
  align-content: center;
  min-height: 43px;
  padding: 4px 5px;
  background: #f1e4ca;
  border: 1px solid #d3bc97;
  border-radius: 3px;
  font-size: .79rem;
  overflow-wrap: anywhere;
  text-align: center;
}
.slot small { color: var(--muted); }
.character-details h2 { margin: 12px 0 6px; }
.character-details p { margin-top: 12px; }
.character-details > p:first-child { margin-top: 0; }
.fighters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
#archiveResult { margin: 14px 0 20px; }
.history-nav { margin-top: 12px; }
.history-row { flex-wrap: wrap; }

@media (min-width: 710px) {
  #characterDetail { grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); }
  .character-details { border-left: 1px solid var(--line); padding-left: 22px; }
}
@media (min-width: 940px) {
  .room-layout { grid-template-columns: minmax(225px, .9fr) minmax(0, 2.1fr); grid-template-areas: "profile center"; }
  .room-layout.has-opponent {
    grid-template-columns: minmax(205px, 1fr) minmax(340px, 2fr) minmax(205px, 1fr);
    grid-template-areas: "profile center opponent";
  }
  .combat-layout {
    grid-template-columns: minmax(200px, 1fr) minmax(350px, 1.95fr) minmax(200px, 1fr);
    grid-template-areas: "left move right" "journal journal journal";
  }
}
@media (max-width: 660px) {
  .header-inner { min-height: 57px; padding: 8px 12px; gap: 7px 10px; flex-wrap: wrap; }
  .brand { font-size: 1.45rem; }
  .brand-mark { width: 21px; height: 22px; }
  #nav { order: 2; flex-basis: 100%; }
  #nav a { flex: 1 1 auto; min-width: min-content; min-height: 41px; padding: 4px; font-size: clamp(.78rem, 3.4vw, .92rem); }
  #logout { min-height: 36px; padding: 6px 10px; font-size: .88rem; }
  main { padding: 16px 12px 30px; }
  .onboarding { grid-template-columns: 1fr; margin-top: 0; }
  .onboarding-art { aspect-ratio: 2.25; height: auto; min-height: 0; border-bottom: 2px solid var(--ochre); }
  .intro-visual { padding: 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .intro-visual .portrait-frame { width: 140px; }
  .onboarding-content h1 { margin-bottom: 13px; }
  .room-layout, .room-center, .combat-layout { gap: 10px; }
  .room-art { aspect-ratio: 2.2; }
  .barlabel, .hp-line { font-size: .75rem; }
  .statgrid div { font-size: .81rem; }
  .battle-page > .page-heading {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 5px 0;
    background: #efe1c8;
  }
  .fighter .portrait-frame { width: min(100%, 118px); }
  .fighter .statgrid div { padding: 3px 0; }
}
@media (max-width: 430px) {
  .paperdoll { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-areas: "figure figure" "first second"; }
  .paperdoll .portrait-frame { width: 140px; }
  .card-heading, .fighter h2 { margin-bottom: 7px; }
  .portrait-frame { padding: 3px; }
  .player-row { font-size: .92rem; }
  .choices button { padding-inline: 5px; }
}
@media (max-width: 359px) {
  .barlabel, .hp-line { grid-template-columns: 1fr; gap: 1px; }
  .barlabel span:last-of-type, .hp-line span:last-of-type { text-align: left; }
  .statgrid div { font-size: .76rem; }
  #nav a { font-size: .81rem; }
  #nav:has(#navFight:not([hidden])) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
