:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --ink: #26221c;
  --muted: #7a7264;
  --brand: #e8833a;
  --brand-dark: #c96a24;
  --line: #e5ded2;
  --danger: #c0392b;
  --ok: #2e7d32;
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
h2 { margin: 4px 0 16px; }
h3 { margin: 8px 0 10px; }
button {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  font: inherit;
}
button:hover { border-color: var(--brand); }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: var(--brand-dark); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.small { padding: 4px 10px; font-size: 13px; }
input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
  min-width: 0;
}
textarea.code {
  width: 100%;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
}
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); min-height: 18px; }
.hidden { display: none !important; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  padding: 32px; width: min(420px, 100%); display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 12px 32px rgba(60, 40, 10, .08);
}
.login-card .logo { font-size: 28px; font-weight: 700; }
.login-card h1 { margin: 0; font-size: 22px; }

/* Layout */
.layout { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar {
  background: #2e2a24; color: #f3ede2; padding: 20px 14px;
  display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh;
}
.sidebar .logo { font-size: 19px; font-weight: 700; padding: 0 8px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-btn {
  text-align: left; background: transparent; border: none; color: #d9d0bf;
  padding: 10px 12px; border-radius: 10px;
}
.nav-btn:hover { background: #3b362e; color: #fff; }
.nav-btn.active { background: var(--brand); color: #fff; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 8px; }
.sidebar-foot .ghost { background: transparent; color: #d9d0bf; border-color: #554c3e; }
.content { padding: 24px 28px 60px; max-width: 1240px; width: 100%; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

/* Components */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px;
}
.card .num { font-size: 28px; font-weight: 700; }
.card .lbl { color: var(--muted); font-size: 13px; margin-top: 4px; }
/* Analytics bar charts (pure CSS, values shown on hover via title). */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 150px; padding-top: 8px; }
.bar-col { flex: 1 1 0; display: flex; align-items: flex-end; justify-content: center; gap: 2px; height: 100%; min-width: 0; }
.bar { flex: 1 1 0; min-height: 2px; border-radius: 3px 3px 0 0; background: var(--brand); }
.bar.alt { background: var(--ok); }
.bar.neg { background: var(--danger); }
.bar-labels { display: flex; gap: 3px; margin-top: 6px; }
.bar-labels span { flex: 1 1 0; text-align: center; font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; background: var(--brand); }
.legend i.alt { background: var(--ok); }
.legend i.neg { background: var(--danger); }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-top: 18px;
}
.notes li { margin: 6px 0; line-height: 1.5; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type="search"], .toolbar input:not([type]) { min-width: 240px; }
.pager { display: flex; gap: 12px; align-items: center; margin: 12px 0; }
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: top; }
th { background: #faf7f1; font-size: 13px; color: var(--muted); }
tr:last-child td { border-bottom: none; }
.entity-cell { display: flex; align-items: center; gap: 10px; }
.entity-cell .thumb { width: 48px; height: 48px; object-fit: contain; flex: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #fdf6ee; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; background: #f1e9dc; }
.badge.db { background: #e3f1e3; color: var(--ok); }
.badge.seed { background: #fdf0dc; color: #9a6206; }
.badge.deleted, .badge.DELETED { background: #fbe3e0; color: var(--danger); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.row-end { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
pre.json {
  background: #2e2a24; color: #efe8da; border-radius: 10px; padding: 12px;
  overflow: auto; max-height: 380px; font-size: 12px; line-height: 1.5;
}
.toast {
  position: fixed; top: 18px; right: 18px; z-index: 60; background: #2e2a24; color: #fff;
  padding: 12px 16px; border-radius: 12px; box-shadow: 0 10px 24px rgba(0,0,0,.2); max-width: 440px;
}
.toast.err { background: var(--danger); }
.modal {
  position: fixed; inset: 0; background: rgba(30, 24, 16, .5);
  display: grid; place-items: center; z-index: 50; padding: 16px;
}
.modal-card {
  background: var(--panel); border-radius: 18px; padding: 22px; width: min(680px, 100%);
  max-height: 90vh; overflow: auto;
}
.inline-input { width: 84px; }
.inline-input.wide-num { width: 110px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
#huntEditor .actions, #energyEditor .actions { margin-top: 10px; }
.actions label { flex-direction: row; align-items: center; gap: 6px; }
.actions button { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.actions .inline-input { padding: 6px 8px; }
#userDetail table button { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .content { padding: 16px 14px 48px; }
  h2 { font-size: 20px; }
  .sidebar { position: static; height: auto; padding: 12px; }
  .sidebar nav { flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 4px; }
  .nav-btn { white-space: nowrap; flex: none; }
  .sidebar-foot { margin-top: 0; flex-direction: row; align-items: center; justify-content: space-between; }
  .form-grid { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .kv { grid-template-columns: 1fr; }
  .toolbar input[type=search], .toolbar input:not([type]) { min-width: 0; flex: 1 1 200px; }
  th, td { padding: 7px 8px; font-size: 13px; }
  .detail-tabs { gap: 2px; }
  .dtab { padding: 8px 12px; }
  .row-end { flex-wrap: wrap; justify-content: flex-start; }
  .snap-thumb, .snap-icon { width: 48px; height: 48px; }
  .snap-icon img { width: 40px; height: 40px; }
  .entity-cell .thumb { width: 40px; height: 40px; }
  .login-card { padding: 24px 20px; }
  .modal-card { padding: 18px 16px; }
  .toast { left: 12px; right: 12px; max-width: none; }
  .panel { padding: 14px; }
}

/* Wide tables scroll sideways instead of breaking the phone layout. */
.panel, #userList, #vocabList, #auditList, #feedbackList, #backupList, #petList, #monsterList, #deckDetail, #userDetail { overflow-x: auto; }

/* ---- snapshot editors (pet / gear / chest) ---- */
.snap-card {
  display: flex; gap: 12px; align-items: flex-start;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); padding: 10px 12px; margin: 8px 0;
}
.snap-thumb { width: 56px; height: 56px; object-fit: contain; flex: none; }
.snap-icon {
  width: 56px; height: 56px; flex: none; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 28px;
}
.snap-icon img { width: 48px; height: 48px; object-fit: contain; }
.snap-body { flex: 1 1 auto; min-width: 0; }
.snap-title { font-weight: 600; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.snap-fields {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-top: 8px;
}
.snap-fields label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; }
.snap-fields label.chk { flex-direction: row; align-items: center; color: var(--ink); font-size: 13px; }
.chip {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; color: #fff; background: var(--muted);
}
.chip-active { background: var(--brand); }
.chip-awake { background: #8e44ad; }
.chip-lock { background: #555; }
.chip-equip { background: var(--ok); }
.chest-row { display: flex; gap: 12px; flex-wrap: wrap; }
.chest-row .snap-card { flex: 1 1 220px; }

/* gear: live stat preview + editable specials */
.gear-preview { margin-top: 6px; }
.gear-specials { margin-top: 8px; }
.special-rows { display: flex; flex-direction: column; gap: 6px; margin: 6px 0; }
.special-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.special-row .special-stat { max-width: 180px; padding: 4px 8px; }
.special-row .special-val { width: 90px; }

/* space the save button away from the specials "+ add" button */
.snap-body .actions { margin-top: 12px; }

/* activity feeds (user detail) */
.feed { display: flex; flex-direction: column; margin: 4px 0; }
.act-row { display: flex; gap: 10px; align-items: flex-start; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.act-row:last-child { border-bottom: none; }
.act-ico { font-size: 16px; flex: none; width: 22px; text-align: center; line-height: 1.4; }
.feed .ghost.small { margin-top: 8px; align-self: flex-start; }

/* activity feed filters */
.feed-filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 6px; }
.chip-btn {
  padding: 3px 10px; font-size: 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer;
}
.chip-btn:hover { border-color: var(--brand); }
.chip-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* user detail tabs */
.detail-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 10px 0 14px; border-bottom: 1px solid var(--line); }
.dtab {
  padding: 8px 16px; border: none; background: none; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.dtab:hover { color: var(--ink); }
.dtab.active { color: var(--brand); border-bottom-color: var(--brand); }
.dtab-panel { display: none; }
.dtab-panel.active { display: block; }
.danger-zone { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); }

/* stats heatmap */
.stats-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.stats-head label { display: flex; align-items: center; gap: 6px; font-size: 13px; }
#statsTotals { margin-bottom: 10px; }
.stats-body { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-start; }
.hm-head, .hm-cells { display: grid; grid-template-columns: repeat(7, 22px); gap: 4px; }
.hm-head span { text-align: center; font-size: 10px; color: var(--muted); margin-bottom: 2px; }
.hm-cell { width: 22px; height: 22px; border-radius: 5px; background: var(--line); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.hm-cell.empty { background: transparent; cursor: default; }
.hm-cell.sel { outline: 2px solid var(--brand); outline-offset: 1px; }
.hm-day { font-size: 9px; color: var(--muted); }
.hm-cell.lv0 { background: #ece7dd; }
.hm-cell.lv1 { background: #cdeccd; }
.hm-cell.lv2 { background: #8fd18f; }
.hm-cell.lv3 { background: #4caf50; }
.hm-cell.lv4 { background: #2e7d32; }
.hm-cell.lv3 .hm-day, .hm-cell.lv4 .hm-day { color: #fff; }
.hm-legend { display: flex; align-items: center; gap: 4px; margin-top: 10px; font-size: 11px; color: var(--muted); }
.hm-legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.hm-legend i.lv0 { background: #ece7dd; } .hm-legend i.lv1 { background: #cdeccd; }
.hm-legend i.lv2 { background: #8fd18f; } .hm-legend i.lv3 { background: #4caf50; }
.hm-legend i.lv4 { background: #2e7d32; }

/* stats: per-day detail card (shown on cell click) */
.stats-detail { min-width: 180px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stats-detail b { display: block; margin-bottom: 8px; font-size: 15px; color: var(--brand); }
.stats-detail div { margin: 3px 0; font-size: 14px; }

/* feedback message: keep user line breaks */
.fb-msg { white-space: pre-wrap; word-break: break-word; }

/* ---- mechanics tab ---- */
.mech-card h3 { display: flex; align-items: center; gap: 10px; }
.mech-ico { font-size: 24px; }
.mech-summary { font-size: 15px; margin: 0 0 10px; }
.mech-formula {
  font-family: ui-monospace, Consolas, monospace; font-size: 13px; line-height: 1.5;
  background: #faf7f1; border-left: 3px solid var(--brand);
  padding: 10px 12px; border-radius: 0 10px 10px 0; margin: 10px 0; overflow-x: auto;
}
.hl { background: #fdf0dc; padding: 1px 7px; border-radius: 6px; font-weight: 700; white-space: nowrap; }
.rdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.r-common { background: #9aa0b4; } .r-uncommon { background: #22c55e; }
.r-rare { background: #4d96ff; } .r-epic { background: #9b5de5; }
.r-legendary { background: #ff9f1c; }
.mech-hl-row td { background: #fdf6ee; font-weight: 600; }
.mech-card table { margin: 10px 0; }
#mechCats { margin-bottom: 14px; }

/* ---- balance field docs ---- */
.bdoc-group { margin: 14px 0; }
.bdoc-group h4 { margin: 14px 0 6px; font-size: 15px; }
.bdoc-intro { margin: 4px 0 10px; }
.bdoc-path { word-break: break-all; }
.bdoc-val { font-family: ui-monospace, Consolas, monospace; font-size: 13px; color: var(--muted); white-space: nowrap; }
.bdoc-missing { font-style: italic; }
#balanceDocs table { margin: 6px 0 10px; }

/* Feedback mail settings (Feedback tab) */
.fb-mail {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.fb-mail h3 { margin: 0 0 4px; }
.fb-mail-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line);
}
.fb-mail-row:last-child { border-bottom: none; }
.fb-mail-addr { flex: 1; font-weight: 600; word-break: break-all; }
.fb-mail-add { display: flex; gap: 8px; margin: 10px 0; }
.fb-mail-add input { flex: 1; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer;
  background: #cfc8ba; border-radius: 999px; transition: 0.2s;
}
.switch .slider::before {
  content: ""; position: absolute; width: 18px; height: 18px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::before { transform: translateX(20px); }
