/* ------------------------------------------------------------
   Admin mode
   ------------------------------------------------------------ */
:root {
  --blue: #1a5cff;
  --blue-dark: #0b3bb8;
  --ink: #141a2b;
  --ink-2: #545d78;
  --ink-3: #8a92ab;
  --line: #e2e7f1;
  --bg: #f4f7fc;
  --card: #ffffff;
  --red: #d8274d;
  --green: #12895a;
  --amber: #b26b00;
  --font: "Rubik", "Helvetica Neue", Arial, sans-serif;
  --r: 14px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: var(--blue); }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
code { font-size: .9em; background: #eef2fa; padding: 1px 6px; border-radius: 6px; }
h1, h2, h3 { letter-spacing: -.01em; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 18px; border-radius: 999px; border: 0;
  font-weight: 700; font-size: 14px; text-decoration: none; white-space: nowrap;
  transition: transform .15s, box-shadow .15s, background .2s, opacity .2s;
}
.btn.primary { background: var(--blue); color: #fff; box-shadow: 0 3px 0 var(--blue-dark); }
.btn.primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 0 var(--blue-dark); }
.btn.primary:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--blue-dark); }
.btn.primary:disabled { opacity: .45; cursor: default; box-shadow: none; }
.btn.ghost { background: #fff; border: 1.5px solid var(--line); }
.btn.ghost:hover { border-color: var(--ink-3); }
.btn.danger { background: #fff; border: 1.5px solid #f3c4cf; color: var(--red); }
.btn.danger:hover { background: #fff3f6; }
.btn.big { height: 48px; padding: 0 26px; font-size: 16px; }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; border: 0; background: transparent; color: var(--ink-2); }
.icon-btn:hover { background: #eef2fa; color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }
.mini-btn { border: 0; background: #e6eeff; color: var(--blue-dark); font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 999px; }
.mini-btn:hover { background: #d6e3ff; }
.link-btn { border: 0; background: none; padding: 0; color: var(--blue); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- sign in ---------- */
.signin { min-height: 100%; display: grid; place-items: center; padding: 32px 16px; }
.signin-card { width: 100%; max-width: 560px; background: var(--card); border-radius: 24px; padding: 32px; box-shadow: 0 4px 0 #dfe5f1; }
.signin-card h1 { margin: 12px 0 8px; font-size: 34px; font-weight: 900; }
.signin-card .lead { color: var(--ink-2); margin: 0 0 20px; }
.back { font-size: 14px; font-weight: 600; text-decoration: none; }
.steps { padding-left: 22px; margin: 0 0 20px; }
.steps > li { margin-bottom: 14px; }
.steps ul { margin: 6px 0; padding-left: 18px; color: var(--ink-2); }
.steps ul li { margin: 3px 0; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0 16px; font-size: 14px; }
.advanced { margin-bottom: 18px; font-size: 14px; color: var(--ink-2); }
.advanced summary { cursor: pointer; }
.error { color: var(--red); font-weight: 600; margin: 12px 0 0; }
.fineprint { font-size: 13px; color: var(--ink-3); margin: 20px 0 0; }

.loading { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--ink-2); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid #dde5f5; border-top-color: var(--blue); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- app shell ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 60px; padding: 0 16px; background: #fff; border-bottom: 1px solid var(--line); }
.bar-left, .bar-right { display: flex; align-items: center; gap: 10px; }
.bar-title { font-weight: 900; font-size: 18px; }
.bar-link { font-weight: 600; font-size: 14px; text-decoration: none; padding: 6px 10px; border-radius: 999px; }
.bar-link:hover { background: #eef2fa; }
.status { font-size: 13px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.status.dirty { color: var(--amber); }
.status.ok { color: var(--green); }
.status.err { color: var(--red); }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 250px minmax(380px, 1fr) minmax(360px, 1.05fr); }

/* sidebar */
.side { overflow-y: auto; background: #fff; border-right: 1px solid var(--line); padding: 14px 10px; display: flex; flex-direction: column; gap: 4px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; border-radius: 12px; background: transparent; font-weight: 600; text-align: left; }
.nav-item svg { width: 20px; height: 20px; color: var(--ink-2); flex: none; }
.nav-item:hover { background: #f1f4fa; }
.nav-item.on { background: #e6eeff; color: var(--blue-dark); }
.nav-item.on svg { color: var(--blue); }
.nav-item.import { margin-top: 10px; border: 1.5px dashed #c9d5ee; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 12px 6px; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.char-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.char-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 12px; background: transparent; text-align: left; }
.char-item:hover { background: #f1f4fa; }
.char-item.on { background: #e6eeff; }
.char-thumb { position: relative; flex: none; width: 36px; height: 36px; border-radius: 10px; overflow: hidden; background: var(--c); display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 13px; }
.char-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: top; }
.char-meta { min-width: 0; display: flex; flex-direction: column; }
.char-meta b { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.char-meta small { color: var(--ink-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.char-item.is-hidden .char-thumb { opacity: .4; }
.char-item .dot { margin-left: auto; width: 8px; height: 8px; border-radius: 50%; background: var(--amber); flex: none; }
.empty-list { padding: 8px 12px; color: var(--ink-3); font-size: 14px; }

/* editor */
.editor { overflow-y: auto; padding: 24px clamp(16px, 2.4vw, 32px) 80px; }
.ed-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.ed-head h1 { margin: 0; font-size: 28px; font-weight: 900; line-height: 1.1; }
.ed-head p { margin: 4px 0 0; color: var(--ink-2); }
.ed-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.sec { background: var(--card); border-radius: 18px; padding: 20px; margin-bottom: 16px; box-shadow: 0 2px 0 #e3e8f3; }
.sec > h2 { margin: 0 0 4px; font-size: 17px; font-weight: 800; }
.sec > .hint { margin: 0 0 14px; color: var(--ink-2); font-size: 14px; }
.sec > h2 + .grid, .sec > h2 + .field { margin-top: 14px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid .full { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field > span small { font-weight: 400; color: var(--ink-3); }
.field input[type=text], .field input[type=number], .field input[type=password], .field input[type=url], .field select, .field textarea {
  width: 100%; height: 40px; padding: 0 12px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px #d6e3ff; }
.prefixed { display: flex; align-items: center; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; overflow: hidden; }
.prefixed:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px #d6e3ff; }
.prefixed b { padding: 0 2px 0 12px; font-weight: 500; color: var(--ink-3); white-space: nowrap; }
.prefixed input { border: 0 !important; box-shadow: none !important; padding-left: 0 !important; }

.toggle { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; user-select: none; }
.toggle input { appearance: none; width: 40px; height: 24px; border-radius: 999px; background: #d3dae8; position: relative; cursor: pointer; transition: background .2s; margin: 0; flex: none; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .2s; }
.toggle input:checked { background: var(--blue); }
.toggle input:checked::after { transform: translateX(16px); }

/* colour picking */
.color-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.color-input { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 6px 0 6px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; }
.color-input input[type=color] { width: 30px; height: 30px; padding: 0; border: 0; border-radius: 8px; background: none; cursor: pointer; }
.color-input input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
.color-input input[type=color]::-webkit-color-swatch { border: 0; border-radius: 8px; }
.color-input input[type=text] { width: 86px; height: 34px; border: 0; padding: 0 4px; font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
.color-input input[type=text]:focus { outline: none; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1.5px var(--line); background: var(--s); padding: 0; }
.swatch:hover { transform: scale(1.1); }
.swatch.on { box-shadow: 0 0 0 2px var(--ink); }

/* ability scores */
.stats-edit { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.stat-box { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px 8px; border-radius: 12px; background: #f3f6fc; }
.stat-box label { font-size: 12px; font-weight: 800; letter-spacing: .08em; color: var(--ink-2); }
.stat-box input { width: 100%; max-width: 64px; height: 38px; border: 1.5px solid var(--line); border-radius: 10px; text-align: center; font-size: 18px; font-weight: 800; background: #fff; }
.stat-box input:focus { outline: none; border-color: var(--blue); }
.stat-box small { font-size: 12px; font-weight: 700; color: var(--ink-3); }

/* extra rows */
.kv { display: flex; flex-direction: column; gap: 8px; }
.kv-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr) 36px; gap: 8px; }
.kv-row input { height: 38px; padding: 0 10px; border: 1.5px solid var(--line); border-radius: 10px; }
.kv-row input:focus { outline: none; border-color: var(--blue); }

/* image uploads */
.uploads { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.upload { position: relative; display: flex; flex-direction: column; gap: 8px; }
.upload-label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.drop {
  position: relative; display: grid; place-items: center; aspect-ratio: 1 / 1; border-radius: 16px; overflow: hidden;
  border: 2px dashed #c9d5ee; background: #f6f8fd; color: var(--ink-2); text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop.wide { aspect-ratio: 16 / 10; }
.drop:hover, .drop.drag { border-color: var(--blue); background: #eef3ff; }
.drop.filled { border-style: solid; border-color: transparent; background: var(--c, #f6f8fd); }
.drop input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop img.art { position: absolute; left: 0; right: 0; bottom: 0; margin: auto; height: 94%; width: auto; max-width: 96%; object-fit: contain; object-position: bottom; pointer-events: none; }
.drop img.cover { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.drop-text { padding: 12px; font-size: 14px; pointer-events: none; }
.drop-text b { display: block; color: var(--ink); font-size: 15px; }
.upload-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.note { font-size: 13px; padding: 8px 12px; border-radius: 10px; background: #fff6e5; color: #7a4a00; }
.note.ok { background: #e9f8f0; color: #0d6b45; }
.badge { display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; background: #fff1d6; color: var(--amber); }

/* range sliders */
.range { display: flex; align-items: center; gap: 12px; }
.range input[type=range] { flex: 1; accent-color: var(--blue); }
.range output { min-width: 56px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { height: 36px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--line); background: #fff; font-weight: 600; }
.chip.on { border-color: var(--blue); background: #e6eeff; color: var(--blue-dark); }
.font-sample { margin-top: 6px; font-size: 22px; font-weight: 800; color: var(--ink); line-height: 1.2; }

/* import */
.import-modes { display: grid; gap: 14px; }
.big-drop { aspect-ratio: auto; min-height: 150px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; height: 40px; padding: 0 12px; border: 1.5px solid var(--line); border-radius: 10px; min-width: 0; }
.inline-form input:focus { outline: none; border-color: var(--blue); }
.bookmarklet { display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 999px; background: var(--ink); color: #fff; font-weight: 700; text-decoration: none; cursor: grab; }
.howto { margin: 10px 0 0; padding-left: 20px; color: var(--ink-2); font-size: 14px; }
.howto li { margin: 4px 0; }
.review { width: 100%; border-collapse: collapse; font-size: 14px; }
.review td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.review td:first-child { width: 28px; }
.review td:nth-child(2) { width: 120px; font-weight: 600; color: var(--ink-2); }
.review td:last-child { white-space: pre-wrap; word-break: break-word; }
.review .changed { color: var(--blue-dark); font-weight: 600; }
.mode-banner { padding: 12px 14px; border-radius: 12px; background: #eef3ff; color: var(--blue-dark); font-size: 14px; margin-bottom: 14px; }

/* preview */
.preview { display: flex; flex-direction: column; min-width: 0; background: #e9eef7; border-left: 1px solid var(--line); }
.preview-bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; height: 48px; padding: 0 12px; font-size: 13px; font-weight: 700; color: var(--ink-2); }
.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: #fff; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.seg button.on { background: var(--ink); color: #fff; }
.preview-frame { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.preview-frame iframe { position: absolute; top: 0; left: 0; border: 0; background: #fff; transform-origin: 0 0; }
.preview-frame.phone iframe { left: 50%; border-radius: 28px; box-shadow: 0 0 0 10px #141a2b, 0 20px 40px rgba(0,0,0,.2); top: 22px; }

/* toast */
.toast { position: fixed; z-index: 100; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; max-width: min(92vw, 520px); padding: 12px 18px; border-radius: 14px; background: var(--ink); color: #fff; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.25); transition: opacity .2s, transform .3s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }

/* ---------- narrower screens ---------- */
.only-narrow { display: none !important; }
@media (max-width: 1180px) {
  .layout { grid-template-columns: 230px minmax(0, 1fr); }
  .only-narrow { display: inline-flex !important; }
  .preview { position: fixed; z-index: 40; inset: 60px 0 0 0; transform: translateX(100%); transition: transform .3s; }
  .preview.open { transform: none; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .side { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; gap: 6px; align-items: center; }
  .side-head { padding: 0; flex: none; }
  .side-head span { display: none; }
  .char-list { flex-direction: row; gap: 6px; }
  .nav-item, .char-item { width: auto; white-space: nowrap; flex: none; }
  .nav-item.import { margin-top: 0; }
  .char-meta small { display: none; }
  #btn-new { flex: none; }
  .bar-link { display: none; }
  .grid, .uploads { grid-template-columns: 1fr; }
  .stats-edit { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .status { display: none; }
}
