:root {
  --bg: #f4f6fb; --panel: #ffffff; --text: #1d2433; --muted: #6b7489; --line: #e3e7ef;
  --accent: #4f6bed; --accent-2: #eef1ff; --ok: #1f9d55; --ok-bg: #e7f7ee; --warn: #b7791f; --warn-bg: #fdf4e3;
  --danger: #d64545; --danger-bg: #fdecec; --side: #18203a; --side-text: #c9d1ea; --gold: #c99a1a; --coin: #2f8f6b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151f; --panel: #1a2030; --text: #e6e9f2; --muted: #98a1b8; --line: #2a3246;
    --accent: #7d93ff; --accent-2: #232c48; --ok-bg: #16301f; --warn-bg: #33290f; --danger-bg: #3a1a1a;
    --side: #0c1018; --side-text: #b7c0db;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.mono { font-family: Consolas, monospace; font-size: 12.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* layout */
.admin { display: flex; min-height: 100vh; }
.side { width: 220px; background: var(--side); color: var(--side-text); padding: 18px 0; flex-shrink: 0; }
.side .brand { font-weight: 700; font-size: 17px; padding: 0 20px 18px; color: #fff; display: flex; align-items: center; gap: 10px; }
.side .brand img { width: 44px; height: 44px; border-radius: 10px; flex: none; }
.side .brand small { display: block; font-size: 11px; font-weight: 500; opacity: .75; }
.side a { display: block; padding: 9px 20px; color: var(--side-text); }
.side a:hover, .side a.on { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.side .badge { float: right; }
.side form { padding: 14px 20px; }
.main { flex: 1; padding: 24px 28px; min-width: 0; }
.public { max-width: 720px; margin: 0 auto; padding: 32px 16px; }

/* components */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.grid { display: grid; gap: 14px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.stat .v { font-size: 22px; font-weight: 700; }
.stat .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
tr:hover td { background: var(--accent-2); }
.scroll { overflow-x: auto; }
.badge { display: inline-block; white-space: nowrap; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--accent-2); color: var(--accent); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.coin { color: var(--coin); font-weight: 600; }
.gold { color: var(--gold); font-weight: 600; }
.pos { color: var(--ok); font-weight: 600; }
.neg { color: var(--danger); font-weight: 600; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.error { background: var(--danger-bg); color: var(--danger); }
.alert-row.danger td:first-child { border-left: 3px solid var(--danger); }
.alert-row.warn td:first-child { border-left: 3px solid var(--warn); }

/* forms */
input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--panel); color: var(--text); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button, .btn { font: inherit; padding: 7px 14px; border-radius: 7px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; cursor: pointer; display: inline-block; }
button.ghost, .btn.ghost { background: transparent; color: var(--accent); }
button.danger { background: var(--danger); border-color: var(--danger); }
button.small { padding: 3px 9px; font-size: 12px; }
.form-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input { width: 100%; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar input[type=text], .toolbar input[type=search] { min-width: 240px; }
.pager { margin-top: 12px; display: flex; gap: 8px; align-items: center; }

/* items */
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.item { border: 1px solid var(--line); border-radius: 9px; padding: 10px; text-align: center; background: var(--panel); }
.item img { width: 48px; height: 48px; object-fit: contain; image-rendering: pixelated; }
.item .n { font-weight: 600; font-size: 13px; margin-top: 4px; }
.item .s { font-size: 12px; color: var(--muted); }
.icon-sm { width: 28px; height: 28px; object-fit: contain; image-rendering: pixelated; vertical-align: middle; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; border-radius: 7px 7px 0 0; color: var(--muted); }
.tabs a.on { background: var(--panel); border: 1px solid var(--line); border-bottom-color: var(--panel); color: var(--text);
  margin-bottom: -1px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; }
.kv div:nth-child(odd) { color: var(--muted); }

/* public */
.hero { text-align: center; padding: 28px 0 10px; }
.hero h1 { font-size: 30px; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
@media (max-width: 760px) {
  .admin { flex-direction: column; }
  .side { width: 100%; padding: 8px 0; }
  .side a { display: inline-block; padding: 6px 12px; }
  .main { padding: 16px; }
  .kv { grid-template-columns: 1fr; }
}

/* item detail + price editing */
td.r, th.r { text-align: right; }
.item-head { display: flex; gap: 18px; align-items: center; margin-bottom: 18px; }
.item-head img { width: 84px; height: 84px; object-fit: contain; image-rendering: pixelated;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.item a.open { color: inherit; text-decoration: none; display: block; }
.item { transition: border-color .15s, transform .15s; }
.item:hover { border-color: var(--accent); transform: translateY(-1px); }
details.bulk { margin-bottom: 14px; }
details.bulk summary { cursor: pointer; color: var(--accent); font-weight: 600; }
details.bulk[open] summary { margin-bottom: 12px; }

/* menu groups */
.side .nav-group { padding: 14px 20px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--side-text); opacity: .55; }

/* map editor */
.map-editor { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; align-items: start; }
.map-tools { gap: 6px; margin-bottom: 10px; }
.map-tools .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.map-tools button.on { background: var(--accent); color: #fff; }
.map-scroll {
  overflow: auto;
  max-height: 75vh;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #5dbeef 0%, #90d3fc 50%, #cbeaff 100%);
  display: flex;
  padding: 20px;
}
.map-scroll.night {
  background: linear-gradient(180deg, #0d1e3d 0%, #152d59 50%, #1f3d73 100%);
}
.map-scroll canvas {
  display: block;
  margin: auto;
  cursor: crosshair;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  border-radius: 8px;
}
.map-side { max-height: calc(70vh + 90px); overflow: auto; }
.buildings { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-top: 4px; }
.bld { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px; min-height: 52px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; color: inherit; cursor: pointer; }
.bld img { max-width: 52px; max-height: 40px; image-rendering: pixelated; }
.bld .nb { font: 600 12px monospace; padding-top: 10px; }
.bld small { font-size: 10px; color: var(--muted); text-align: center; line-height: 1.2; }
.bld.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
@media (max-width: 900px) { .map-editor { grid-template-columns: 1fr; } }
.btn.small { padding: 3px 9px; font-size: 12px; }

.map-side { overflow-x: hidden; }
.map-status { font-size: 13px; margin-top: 8px; padding: 6px 10px; background: var(--bg); border-radius: 6px; min-height: 18px; }
.brush-box { display: flex; gap: 10px; align-items: center; }
.brush-box canvas { border: 1px solid var(--line); border-radius: 6px; background: var(--bg); image-rendering: pixelated; }
.map-help summary { cursor: pointer; }
.map-help .steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin-top: 12px; }
.map-help .step { display: flex; gap: 10px; font-size: 13px; line-height: 1.5; }
.map-help .num { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; }

.bld .pic-link { font-size: 10px; margin-top: 2px; }
.pic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.pic { border: 1px solid var(--line); border-radius: 9px; padding: 10px; background: var(--panel); text-align: center;
  color: inherit; display: block; }
.pic:hover { border-color: var(--accent); text-decoration: none; }
.pic img, .pic-big img { image-rendering: pixelated; max-width: 100%; }
.pic .thumb { height: 110px; display: flex; align-items: flex-end; justify-content: center;
  background: repeating-conic-gradient(#e8e8ee 0 25%, #fff 0 50%) 0 0 / 16px 16px; border-radius: 6px; }
.pic .thumb img { max-height: 106px; }
.pic-big { display: inline-flex; align-items: flex-end; justify-content: center; padding: 8px; border-radius: 8px;
  background: repeating-conic-gradient(#e8e8ee 0 25%, #fff 0 50%) 0 0 / 16px 16px; }

/* picture upload */
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 22px 12px; text-align: center;
  border: 2px dashed var(--line); border-radius: 10px; cursor: pointer; background: var(--bg); transition: .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: rgba(80, 110, 240, .08); }
.dropzone input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone .dz-icon { font-size: 26px; color: var(--accent); }
.dropzone .dz-file { font-size: 13px; color: var(--accent); font-weight: 600; }
.pic.over { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(80, 110, 240, .3); }
.pic.busy { opacity: .5; pointer-events: none; }
.dropzone { position: relative; }

.adjust { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 8px 0; }
.adjust label { display: grid; grid-template-columns: 90px 1fr 46px; align-items: center; gap: 8px; font-size: 13px; }
.adjust input[type=range] { width: 100%; }
.pic-big canvas { image-rendering: pixelated; }

/* Pet animation */
.pet-c { image-rendering: pixelated; }
#stage { image-rendering: pixelated; display: block; }
.pet-frames { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.pet-frame label { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: 6px; font-size: 13px; margin-top: 6px; }
.pet-frame .thumb { height: 90px; display: flex; align-items: center; justify-content: center; }
.pet-frame .thumb img, .pet-choices img { image-rendering: pixelated; transform: scale(2); }
.pet-choices { display: flex; flex-wrap: wrap; gap: 10px; }
.pet-choices figure { margin: 0; width: 80px; height: 90px; border: 1px solid var(--line); border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 14px 4px 4px; }
.pet-choices figcaption { font-size: 11px; }

/* New item / pet */
.steps ol { margin: 6px 0 0; padding-left: 20px; line-height: 1.6; }
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.slot.busy { opacity: .55; }
.slot .pair { display: flex; gap: 10px; margin: 8px 0; }
.slot figure { flex: 1; margin: 0; min-height: 110px; border: 1px solid var(--line); border-radius: 8px; padding: 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  background: repeating-conic-gradient(rgba(128,128,128,.12) 0 25%, transparent 0 50%) 0 0 / 12px 12px; }
.slot figure img { image-rendering: pixelated; max-width: 100%; max-height: 120px; min-height: 40px; object-fit: contain; }
.slot figure .empty { font-size: 28px; color: var(--muted, #999); margin: auto; }
.slot figcaption { font-size: 11px; }
.slot .drop { position: relative; display: block; border: 2px dashed var(--line); border-radius: 8px; padding: 12px;
  text-align: center; font-size: 13px; cursor: pointer; margin-bottom: 4px; }
.slot .drop.over, .slot .drop:hover { border-color: var(--accent); }
.slot .drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin: 10px 0; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }

.create-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin: 12px 0 18px; }
.create-btn { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-radius: 10px; font-weight: 600;
  border: 2px solid var(--accent); color: var(--accent); background: var(--panel); text-decoration: none; }
.create-btn span { font-size: 22px; line-height: 1; }
.create-btn:hover { background: var(--accent); color: #fff; }

a.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

.safety-banner { display: block; text-decoration: none; font-weight: 600; }
.console { background: #111; color: #ddd; font: 12px/1.4 Consolas, monospace; padding: 10px; border-radius: 8px;
  max-height: 360px; overflow: auto; white-space: pre-wrap; }
.console .bad { color: #ff7b7b; }
.light { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.light.ok { background: #2fa84f; } .light.bad { background: #d33; } .light.warn { background: #e0a030; }
