/* =========================================================================
   Attack Resolver — Destiny Kingdom
   Grim fantasy, with a glimmer of hope: obsidian black, dried blood red,
   deep forest green, royal blue, and a single thread of gold.

   Two supported screens:
   - Laptop (~1366–1920 px): compact base size
   - 27"–32" monitors (>= 2200 px): scaled up
   ========================================================================= */

:root {
  --ink:        #0c0a0e;   /* near-black, cold */
  --panel:      #161219;   /* raised panel */
  --panel-2:    #1d1723;   /* inner panel */
  --edge:       #2c2433;   /* hairline borders */
  --blood:      #8e1f1f;   /* deep red */
  --blood-hi:   #c23a2c;   /* ember red */
  --green:      #1f4d3a;   /* deep green */
  --green-hi:   #2f7a58;
  --royal:      #27407a;   /* royal blue */
  --royal-hi:   #3f63b4;
  --gold:       #c9a23a;   /* the glimmer */
  --gold-dim:   #8a6e24;
  --text:       #e9e0cb;   /* parchment */
  --text-dim:   #a89e89;
  --danger-txt: #e07a6a;

  --font-display: "Cinzel", "Times New Roman", serif;
  --font-body: "Alegreya Sans", "Segoe UI", system-ui, sans-serif;

  font-size: 15px;
}

/* 27"–32" screens */
@media (min-width: 2200px) {
  :root { font-size: 19px; }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 50% -200px, #191320 0%, transparent 60%),
    var(--ink);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.45;
}

h1, h2, h3, legend { font-family: var(--font-display); font-weight: 700; }

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- header */

.masthead {
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
  padding: 0.7rem 1.4rem 0.55rem;
}

.masthead h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: 0.14em;
  color: var(--gold);
  text-transform: uppercase;
}

.masthead .realm {
  color: var(--text-dim);
  font-size: 0.85rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.masthead .spacer { flex: 1; }

.masthead label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
}

.masthead .who { color: var(--text-dim); font-size: 0.85rem; }
.masthead .who b { color: var(--text); font-weight: 600; }

/* The destiny thread: a single line of gold across the dark */
.destiny-thread {
  height: 2px;
  background: linear-gradient(90deg,
    transparent 0%, var(--gold-dim) 12%, var(--gold) 50%,
    var(--gold-dim) 88%, transparent 100%);
  box-shadow: 0 0 12px rgba(201, 162, 58, 0.35);
  margin-bottom: 0.9rem;
}

/* ---------------------------------------------------------------- layout */

.workspace {
  display: grid;
  grid-template-columns: 15.5rem 20rem minmax(17rem, 1.1fr) 19rem;
  gap: 0.9rem;
  padding: 0 1.4rem 1.5rem;
  max-width: 100rem;
  margin: 0 auto;
  align-items: start;
}

.column { display: flex; flex-direction: column; gap: 0.9rem; }

.panel {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 0.85rem 0.95rem 1rem;
}

.panel > h2 {
  margin: 0 0 0.7rem;
  font-size: 0.82rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
  border-bottom: 1px solid var(--edge);
  padding-bottom: 0.45rem;
}

/* ---------------------------------------------------------------- fields */

.field { margin-bottom: 0.6rem; }
.field:last-child { margin-bottom: 0; }

.field > label {
  display: block;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.2rem;
}

.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--edge);
  border-radius: 3px;
  padding: 0.4rem 0.5rem;
  color: var(--text);
}

.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible,
button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.field textarea { resize: vertical; min-height: 5.5rem; }
.field textarea:disabled { color: var(--text-dim); }

.inline { display: flex; gap: 0.5rem; align-items: end; }
.inline .field { flex: 1; }

/* stances */
.stances { display: grid; gap: 0.25rem; margin: 0.4rem 0 0.6rem; }
.stances label {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.28rem 0.45rem;
  border: 1px solid var(--edge);
  border-radius: 3px;
  cursor: pointer;
  color: var(--text-dim);
}
.stances input { accent-color: var(--gold); }
.stances label:has(input:checked) {
  color: var(--text);
  border-color: var(--gold-dim);
  background: rgba(201, 162, 58, 0.06);
}

/* ---------------------------------------------------------------- buttons */

button {
  cursor: pointer;
  border: 1px solid var(--edge);
  border-radius: 3px;
  background: var(--panel-2);
  color: var(--text);
  padding: 0.42rem 0.85rem;
  transition: filter 120ms ease, border-color 120ms ease;
}
button:hover { filter: brightness(1.18); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-hit {
  background: linear-gradient(180deg, #a02620, var(--blood));
  border-color: #5c1512;
  font-family: var(--font-display);
  font-size: 1.02rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  padding: 0.55rem 1rem;
  width: 100%;
}

.btn-forge {
  background: linear-gradient(180deg, #276146, var(--green));
  border-color: #143526;
}

.btn-royal { background: linear-gradient(180deg, #33508f, var(--royal)); border-color: #1a2b52; }

.btn-doom { background: linear-gradient(180deg, #7e2620, #591713); border-color: #3c0f0c; color: #f0d9d4; }

.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); }

.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.btn-row > * { flex: 1; }

/* info "?" buttons */
.info-btn {
  flex: 0 0 auto;
  width: 1.35rem; height: 1.35rem;
  padding: 0;
  border-radius: 50%;
  border-color: var(--gold-dim);
  color: var(--gold);
  font-family: var(--font-display);
  font-size: 0.8rem;
  line-height: 1;
  background: transparent;
}

/* ------------------------------------------------------ result plaque
   The signature element: an obsidian slab bound in gold where the
   verdict of every strike is written. */

.result-plaque {
  position: relative;
  border: 1px solid var(--gold-dim);
  border-radius: 4px;
  background:
    linear-gradient(160deg, #191219 0%, #0e0a10 65%, #140d12 100%);
  box-shadow: inset 0 0 30px rgba(0,0,0,0.7);
  padding: 0.85rem 0.9rem 0.95rem;
  text-align: center;
}
.result-plaque::before {
  content: "";
  position: absolute; inset: 4px;
  border: 1px solid rgba(201, 162, 58, 0.25);
  border-radius: 2px;
  pointer-events: none;
}
.result-plaque .caption {
  font-size: 0.72rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.result-plaque .verdict {
  font-family: var(--font-display);
  font-size: 2.3rem;
  line-height: 1.15;
  color: var(--text);
  min-height: 2.6rem;
  text-shadow: 0 0 18px rgba(194, 58, 44, 0);
  transition: text-shadow 400ms ease, color 400ms ease;
}
.result-plaque.struck .verdict {
  color: #f4e6c8;
  text-shadow: 0 0 22px rgba(194, 58, 44, 0.85);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------------------------------------------------------------- stats */

.stats-grid { display: grid; grid-template-columns: 1fr auto auto; gap: 0.3rem 0.5rem; align-items: center; }
.stats-grid .stat-label { font-size: 0.82rem; color: var(--text-dim); }
.stats-grid .stat-value {
  min-width: 5.2rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  background: var(--panel-2);
  border: 1px solid var(--edge);
  border-radius: 3px;
  padding: 0.18rem 0.45rem;
}
.stats-grid .stat-value.negative { color: var(--danger-txt); border-color: var(--blood); }
.stats-divider { grid-column: 1 / -1; border-top: 1px solid var(--edge); margin: 0.25rem 0; }

/* ------------------------------------------------------ customization */

.custom-row {
  display: grid;
  grid-template-columns: 6.4rem 1fr auto auto;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.4rem;
}
.custom-row .cat {
  font-size: 0.78rem;
  text-transform: capitalize;
  color: var(--text-dim);
}
.picker-btn {
  width: 100%;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--panel-2);
}
.picker-btn.has-picks { border-color: var(--green-hi); }

.picker-pop {
  position: absolute;
  z-index: 30;
  background: var(--panel-2);
  border: 1px solid var(--gold-dim);
  border-radius: 4px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.7);
  padding: 0.6rem 0.75rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(8rem, 1fr));
  gap: 0.15rem 1rem;
  max-width: 24rem;
}
.picker-pop label {
  display: flex; gap: 0.4rem; align-items: center;
  font-size: 0.88rem; cursor: pointer; padding: 0.12rem 0;
}
.picker-pop input { accent-color: var(--green-hi); }
.picker-pop .pop-close { grid-column: 1 / -1; margin-top: 0.4rem; }

/* ---------------------------------------------------------------- armory */

.weapon-figure {
  border: 1px solid var(--edge);
  border-radius: 4px;
  background: var(--panel-2);
  min-height: 18rem;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.weapon-figure img { max-width: 100%; max-height: 26rem; display: block; }
.weapon-figure .no-image { color: var(--text-dim); font-size: 0.85rem; }

/* ------------------------------------------------------------- crit panel */

.crit-panel { border-color: var(--gold-dim); }
.crit-panel > h2 { color: var(--gold); }
.crit-result {
  white-space: pre-wrap;
  background: var(--panel-2);
  border: 1px solid var(--edge);
  border-radius: 3px;
  min-height: 7.5rem;
  padding: 0.5rem 0.6rem;
  font-size: 0.92rem;
}

/* ---------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(5, 3, 7, 0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--panel);
  border: 1px solid var(--gold-dim);
  border-radius: 4px;
  max-width: 46rem;
  width: min(92vw, 46rem);
  max-height: 82vh;
  display: flex; flex-direction: column;
}
.modal header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--edge);
}
.modal header h3 { margin: 0; color: var(--gold); font-size: 1rem; letter-spacing: 0.1em; }
.modal .modal-body { padding: 0.9rem 1rem; overflow: auto; }
.modal .modal-body pre {
  margin: 0; white-space: pre-wrap; font-size: 0.85rem;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--text);
}

/* toast */
.toast {
  position: fixed;
  bottom: 1.2rem; left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--gold-dim);
  border-radius: 4px;
  padding: 0.5rem 1rem;
  color: var(--text);
  z-index: 60;
  transition: opacity 300ms ease;
}
.toast.error { border-color: var(--blood-hi); color: var(--danger-txt); }
.toast.hidden { opacity: 0; pointer-events: none; }

.hidden { display: none !important; }

/* ---------------------------------------------------------------- login */

.gate {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  gap: 1.4rem;
  padding: 2rem 1rem;
}
.gate .seal {
  width: 5.5rem; height: 5.5rem;
  border: 2px solid var(--gold);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 2.2rem;
  color: var(--gold);
  box-shadow: 0 0 30px rgba(201, 162, 58, 0.25),
              inset 0 0 20px rgba(201, 162, 58, 0.12);
}
.gate h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  text-align: center;
}
.gate .sub { color: var(--text-dim); letter-spacing: 0.25em; text-transform: uppercase; font-size: 0.75rem; }
.gate form {
  width: min(92vw, 22rem);
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 1.3rem 1.4rem 1.5rem;
  display: grid; gap: 0.8rem;
}
.gate .error {
  color: var(--danger-txt);
  border: 1px solid var(--blood);
  border-radius: 3px;
  padding: 0.45rem 0.6rem;
  font-size: 0.88rem;
}

.sub-center { text-align: center; }
