/* ==========================================================================
   Chimera Craft — design system
   Warm storybook parchment, deep evergreen, gold accents. Light + dark.
   ========================================================================== */
:root {
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;

  --bg: #f6efe2;
  --bg-2: #efe4cf;
  --paper: #fffaf1;
  --paper-2: #f8f1e3;
  --ink: #2b2620;
  --ink-2: #5a5148;
  --ink-3: #8a7f73;
  --line: #e3d6bf;
  --line-2: #cdbc9d;

  --green: #2f6b5e;
  --green-2: #3d8a78;
  --green-soft: #d9ebe3;
  --gold: #c9962b;
  --gold-2: #e8b84a;
  --gold-soft: #f7e9c4;
  --rose: #b5484d;
  --rose-soft: #f6dcdc;
  --blue: #3f6f9e;
  --blue-soft: #dbe7f3;
  --violet: #6b4c9a;
  --violet-soft: #e6dcf3;

  --female: #c85a8f;
  --male: #3e7bbf;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 6px 24px rgba(60, 40, 10, .10), 0 1px 3px rgba(60, 40, 10, .08);
  --shadow-sm: 0 2px 8px rgba(60, 40, 10, .10);
  --focus: 0 0 0 3px rgba(61, 138, 120, .35);
  --topbar-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1a17; --bg-2: #24211d; --paper: #2a2622; --paper-2: #322d28;
    --ink: #f1e9dc; --ink-2: #c9bfb0; --ink-3: #958b7d; --line: #3d3730; --line-2: #55493c;
    --green-soft: #21382f; --gold-soft: #3f3418; --rose-soft: #42262a; --blue-soft: #1f2d3b; --violet-soft: #2c2338;
    --shadow: 0 6px 24px rgba(0,0,0,.4), 0 1px 3px rgba(0,0,0,.3); --shadow-sm: 0 2px 8px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --bg: #1c1a17; --bg-2: #24211d; --paper: #2a2622; --paper-2: #322d28;
  --ink: #f1e9dc; --ink-2: #c9bfb0; --ink-3: #958b7d; --line: #3d3730; --line-2: #55493c;
  --green-soft: #21382f; --gold-soft: #3f3418; --rose-soft: #42262a; --blue-soft: #1f2d3b; --violet-soft: #2c2338;
  --shadow: 0 6px 24px rgba(0,0,0,.4), 0 1px 3px rgba(0,0,0,.3); --shadow-sm: 0 2px 8px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font-body); color: var(--ink); background: var(--bg);
  background-image: radial-gradient(1200px 600px at 10% -10%, rgba(232,184,74,.10), transparent 60%),
                    radial-gradient(900px 500px at 100% 0%, rgba(47,107,94,.10), transparent 60%);
  line-height: 1.5; min-height: 100vh;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; margin: 0 0 .4em; line-height: 1.15; letter-spacing: .01em; }
h1 { font-size: 2.1rem; } h2 { font-size: 1.6rem; } h3 { font-size: 1.25rem; } h4 { font-size: 1.05rem; font-family: var(--font-body); font-weight: 800; }
p { margin: 0 0 .8em; }
a { color: var(--green-2); text-decoration: none; } a:hover { text-decoration: underline; }
small, .muted { color: var(--ink-3); }
.muted { font-size: .92em; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--paper-2); padding: .1em .35em; border-radius: 4px; font-size: .9em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
img, svg { max-width: 100%; }
[hidden] { display: none !important; }

/* ---- Layout ------------------------------------------------------------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.view { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: 20px 16px 60px; }
.view.wide { max-width: 1600px; }
.footer { text-align: center; color: var(--ink-3); font-size: .85rem; padding: 16px; border-top: 1px solid var(--line); }

.topbar {
  position: sticky; top: 0; z-index: 50; height: var(--topbar-h);
  background: color-mix(in srgb, var(--paper) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; padding: 0 16px;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; font-size: 1.35rem; color: var(--ink); margin-right: 8px; white-space: nowrap; }
.topbar .brand img { width: 30px; height: 30px; }
.topbar nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.topbar nav::-webkit-scrollbar { display: none; }
.topbar nav a { padding: 8px 11px; border-radius: 999px; color: var(--ink-2); font-weight: 700; font-size: .92rem; white-space: nowrap; position: relative; }
.topbar nav a:hover { background: var(--bg-2); text-decoration: none; color: var(--ink); }
.topbar nav a.active { background: var(--green); color: #fff; }
.topbar nav a .badge { position: absolute; top: 2px; right: 2px; }
.topbar .right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.wallet { display: inline-flex; align-items: center; gap: 6px; background: var(--gold-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent); padding: 5px 12px; border-radius: 999px; font-weight: 800; white-space: nowrap; }
.wallet .glim { color: var(--gold); }
.iconbtn { position: relative; background: transparent; border: 1px solid transparent; border-radius: 999px; width: 38px; height: 38px; display: inline-grid; place-items: center; cursor: pointer; font-size: 1.15rem; color: var(--ink-2); }
.iconbtn:hover { background: var(--bg-2); }
.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--rose); color: #fff; font-size: .7rem; font-weight: 800; line-height: 1; }
.badge.gold { background: var(--gold); }
.badge.green { background: var(--green-2); }
.menu { position: absolute; right: 0; top: 44px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow); min-width: 200px; padding: 6px; z-index: 60; }
.menu a, .menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px; color: var(--ink); background: none; border: 0; font: inherit; cursor: pointer; }
.menu a:hover, .menu button:hover { background: var(--bg-2); text-decoration: none; }
.userbtn { display: inline-flex; align-items: center; gap: 8px; padding: 5px 10px 5px 6px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); cursor: pointer; font: inherit; color: var(--ink); font-weight: 700; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--green); color: #fff; display: inline-grid; place-items: center; font-weight: 800; font-size: .85rem; }

/* ---- Cards & panels ------------------------------------------------------ */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 18px; }
.card.pad-lg { padding: 26px; }
.card.flat { box-shadow: none; }
.card + .card { margin-top: 16px; }
.card-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-title h2, .card-title h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--ink-3); margin: 0; }
.section { margin-top: 24px; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr); gap: 20px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
.sidebar-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; }
@media (max-width: 900px) { .sidebar-layout { grid-template-columns: 1fr; } }

/* ---- Buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--paper); color: var(--ink); font: inherit; font-weight: 800; cursor: pointer;
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease; white-space: nowrap; line-height: 1.2;
}
.btn:hover { background: var(--bg-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-2); }
.btn.gold { background: var(--gold-2); border-color: var(--gold); color: #2b2620; }
.btn.gold:hover { background: var(--gold); }
.btn.danger { background: var(--rose-soft); border-color: var(--rose); color: var(--rose); }
.btn.danger:hover { background: var(--rose); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--bg-2); }
.btn.sm { padding: 5px 11px; font-size: .85rem; }
.btn.lg { padding: 12px 22px; font-size: 1.05rem; }
.btn.block { width: 100%; }
.btn .ico { font-size: 1.1em; }
.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* ---- Forms --------------------------------------------------------------- */
label { font-weight: 700; font-size: .9rem; color: var(--ink-2); display: block; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field .hint { font-size: .8rem; color: var(--ink-3); margin-top: 3px; }
input[type="text"], input[type="password"], input[type="email"], input[type="number"], input[type="search"], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--paper); color: var(--ink);
  font: inherit; transition: box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus { outline: none; box-shadow: var(--focus); border-color: var(--green-2); }
textarea { min-height: 90px; resize: vertical; }
input[type="range"] { width: 100%; accent-color: var(--green-2); }
input[type="color"] { width: 44px; height: 32px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--paper); padding: 2px; }
.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--green-2); }
.form-error { color: var(--rose); font-weight: 700; margin: 8px 0; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select { width: auto; flex: 1; min-width: 120px; }

/* ---- Chips, tags, pills ------------------------------------------------ */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; background: var(--bg-2); color: var(--ink-2); font-size: .8rem; font-weight: 700; border: 1px solid var(--line); }
.chip.green { background: var(--green-soft); color: var(--green); border-color: transparent; }
.chip.gold { background: var(--gold-soft); color: #8a6414; border-color: transparent; }
.chip.rose { background: var(--rose-soft); color: var(--rose); border-color: transparent; }
.chip.blue { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.chip.violet { background: var(--violet-soft); color: var(--violet); border-color: transparent; }
.chip.female { background: #f9dfe9; color: var(--female); border-color: transparent; }
.chip.male { background: #dbe8f6; color: var(--male); border-color: transparent; }
.chip.clickable { cursor: pointer; } .chip.clickable:hover { filter: brightness(.96); }
.chip.active { background: var(--green); color: #fff; }
.sex-badge { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; color: #fff; font-weight: 800; font-size: .8rem; }
.sex-badge.F { background: var(--female); } .sex-badge.M { background: var(--male); }

/* ---- Tabs ---------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 14px; font: inherit; font-weight: 800; color: var(--ink-3); cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--green); border-bottom-color: var(--green); }
.tabs button:hover { color: var(--ink); }

/* ---- Tables -------------------------------------------------------------- */
table.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--ink-3); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.table tr:hover td { background: var(--paper-2); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Portrait wall ------------------------------------------------------ */
.wall { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.portrait-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; position: relative; display: flex; flex-direction: column; }
.portrait-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.portrait-card .pic { aspect-ratio: 4 / 3; background: linear-gradient(180deg, var(--paper-2), var(--bg-2)); display: grid; place-items: center; overflow: hidden; }
.portrait-card .pic svg, .portrait-card .pic img { width: 100%; height: 100%; object-fit: contain; }
.portrait-card .info { padding: 8px 10px 10px; }
.portrait-card .name { font-weight: 800; display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.portrait-card .meta { font-size: .78rem; color: var(--ink-3); }
.portrait-card .alerts { position: absolute; top: 8px; left: 8px; display: flex; gap: 4px; }
.portrait-card .alerts span { background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 2px 7px; font-size: .8rem; box-shadow: var(--shadow-sm); }
.portrait-card.selected { outline: 3px solid var(--green-2); }

/* ---- Creature figure -------------------------------------------------- */
.creature-figure { width: 100%; display: grid; place-items: center; }
.creature-figure svg { width: 100%; height: auto; }
.creature-stage { background: radial-gradient(ellipse at 50% 85%, rgba(0,0,0,.10), transparent 60%), linear-gradient(180deg, var(--paper-2), var(--bg-2)); border-radius: var(--radius); border: 1px solid var(--line); }

/* ---- Item icons / inventory -------------------------------------------- */
.item-icon { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--paper-2); border: 1px solid var(--line); font-size: 1.35rem; }
.item-icon img { width: 34px; height: 34px; object-fit: contain; }
.item-icon.sm { width: 28px; height: 28px; font-size: 1rem; border-radius: 7px; }
.item-icon.lg { width: 60px; height: 60px; font-size: 2rem; border-radius: 14px; }
.item-row { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.item-row:last-child { border-bottom: 0; }
.item-row .grow { flex: 1; min-width: 0; }
.item-row .name { font-weight: 700; }
.item-row .qty { font-weight: 800; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.item-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.item-card .top { display: flex; gap: 8px; align-items: center; }
.item-card .name { font-weight: 800; font-size: .9rem; line-height: 1.2; }
.item-card .desc { font-size: .78rem; color: var(--ink-3); flex: 1; }
.price { font-weight: 800; color: var(--gold); white-space: nowrap; }
.price::before { content: '✦ '; }

/* ---- Modals ------------------------------------------------------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 15, 10, .55); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fadeIn .15s ease; }
.modal { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); width: min(640px, 100%); max-height: 92vh; overflow: auto; padding: 22px; animation: popIn .18s ease; }
.modal.lg { width: min(960px, 100%); }
.modal.sm { width: min(420px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h2, .modal-head h3 { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes popIn { from { transform: translateY(8px) scale(.98); opacity: 0 } to { transform: none; opacity: 1 } }

/* ---- Toasts -------------------------------------------------------------- */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; pointer-events: none; width: min(420px, calc(100% - 32px)); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 700; animation: popIn .18s ease; pointer-events: auto; display: flex; gap: 8px; align-items: center; }
.toast.success { background: var(--green); color: #fff; }
.toast.error { background: var(--rose); color: #fff; }
.toast.gold { background: var(--gold); color: #2b2620; }

/* ---- Misc components ---------------------------------------------------- */
.loading-screen { display: grid; place-items: center; min-height: 60vh; color: var(--ink-3); text-align: center; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--line); border-top-color: var(--green-2); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--ink-3); padding: 40px 16px; }
.empty .big { font-size: 2.6rem; margin-bottom: 8px; }
.progress { height: 10px; border-radius: 999px; background: var(--bg-2); overflow: hidden; border: 1px solid var(--line); }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--green-2), var(--gold-2)); border-radius: 999px; transition: width .3s ease; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .k { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 800; }
.stat .v { font-weight: 800; font-size: 1.05rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: .93rem; }
.kv dt { color: var(--ink-3); font-weight: 700; } .kv dd { margin: 0; }
.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line-2); }
.timeline li { padding: 4px 0 10px 14px; position: relative; font-size: .92rem; }
.timeline li::before { content: ''; position: absolute; left: -7px; top: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--gold-2); border: 2px solid var(--paper); }
.timeline .when { color: var(--ink-3); font-size: .78rem; display: block; }
.notice { padding: 10px 14px; border-radius: var(--radius-sm); background: var(--gold-soft); border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent); font-size: .92rem; }
.notice.green { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 35%, transparent); }
.notice.rose { background: var(--rose-soft); border-color: color-mix(in srgb, var(--rose) 35%, transparent); }
.notice.blue { background: var(--blue-soft); border-color: color-mix(in srgb, var(--blue) 35%, transparent); }
.swatch { display: inline-block; width: 22px; height: 22px; border-radius: 6px; border: 1px solid rgba(0,0,0,.2); vertical-align: middle; }
.trait-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px 14px; font-size: .9rem; }
.trait-list .t { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.trait-list .t .k { color: var(--ink-3); }
.trait-list .t .v { font-weight: 700; text-align: right; }
.trait-list .t .v small { color: var(--ink-3); font-weight: 600; }
.dev-panel { position: fixed; right: 12px; bottom: 12px; z-index: 90; }
.dev-panel .card { padding: 10px 12px; font-size: .85rem; }
kbd { font: inherit; font-size: .8em; padding: 1px 5px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; background: var(--paper-2); }

/* ---- Auth screen ---------------------------------------------------------- */
.auth-wrap { min-height: calc(100vh - 40px); display: grid; place-items: center; }
.auth-card { width: min(440px, 100%); }
.auth-hero { text-align: center; margin-bottom: 18px; }
.auth-hero h1 { font-size: 2.6rem; margin: 0; }
.auth-hero p { color: var(--ink-3); }

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 700px) {
  .view { padding: 14px 12px 70px; }
  .topbar { padding: 0 10px; }
  .topbar .brand span { display: none; }
  .wallet { padding: 4px 9px; font-size: .9rem; }
  .card { padding: 14px; }
  h1 { font-size: 1.7rem; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001s !important; transition-duration: .001s !important; } }
