* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #c8c8c6;
  --paper: #ecebe7;
  --paper-2: #f6f5f1;
  --ink: #2b2b2b;
  --graphite: #6b6b6b;
  --line: #8a8a86;
  --off: #c4c4bf;
  --accent: #8b3a3a;
}

body.dark {
  --bg: #2a2b2e;
  --paper: #3a3c40;
  --paper-2: #44474c;
  --ink: #e8e8e4;
  --graphite: #a4a6aa;
  --line: #5d6066;
  --off: #55585e;
  --accent: #c96a6a;
}

body {
  font-family: 'Caveat', 'Segoe Print', cursive;
  font-size: 20px;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  padding-bottom: 32px;
}

button {
  font-family: inherit;
  font-size: 18px;
  color: var(--ink);
  background: var(--paper-2);
  border: 2px solid var(--ink);
  border-radius: 3px 5px 4px 6px;
  cursor: pointer;
  padding: 2px 10px;
}

button:hover:not(:disabled) {
  background: #ffffff;
}

body.dark button:hover:not(:disabled) {
  background: #55585e;
}

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

button.ghost {
  background: transparent;
  border-style: dashed;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  border-bottom: 2px dashed var(--line);
  flex-wrap: wrap;
}

.menu {
  position: relative;
}

.menu summary {
  list-style: none;
  cursor: pointer;
  font-size: 20px;
  padding: 4px 12px;
  border: 2px solid var(--ink);
  border-radius: 3px 5px 4px 6px;
  background: var(--paper-2);
}

.menu summary::-webkit-details-marker {
  display: none;
}

.menu-list {
  position: absolute;
  top: 110%;
  left: 0;
  z-index: 20;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--line);
}

.menu-list button {
  text-align: left;
}

.menu-head {
  font-size: 16px;
  color: var(--graphite);
  margin-top: 6px;
}

.name-input {
  font-family: inherit;
  font-size: 24px;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--graphite);
  color: var(--ink);
  padding: 2px 6px;
  width: 300px;
}

.name-input:focus {
  outline: none;
  border-bottom-color: var(--ink);
}

.viewing {
  color: var(--accent);
  font-size: 18px;
}

.roll-log {
  margin-left: auto;
  font-size: 22px;
  color: var(--accent);
}

.save-status {
  font-size: 16px;
  color: var(--graphite);
}

.sheet {
  display: grid;
  grid-template-columns: 25% 35% 25%;
  justify-content: center;
  gap: 24px;
  max-width: none;
  width: 100%;
  margin: 24px 0;
  padding: 0 24px;
  align-items: start;
}

.column {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.paper {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 6px 10px 7px 11px;
  box-shadow: 3px 4px 0 var(--line);
  padding: 14px 16px;
}

h2 {
  font-size: 24px;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.pool {
  font-size: 22px;
  min-width: 36px;
  text-align: center;
  line-height: 1.2;
  padding: 0 6px;
}

/* Info tooltips */
.tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: 6px;
  border: 1.5px solid var(--graphite);
  border-radius: 50%;
  font-size: 13px;
  color: var(--graphite);
  position: relative;
  cursor: help;
  vertical-align: middle;
}

.tip:hover::after,
.tip:focus::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  top: 140%;
  transform: translateX(-50%);
  width: 260px;
  z-index: 30;
  background: #353535;
  color: #f4f2ec;
  padding: 8px 10px;
  font-size: 16px;
  line-height: 1.3;
  border-radius: 4px;
  text-align: left;
  pointer-events: none;
}

/* Attributes */
.attr {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 0 12px;
  border-bottom: 1px dashed var(--line);
}

.attr:last-child {
  border-bottom: none;
}

.attr-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.attr-name {
  font-size: 22px;
  font-weight: 700;
}

.attr-name .lvl {
  font-size: 16px;
  font-weight: 400;
  color: var(--graphite);
  margin-left: 4px;
}

.roll-btn {
  font-size: 16px;
  padding: 0 8px;
}

.dice-row {
  display: flex;
  gap: 6px;
}

.die-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 0;
  color: var(--off);
  background: transparent;
  border-color: var(--off);
}

.die-btn svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}

.die-btn span {
  font-size: 13px;
  color: var(--graphite);
}

.die-btn.on {
  color: var(--ink);
  border-color: var(--ink);
  background: var(--paper-2);
}

/* Vitals */
.vitals h2 {
  margin-bottom: 10px;
}

.vital {
  margin-bottom: 10px;
}

.vital-head {
  display: flex;
  justify-content: space-between;
  font-size: 18px;
}

.bar {
  height: 16px;
  border: 2px solid var(--ink);
  background: var(--paper-2);
  margin: 3px 0;
  overflow: hidden;
}

.fill {
  height: 100%;
  background: repeating-linear-gradient(90deg, var(--ink) 0 10px, transparent 10px 12px);
}

.fill.spirit {
  background: repeating-linear-gradient(90deg, var(--accent) 0 10px, transparent 10px 12px);
}

.vital-btns {
  display: flex;
  gap: 6px;
}

.vital-btns button {
  font-size: 16px;
  padding: 0 10px;
}

.wound-title {
  font-size: 18px;
  color: var(--graphite);
  margin: 10px 0 4px;
}

.wound-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.wound-row .label {
  width: 60px;
  font-size: 18px;
  color: var(--graphite);
}

.wound-box {
  width: 24px;
  height: 24px;
  padding: 0;
}

.wound-box.on {
  background: var(--accent);
  border-color: var(--accent);
}

.derived-rows {
  margin-top: 10px;
  border-top: 2px dashed var(--line);
  padding-top: 8px;
  display: grid;
  gap: 2px;
}

.derived-rows .row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 18px;
}

.derived-rows .row span {
  color: var(--graphite);
}

/* Center stage */
.stage {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.picker-row {
  display: flex;
  justify-content: center;
}

.picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 320px;
}

.picker-label {
  font-size: 16px;
  color: var(--graphite);
}

.picker-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.picker-nav .name {
  font-size: 26px;
  font-weight: 700;
  min-width: 240px;
  text-align: center;
}

.stage-figure {
  text-align: center;
}

.figure-wrap {
  position: relative;
  width: 100%;
  max-width: 380px;
  aspect-ratio: 832 / 1248;
  margin: 0 auto;
}

.figure-wrap img,
.figure-wrap svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#figWeaponImg {
  position: absolute;
  inset: auto;
  width: auto;
  height: auto;
}

.figure-wrap img[hidden] {
  display: none;
}

.stage-figure {
  background: #ecebe7;
  color: #2b2b2b;
}

.stage-figure .caption {
  color: #555;
}

.caption {
  font-size: 20px;
  margin-top: 6px;
  color: var(--graphite);
}

/* Slots and cards */
.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.card {
  position: relative;
  width: 100%;
  aspect-ratio: 63.5 / 88.5;
  background: #fbfaf6;
  color: #222;
  border: 2px solid #353535;
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  text-align: left;
  padding: 0;
  font-weight: 400;
  font-family: inherit;
}

.card .c-title {
  background: #353535;
  color: #f4f2ec;
  font-size: 16px;
  font-weight: 700;
  padding: 1px 6px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card .c-art {
  flex: 1.5;
  border-bottom: 1.5px solid #353535;
  display: flex;
  align-items: center;
  justify-content: center;
  background: repeating-linear-gradient(45deg, #f0eee8 0 6px, #e6e4dd 6px 7px);
  overflow: hidden;
}

.card .c-art svg {
  width: 80%;
  height: 80%;
}

.card .c-type {
  font-size: 13px;
  font-weight: 700;
  border-bottom: 1.5px solid #353535;
  padding: 0 6px;
  line-height: 1.4;
}

.card .c-text {
  flex: 1;
  font-size: 14px;
  padding: 3px 6px;
  line-height: 1.2;
  color: #333;
}

.card.empty {
  background: transparent;
  border: 2px dashed var(--line);
  color: var(--graphite);
  align-items: center;
  justify-content: center;
  font-size: 18px;
  border-radius: 3px;
}

.card.empty:hover {
  border-color: var(--ink);
  color: var(--ink);
  background: transparent;
}

.card .x {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  background: #fbfaf6;
  color: #353535;
  border: 1.5px solid #353535;
  border-radius: 50%;
  z-index: 2;
}

.card-input {
  font-family: inherit;
  font-size: 16px;
  border: none;
  border-bottom: 2px solid #353535;
  background: transparent;
  padding: 4px 6px;
  margin: 6px;
  color: #222;
  width: calc(100% - 12px);
}

.card-input:focus {
  outline: none;
}

.picker-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  margin-top: 8px;
  border: 2px solid var(--ink);
  background: var(--paper-2);
}

.picker-list button {
  font-size: 16px;
}

.new-panel {
  max-width: 1000px;
  margin: 18px auto 0;
}

.new-row {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

#createBtn {
  font-size: 20px;
  padding: 6px 16px;
}

.pickers {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 24px;
}

.choices {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.choice-label {
  font-size: 16px;
  color: var(--graphite);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.chip {
  font-size: 16px;
  padding: 0 8px;
}

.chip.on {
  background: var(--ink);
  color: var(--paper);
}

.small {
  font-size: 16px;
  color: var(--graphite);
}

.skill-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 19px;
}

.skill-name {
  display: flex;
  align-items: center;
}

.skill-btns {
  display: flex;
  align-items: center;
  gap: 6px;
}

.skill-btns button {
  font-size: 16px;
  padding: 0 8px;
}

.skill-btns .lvl {
  min-width: 18px;
  text-align: center;
  font-weight: 700;
}

.segs {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin: 4px 0 10px;
}

.seg {
  width: 14px;
  height: 20px;
  padding: 0;
  border-width: 2px;
  border-radius: 2px;
  background: var(--paper-2);
}

.seg.stamina.on {
  background: #b53a3a;
  border-color: #b53a3a;
}

.seg.spirit.on {
  background: #3a6fb5;
  border-color: #3a6fb5;
}

/* Small playing-card slots, enlarged on hover */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 12px;
}

.card {
  width: 100%;
  aspect-ratio: 63.5 / 88.5;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card:not(.empty):hover {
  transform: scale(2);
  transform-origin: center;
  z-index: 40;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

.card.empty {
  cursor: pointer;
}

.card .c-title {
  font-size: 12px;
}

.card .c-type {
  font-size: 10px;
}

.card .c-text {
  font-size: 10px;
  overflow: hidden;
}

.card .c-art img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
}

.card .x {
  width: 18px;
  height: 18px;
  font-size: 11px;
}

/* Popups */
.modal,
.roll-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

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

.modal-box {
  width: min(560px, 92vw);
  max-height: 86vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-search {
  font-family: inherit;
  font-size: 18px;
  padding: 6px 8px;
  border: 2px solid var(--ink);
  background: #fbfaf7;
  color: #2b2b2b;
}

.modal-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 300px;
  overflow: auto;
}

.modal-list button {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.modal-list .opt-text {
  font-size: 15px;
  color: var(--graphite);
  white-space: normal;
}

.modal-create {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 2px dashed var(--line);
  padding-top: 10px;
}

.modal-create h3 {
  font-size: 20px;
}

.modal-text {
  font-family: inherit;
  font-size: 16px;
  min-height: 70px;
  padding: 6px 8px;
  border: 2px solid var(--ink);
  background: #fbfaf7;
  color: #2b2b2b;
}

.modal-close {
  align-self: flex-end;
}

.roll-box {
  width: min(360px, 90vw);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.roll-label {
  font-size: 22px;
  color: var(--graphite);
}

.roll-number {
  font-size: 96px;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
}

.roll-number.rolling {
  animation: tumble 0.12s linear infinite;
}

.roll-detail {
  font-size: 20px;
}

@keyframes tumble {
  0% { transform: rotate(-8deg) scale(1.05); }
  50% { transform: rotate(8deg) scale(0.95); }
  100% { transform: rotate(-8deg) scale(1.05); }
}

/* Deadly wound: pencil cross over the figure */
#deadlyCross {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#deadlyCross[hidden] {
  display: none;
}

.pencil-cross path {
  fill: none;
  stroke: #2b2b2b;
  stroke-width: 22;
  stroke-linecap: round;
  opacity: 0.7;
}

.pencil-cross path:nth-child(2n) {
  stroke-width: 10;
  opacity: 0.45;
}

.check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 18px;
  cursor: pointer;
}

.check input {
  width: 18px;
  height: 18px;
}

.card:not(.empty):hover {
  transform: scale(2.8);
}

.card .c-title {
  font-size: 10px;
  padding: 1px 4px;
}

.card .c-type {
  font-size: 8px;
  padding: 1px 4px;
  line-height: 1.3;
}

.card .c-meta {
  font-size: 8px;
  padding: 1px 4px;
  border-bottom: 1px solid #353535;
  color: #444;
  line-height: 1.3;
}

.card .c-text {
  font-size: 8px;
  padding: 2px 4px;
  line-height: 1.25;
}

.card .c-to-scar {
  position: absolute;
  bottom: 2px;
  left: 2px;
  font-size: 8px;
  padding: 0 4px;
  background: #fbfaf6;
  color: #353535;
  border: 1px solid #353535;
  border-radius: 3px;
  z-index: 2;
}

.roll-die {
  position: relative;
  width: 200px;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.roll-die svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: var(--paper-2);
  stroke: var(--ink);
  stroke-width: 0.6;
  stroke-linejoin: round;
}

.roll-die svg.rolling {
  animation: spin 0.5s linear infinite;
}

.roll-number {
  position: relative;
  font-size: 56px;
  color: var(--ink);
}

.roll-number.rolling {
  animation: none;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.figure-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.figure-layer img {
  position: absolute;
  height: auto;
}

#figHelmetImg {
  position: absolute;
  inset: auto;
  height: auto;
}

#figHelmetImg[hidden] {
  display: none;
}

.skill-row {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding: 6px 0;
}

.skill-top,
.skill-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.skill-bottom .roll-btn {
  font-size: 15px;
  padding: 0 8px;
}

.bonus {
  margin-left: 6px;
  font-size: 15px;
  color: var(--accent);
  font-weight: 700;
}

.xp {
  display: flex;
  gap: 4px;
}

.xp-box {
  width: 16px;
  height: 16px;
  padding: 0;
  border-width: 2px;
}

.xp-box.on {
  background: var(--ink);
  border-color: var(--ink);
}

details.fold > summary {
  list-style: none;
  cursor: pointer;
}

details.fold > summary::-webkit-details-marker {
  display: none;
}

details.fold > summary h2 {
  margin-bottom: 8px;
}

.chev {
  margin-left: auto;
  font-size: 18px;
  color: var(--graphite);
  transition: transform 0.15s;
}

details.fold:not([open]) .chev {
  transform: rotate(-90deg);
}

details.fold:not([open]) > summary h2 {
  border-bottom: none;
  margin-bottom: 0;
}

.xp-lines {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.xp-line {
  flex: 1;
  height: 9px;
  padding: 0;
  border-width: 2px;
  border-radius: 1px;
  background: var(--paper-2);
}

.xp-line.on {
  background: var(--ink);
  border-color: var(--ink);
}

/* Dice roll popup */
.roll-box {
  width: min(640px, 94vw);
  max-height: 92vh;
  overflow: auto;
}

.roll-hint {
  font-size: 16px;
  color: var(--graphite);
  margin: 0;
}

.roll-dice {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 18px;
  min-height: 190px;
  width: 100%;
  cursor: pointer;
}

.roll-die {
  position: relative;
  width: 160px;
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.roll-die svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: var(--paper-2);
  stroke: var(--ink);
  stroke-width: 0.6;
  stroke-linejoin: round;
}

.roll-die.spinning {
  animation: spin 3s linear infinite;
}

.roll-die.landing {
  animation: landIn 0.35s ease-out;
}

.roll-die.explode svg {
  stroke: var(--accent);
  stroke-width: 1;
}

.roll-die.chosen svg {
  fill: #f6e6a8;
}

.roll-die.dim {
  opacity: 0.35;
}

.roll-die .roll-number {
  position: relative;
  font-size: 52px;
  line-height: 1;
  color: var(--ink);
  font-weight: 700;
}

@keyframes landIn {
  0% { transform: scale(0.4); opacity: 0; }
  70% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); }
}

.roll-choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.roll-choices button {
  font-size: 22px;
  padding: 4px 14px;
}

.roll-explain {
  font-size: 18px;
  line-height: 1.4;
  text-align: left;
  width: 100%;
}

.roll-explain small {
  color: var(--graphite);
}

/* Advantage / disadvantage counters */
.mods {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 18px;
}

.mods button {
  font-size: 16px;
  width: 28px;
  height: 28px;
  padding: 0;
}

.mods span[id] {
  min-width: 18px;
  text-align: center;
  font-weight: 700;
}

.mod-label {
  color: var(--graphite);
  margin-left: 6px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  margin-left: 6px;
  vertical-align: middle;
}

.icon-btn svg {
  display: block;
  width: 15px;
  height: 15px;
  fill: var(--paper-2);
  stroke: var(--ink);
  stroke-width: 1.4;
}

/* Small shake while the dice are rolling */
.roll-die.spinning svg,
.roll-die.spinning .roll-number {
  animation: jitter 0.14s steps(2) infinite;
}

@keyframes jitter {
  0% { transform: translate(-1.5px, 0.5px); }
  50% { transform: translate(1.5px, -0.5px); }
  100% { transform: translate(-0.5px, 1px); }
}

/* Pool counters: red while points are still open, hidden when all are used */
.pool {
  margin-left: 14px;
}

.pool.open {
  color: #b53a3a;
  border: 2px solid #b53a3a;
  border-radius: 50%;
  padding: 0 7px;
}

.skill-bonus-remove {
  font-size: 13px;
  padding: 0 5px;
  margin-left: 4px;
  line-height: 1.2;
}

.card .x {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  z-index: 3;
}

body.dark .roll-die.chosen svg {
  fill: #6b5418;
}

.card.deadly {
  border-color: #7a1f1f;
  box-shadow: inset 0 0 0 2px #7a1f1f;
}

.card .c-type.lvl-minor {
  background: #efe4c2;
}

.card .c-type.lvl-major {
  background: #efc7bf;
}

/* Movable panels */
.panel {
  position: relative;
}

.grip {
  cursor: grab;
  text-align: center;
  font-size: 18px;
  line-height: 1;
  color: var(--graphite);
  user-select: none;
  margin-bottom: 2px;
}

.grip:active {
  cursor: grabbing;
}

.panel.dragging {
  opacity: 0.5;
}

.drop-col {
  min-height: 160px;
}

.notes-area {
  width: 100%;
  min-height: 120px;
  font-family: inherit;
  font-size: 18px;
  padding: 8px;
  background: #fbfaf7;
  color: #2b2b2b;
  border: 2px solid var(--ink);
  resize: vertical;
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card .x {
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  border-width: 1.5px;
}

.card .x > * {
  margin: 0;
}

/* Grip sits on the same line as the panel title */
.panel > .grip {
  position: absolute;
  left: 10px;
  top: 14px;
  margin: 0;
  font-size: 18px;
  line-height: 1;
  z-index: 2;
}

details.fold > summary h2 {
  padding-left: 26px;
}

#figPortrait {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#figPortrait[hidden] {
  display: none;
}

.submenu {
  border: 1px dashed var(--line);
  padding: 4px 6px;
}

.submenu > summary {
  cursor: pointer;
  font-size: 18px;
  list-style: none;
  padding: 2px 0;
}

.submenu > summary::-webkit-details-marker {
  display: none;
}

.submenu > summary::after {
  content: ' â–¸';
  color: var(--graphite);
}

.submenu[open] > summary::after {
  content: ' â–¾';
}

.submenu-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 0 4px 14px;
}

.menu-list .submenu-body button,
.menu-list .submenu-body .check,
.menu-list .submenu-body .pixel-label {
  font-size: 15px;
  padding: 3px 8px;
}

.submenu-body > button {
  justify-content: flex-start;
  text-align: left;
}

.options-menu {
  margin-left: auto;
}

.options-menu .menu-list {
  left: auto;
  right: 0;
  min-width: 260px;
}

.options-menu .menu-list > * {
  display: flex;
  align-items: center;
  gap: 8px;
}

.options-menu .menu-list > button {
  justify-content: flex-start;
}

.portrait-tools {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

.pixel-label {
  display: inline-block;
  font-size: 18px;
  padding: 2px 10px;
  border: 2px solid var(--ink);
  border-radius: 3px 5px 4px 6px;
  background: var(--paper-2);
  cursor: pointer;
}

.menu-link {
  display: block;
  padding: 6px 4px;
  color: var(--ink);
  font-size: 18px;
}

/* One look for every entry in the menu: buttons, links, upload and checkboxes */
.menu-list button,
.menu-list .menu-link,
.menu-list .pixel-label,
.menu-list .check {
  display: flex;
  align-items: center;
  gap: 8px;
  box-sizing: border-box;
  width: 100%;
  margin: 0;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 18px;
  color: var(--ink);
  background: var(--paper-2);
  border: 2px solid var(--ink);
  border-radius: 3px 5px 4px 6px;
  text-decoration: none;
  text-align: left;
  cursor: pointer;
}

.menu-list button:hover,
.menu-list .menu-link:hover,
.menu-list .pixel-label:hover,
.menu-list .check:hover {
  background: #ffffff;
}

body.dark .menu-list button:hover,
body.dark .menu-list .menu-link:hover,
body.dark .menu-list .pixel-label:hover,
body.dark .menu-list .check:hover {
  background: #55585e;
}

.menu-list .check input {
  margin: 0;
  width: 18px;
  height: 18px;
}

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

/* Pokï¿½Pan: trainer and Pokï¿½mon tabs */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 24px 0;
  border-bottom: 2px solid var(--ink);
}

.tab-wrap {
  display: inline-flex;
  align-items: stretch;
}

.tab {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom: none;
  padding: 4px 14px;
}

.tab.on {
  background: var(--paper);
  font-weight: 700;
}

.tab-close {
  border-left: none;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom: none;
  padding: 2px 8px;
}

.small-slot {
  margin-top: 6px;
  font-size: 16px;
  padding: 1px 8px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 8px 0;
}

.level-feat {
  padding: 6px 0;
  border-bottom: 1px dashed var(--line);
  display: flex;
  flex-direction: column;
}

.level-feat:not(.on) {
  opacity: 0.45;
}

/* Pokï¿½Pan: hold to confirm, level up, ability card */
.hold-btn {
  background: linear-gradient(90deg, #d9a0a0 var(--hold, 0%), var(--paper-2) var(--hold, 0%));
  user-select: none;
  touch-action: none;
}

.hold-btn.holding {
  border-style: dashed;
}

.card .x.hold-btn {
  width: 22px;
  height: 22px;
}

.levelup-btn {
  margin-top: 6px;
}

.species-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.card.ability {
  border-style: double;
}

/* Pokï¿½Pan: Pokï¿½mon artwork in the paper style */
/* Artwork keeps its own proportions: the figure box follows the image instead of stretching it. */
.figure-wrap.pokemon-art {
  aspect-ratio: auto;
}

.figure-wrap.pokemon-art img {
  position: static;
  width: 100%;
  height: auto;
}

/* Small art (cards, feats) only gets a grey filter: the ink filter is too coarse at this size. */
.pokemon-art img,
.feat-art img {
  filter: grayscale(0.9) contrast(0.95) brightness(1.06);
  mix-blend-mode: multiply;
}

/* Large figure: pencil-sketch look with dark ink on edges (filter #sketch in character.html). */
.figure-wrap.pokemon-art img {
  filter: url(#sketch);
}

.feat-art img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}

.confirm-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
}

/* Pokï¿½Pan: playing-card layout shared by feats, items, conditions and Pokï¿½mon */
.pcard {
  position: relative;
  width: 100%;
  min-width: 0;
  aspect-ratio: 5 / 7;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: var(--paper-2);
  border: 2px solid var(--ink);
  border-radius: 8px;
  text-align: left;
  font-size: 14px;
  color: var(--ink);
  overflow: hidden;
}

button.pcard {
  padding: 6px;
  font-size: 14px;
}

button.pcard:hover:not(:disabled) {
  background: var(--paper-2);
}

.pcard.empty {
  align-items: center;
  justify-content: center;
  background: transparent;
  border-style: dashed;
  box-shadow: none;
  color: var(--graphite);
  text-align: center;
}

.pc-plus {
  font-size: 30px;
  line-height: 1;
}

.pc-top {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
}

.pc-action {
  flex: 0 0 14px;
  width: 14px;
  height: 14px;
}

.pc-action svg {
  display: block;
  width: 100%;
  height: 100%;
}

.pc-name {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
}

.pc-badge {
  display: inline-block;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 1px 5px;
  border: 1.5px solid var(--ink);
  border-radius: 9px;
  color: #fff;
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

.pc-badge.dark {
  color: #2b2b2b;
  text-shadow: none;
}

/* Artwork fills a fixed window; the image is cropped to fit, never stretched. */
.pc-art {
  width: 100%;
  aspect-ratio: 2 / 1;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1.5px solid var(--ink);
  background: var(--off);
}

.pc-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: grayscale(0.9) contrast(0.95) brightness(1.06);
  mix-blend-mode: multiply;
}

.pc-cat {
  font-size: 12px;
  color: var(--graphite);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pc-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.15;
}

.pc-flavour {
  font-style: italic;
  color: var(--graphite);
  margin-bottom: 2px;
}

.pc-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-size: 12px;
}

.pc-foot .small-slot {
  margin: 0;
  padding: 0 6px;
  font-size: 12px;
}

.pc-dmg {
  font-weight: 700;
  padding: 0 4px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
}

.pc-x {
  margin-left: auto;
  width: 14px;
  height: 14px;
  padding: 0;
  line-height: 1;
  font-size: 11px;
  border: none;
  background: none;
  box-shadow: none;
  color: var(--graphite);
}

.pc-x:hover:not(:disabled) {
  background: none;
  color: var(--ink);
}

/* Hovering a card magnifies it like a zoomed card: same proportions and content, raised above its neighbours. */
.pcard:not(.empty):hover {
  transform: scale(3.2);
  z-index: 50;
}

.card-grid {
  position: relative;
}

.card-grid:has(.pcard:hover) {
  z-index: 50;
}

/* Type matchups for Pokï¿½mon */
.matchups {
  margin-top: 8px;
}

.matchups h4 {
  font-size: 17px;
  margin-bottom: 4px;
}

.mu-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 3px 0;
  flex-wrap: wrap;
}

.mu-label {
  min-width: 62px;
  font-size: 13px;
  font-weight: 700;
}

.mu-label.weak {
  color: var(--accent);
}

.mu-label.resist {
  color: var(--graphite);
}

.mu-types {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* Cards without artwork show a category symbol in the same picture window */
.pc-glyph {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  color: var(--graphite);
}

.pc-glyph svg {
  width: 40%;
  height: 80%;
}

/* Card header and species line */
.pc-top {
  align-items: center;
}

.pc-name {
  line-height: 1;
  text-align: left;
}

.pc-badge-slot {
  display: flex;
  align-items: center;
}

.pc-badge {
  line-height: 1;
  height: 14px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  box-sizing: border-box;
}

.pc-sub {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 2px;
}

/* Pokï¿½mon artwork fits the whole image inside the frame; the frame keeps its size. */
.pc-art.pc-art-contain img {
  object-fit: contain;
}

.pcard:not(.empty):hover {
  transform: scale(2.47);
}

/* Level in the top-left corner of a Pokémon card, and type badges in a row */
.pc-level {
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.pc-badge-slot,
.pc-types {
  display: flex;
  align-items: center;
  gap: 3px;
}

/* Dual types: smaller badges so both fit beside the title */
.pc-badge.small {
  font-size: 6px;
  height: 11px;
  padding: 0 3px;
}

/* Pokémon vitals tab: type badges are larger, also for dual types */
.pc-types .pc-badge.small,
.pc-types .pc-badge {
  font-size: 12px;
  height: 20px;
  padding: 0 8px;
}

/* Trainer portrait upload and Pokémon placeholder */
.figure-wrap img.portrait-art {
  object-fit: contain;
}

.figure-glyph {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--graphite);
}

.figure-glyph svg {
  width: 45%;
  height: 45%;
}

.figure-controls {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 6px;
}

.upload-label {
  cursor: pointer;
  display: inline-block;
}

/* Centre the Poké Ball placeholder (overrides the general figure svg rule) */
.figure-wrap .figure-glyph svg {
  position: static;
  width: 45%;
  height: auto;
  aspect-ratio: 1 / 1;
}
