:root {
  --bg0: #0f1412;
  --bg1: #1a221c;
  --ink: #e7ede6;
  --muted: #8a968c;
  --line: #2c382f;
  --accent: #c4a35a;
  --accent-dim: #8a7340;
  --danger: #d07060;
  --field: #121916;
  --radius: 8px;
  --font: "Instrument Sans", system-ui, sans-serif;
  --display: "Newsreader", Georgia, serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 16px;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #243028 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #1c2420 0%, transparent 50%),
    var(--bg0);
}
.wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 3.5rem;
}
header { margin-bottom: 1.5rem; }
header .brand {
  font-family: var(--display);
  font-size: clamp(2.2rem, 4vw, 3rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}
header .brand span { color: var(--accent); }
header p { margin: 0.4rem 0 0; color: var(--muted); }
a.docs {
  float: right;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.35rem;
}
a.docs:hover { color: var(--accent); }

.layout {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(420px, 1fr);
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: color-mix(in srgb, var(--bg1) 90%, black);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.25rem 1.35rem 1.5rem;
}
.panel-form {
  max-height: calc(100vh - 7rem);
  overflow: auto;
}

.tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.tabs button {
  flex: 1;
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 0.65rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
}
.tabs button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1408;
}

.section {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.05rem 1.15rem;
  margin-top: 0.9rem;
  background: color-mix(in srgb, var(--field) 65%, transparent);
}
.section:first-of-type { margin-top: 0.35rem; }
.section h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0.7rem 0 0.35rem;
}
.field-label:first-child { margin-top: 0; }

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  appearance: none;
  background: var(--field);
  border: 1px solid var(--line);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  border-radius: var(--radius);
  padding: 0.7rem 0.8rem;
}
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}
textarea { min-height: 4.5rem; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent);
  border-color: var(--accent-dim);
}

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.75rem; }
@media (max-width: 560px) {
  .row, .row3 { grid-template-columns: 1fr; }
}

.combo { position: relative; }
.combo-list {
  display: none;
  position: absolute;
  z-index: 20;
  left: 0; right: 0;
  top: calc(100% + 4px);
  max-height: 220px;
  overflow: auto;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  background: #0d1210;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
.combo.open .combo-list { display: block; }
.combo-list li {
  padding: 0.55rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
}
.combo-list li:hover, .combo-list li.active {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}
.combo-list .muted { color: var(--muted); font-size: 0.82rem; }

.flags {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem 0.85rem;
  margin-top: 0.35rem;
}
.flags label {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  margin: 0;
  cursor: pointer;
  font-size: 0.95rem;
}
.flags input[type="checkbox"] {
  appearance: auto;
  -webkit-appearance: checkbox;
  width: 1.2rem;
  height: 1.2rem;
  accent-color: var(--accent);
  flex-shrink: 0;
  cursor: pointer;
}

.effect, .mod-row, .rest-row {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-top: 0.55rem;
  background: var(--field);
}
.effect-head, .mod-row, .rest-row {
  display: flex;
  gap: 0.5rem;
  align-items: end;
}
.effect-head > div, .mod-row > div, .rest-row > div { flex: 1; }
.remove, .add-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--danger);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  white-space: nowrap;
}
.add-btn {
  width: 100%;
  margin-top: 0.65rem;
  color: var(--accent);
  border-style: dashed;
  font-weight: 600;
}

.actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.15rem;
  position: sticky;
  bottom: 0;
  padding-top: 0.75rem;
  background: linear-gradient(transparent, var(--bg1) 30%);
}
.actions button {
  appearance: none;
  border: 0;
  font: inherit;
  font-weight: 700;
  border-radius: var(--radius);
  padding: 0.8rem 1.05rem;
  cursor: pointer;
}
.actions .primary {
  background: var(--accent);
  color: #1a1408;
  flex: 1.4;
}
.actions .ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  flex: 1;
}

.error {
  margin-top: 0.75rem;
  color: var(--danger);
  white-space: pre-wrap;
}
.mode-hint { color: var(--muted); font-size: 0.9rem; margin: 0 0 0.6rem; }

.item-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.45rem; }
.item-list button {
  width: 100%; text-align: left; appearance: none;
  border: 1px solid var(--line); background: var(--field);
  color: var(--ink); font: inherit; border-radius: var(--radius);
  padding: 0.8rem 0.9rem; cursor: pointer;
}
.item-list button:hover { border-color: var(--accent-dim); }
.item-list .name { display: block; font-weight: 600; font-size: 1.05rem; }
.item-list .id { display: block; color: var(--muted); font-size: 0.82rem; font-family: ui-monospace, monospace; margin-top: 0.2rem; }

.result h2 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.7rem;
  margin: 0 0 0.35rem;
}
.codes { color: var(--muted); margin-bottom: 1rem; }
.codes code { color: var(--accent); font-family: ui-monospace, monospace; }
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.55rem;
  margin-bottom: 1rem;
}
.stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 0.65rem;
}
.stat b {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.stat span { font-size: 1.1rem; font-weight: 600; }
.effects-out { list-style: none; margin: 0 0 1rem; padding: 0; }
.effects-out li {
  border-left: 2px solid var(--accent-dim);
  padding: 0.35rem 0 0.35rem 0.75rem;
  margin-bottom: 0.5rem;
}
.effects-out strong { display: block; color: var(--accent); }
.effects-out span { color: var(--muted); font-size: 0.92rem; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
@media (max-width: 700px) { .cards { grid-template-columns: 1fr; } }
.card-slot {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #0a0d0b;
  min-height: 200px;
  display: grid;
  place-items: center;
}
.card-slot img { width: 100%; display: block; }
.card-slot .ph { color: var(--muted); padding: 2rem; text-align: center; }
.empty { color: var(--muted); padding: 1.5rem 0.25rem; }

.app-nav {
  display: flex;
  gap: 0.4rem;
  margin: 1.15rem 0 0;
}
.app-nav button {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 0.55rem 1.15rem;
  border-radius: 999px;
  cursor: pointer;
}
.app-nav button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1408;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.section .section-head h3 { margin: 0; }
.talent {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}
.talent input {
  appearance: auto;
  -webkit-appearance: checkbox;
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
  cursor: pointer;
}
.section-note {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0 0 0.85rem;
  line-height: 1.45;
}
.xp-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem 0.75rem;
}
@media (max-width: 560px) {
  .xp-fields { grid-template-columns: 1fr; }
}
.xp-hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.28rem;
}
.xp-hint b { color: var(--accent); font-weight: 600; }
#xp-life-cap {
  margin: 0.4rem 0 0;
}
#xp-life-cap.over-cap {
  color: color-mix(in srgb, var(--danger) 70%, var(--muted));
}
input.over-cap {
  border-color: color-mix(in srgb, var(--danger) 55%, var(--line));
}
.xp-group-spent {
  margin-top: 0.85rem;
  font-size: 0.88rem;
  color: var(--muted);
}
.xp-group-spent b { color: var(--accent); }

.xp-board { display: flex; flex-direction: column; gap: 1rem; }
.xp-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.xp-toolbar-flags {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.xp-toolbar-actions {
  display: flex;
  gap: 0.45rem;
}
#xp-energy-note {
  margin: 0.4rem 0 0;
}
.xp-toolbar-actions button {
  appearance: none;
  border: 1px solid var(--line);
  font: inherit;
  font-weight: 700;
  border-radius: var(--radius);
  padding: 0.55rem 0.9rem;
  cursor: pointer;
}
#xp-recalc {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1408;
}
#xp-reset {
  background: transparent;
  color: var(--muted);
}
.xp-row {
  display: grid;
  gap: 1rem;
}
.xp-row-3 { grid-template-columns: repeat(3, 1fr); }
.xp-row-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 980px) {
  .xp-row-3, .xp-row-2 { grid-template-columns: 1fr; }
}
.xp-card {
  background: color-mix(in srgb, var(--bg1) 90%, black);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.1rem 1.15rem 1.2rem;
  min-width: 0;
}
.xp-card h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}
.xp-card .section-head { margin-bottom: 0.85rem; }
.xp-head-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}
.xp-die {
  flex: 0 0 auto;
  width: 2.4rem;
  height: 2.6rem;
  display: grid;
  place-items: center;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: #1a1408;
  background:
    linear-gradient(160deg, #f0d9a0 0%, var(--accent) 55%, var(--accent-dim) 100%);
  clip-path: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
  user-select: none;
  line-height: 1;
}
.info-dice {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.15rem;
  margin: 0.75rem 0 1.15rem;
  align-items: end;
}
.info-dice figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}
.info-dice figcaption {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.3;
}
.xp-warn {
  border: 1px solid color-mix(in srgb, var(--danger) 55%, var(--accent));
  background: color-mix(in srgb, var(--danger) 14%, var(--field));
  color: #edd6b0;
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  font-size: 0.86rem;
  line-height: 1.45;
}
.xp-warn[hidden] { display: none; }
.xp-warn p { margin: 0.28rem 0 0; }
.xp-warn p:first-child { margin-top: 0; }

.xp-totals {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
}
@media (max-width: 700px) {
  .xp-totals { grid-template-columns: 1fr 1fr; }
}
.xp-total {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.75rem;
  background: var(--field);
}
.xp-total.emph { border-color: var(--accent-dim); }
.xp-total b {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.xp-total span {
  font-size: 1.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.remain.neg { color: var(--danger); }
.remain.ok { color: #8fca9a; }

.skill-block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-top: 0.55rem;
  background: var(--field);
}
.skill-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.skill-head strong { font-size: 0.92rem; }
.trans-row {
  display: flex;
  gap: 0.5rem;
  align-items: end;
  margin-top: 0.45rem;
}
.trans-row > div { flex: 1; }

.layout-single {
  grid-template-columns: 1fr;
}
.panel-form {
  max-height: none;
}
.text-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
.info-doc h2,
.info-doc h3,
.info-doc h4 {
  scroll-margin-top: 1rem;
}
.info-doc h2 {
  font-family: var(--display);
  margin: 2.1rem 0 0.6rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
}
.info-doc > nav + h2 {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}
.info-doc h3 {
  color: var(--accent);
  margin: 1.25rem 0 0.45rem;
  font-size: 1rem;
}
.info-doc h4 {
  margin: 0.9rem 0 0.4rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
}
.info-doc p, .info-doc li {
  color: var(--muted);
  line-height: 1.55;
}
.info-doc b { color: var(--ink); }
.info-doc code {
  font-family: ui-monospace, monospace;
  font-size: 0.86em;
  color: var(--accent);
}
.info-toc {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.2rem 1.15rem;
  margin-bottom: 0.5rem;
}
.info-toc h2 {
  font-size: 1.2rem;
  margin: 0 0 0.55rem;
  padding: 0;
  border: 0;
}
.info-toc ol {
  margin: 0;
  padding-left: 1.25rem;
}
.info-toc > ol > li { margin: 0.35rem 0; }
.info-toc ol ol {
  margin-top: 0.25rem;
  margin-bottom: 0.15rem;
}
.info-toc a {
  color: var(--accent);
  text-decoration: none;
}
.info-toc a:hover { text-decoration: underline; }
.info-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 0.7rem;
  margin: 0.7rem 0 1.2rem;
}
.info-gallery.gallery-art {
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
}
.info-gallery.gallery-wide {
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}
.info-gallery figure {
  margin: 0;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.info-gallery img {
  width: 100%;
  height: 88px;
  object-fit: contain;
  background: #0a0e0c;
}
.info-gallery.gallery-art img { height: 128px; }
.info-gallery.gallery-wide img { height: 110px; }
.info-gallery figcaption {
  font-size: 0.74rem;
  padding: 0.4rem 0.45rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.3;
}
.info-doc table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.6rem 0 1.1rem;
  font-size: 0.9rem;
}
.info-doc th,
.info-doc td {
  border: 1px solid var(--line);
  padding: 0.35rem 0.55rem;
  text-align: left;
}
.info-doc th {
  color: var(--ink);
  background: var(--field);
  font-weight: 600;
}
.info-doc td { color: var(--muted); }
.info-doc td code { color: var(--accent); }
.view-layout {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 900px) {
  .view-layout { grid-template-columns: 1fr; }
}
.code-load {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}
.code-load input { flex: 1; min-width: 6rem; }
.code-load button { flex: 0 0 auto; padding: 0.65rem 0.85rem; font-weight: 700; }
#xp-code {
  font-family: ui-monospace, monospace;
  font-size: 0.86rem;
}
#modal-xp-code {
  width: min(560px, 94vw);
}
#modal-xp-code .code-load { margin-bottom: 0.45rem; }
#modal-xp-code .section-note { margin-bottom: 0; }
.view-actions { display: flex; gap: 0.4rem; }
.danger-btn {
  appearance: none;
  border: 1px solid var(--danger);
  background: transparent;
  color: var(--danger);
  font: inherit;
  font-weight: 700;
  border-radius: var(--radius);
  padding: 0.55rem 0.85rem;
  cursor: pointer;
}
.app-nav { flex-wrap: wrap; }
.combo-list li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.combo-list img.origin-thumb {
  width: 36px;
  height: 24px;
  object-fit: cover;
  border-radius: 3px;
  background: #2a332c;
  flex: 0 0 auto;
}
.origin-missing {
  width: 36px;
  height: 24px;
  border-radius: 3px;
  background: repeating-linear-gradient(45deg, #3a2a20, #3a2a20 4px, #2a332c 4px, #2a332c 8px);
  flex: 0 0 auto;
}
.modal {
  width: min(720px, 94vw);
  max-height: 88vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg1);
  color: var(--ink);
  padding: 1.1rem 1.2rem 1.4rem;
}
.modal::backdrop { background: rgba(0,0,0,0.55); }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}
.modal-head h2 { margin: 0; font-family: var(--display); font-size: 1.45rem; }
.catalog-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0.5rem 0 1rem;
  max-height: 240px;
  overflow: auto;
}
.catalog-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.5rem 0.65rem;
  background: var(--field);
}
.catalog-row span { flex: 1; }
.catalog-row img {
  width: 48px;
  height: 32px;
  object-fit: cover;
  border-radius: 3px;
}
.catalog-form {
  border-top: 1px solid var(--line);
  padding-top: 0.85rem;
}
.catalog-form .primary {
  margin-top: 0.85rem;
  appearance: none;
  border: 0;
  background: var(--accent);
  color: #1a1408;
  font: inherit;
  font-weight: 700;
  border-radius: var(--radius);
  padding: 0.7rem 1rem;
  cursor: pointer;
}
.lang-result {
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--accent);
  margin: 1rem 0;
}
.lang-art { margin-top: 1rem; min-height: 160px; }
