:root {
  --bg: #222326;
  --panel: #2a2c30;
  --panel-2: #32353b;
  --line: #3d4148;
  --text: #ffffff;
  --muted: #a8adb6;
  --accent: #f1e542;
  --accent-dim: rgba(241, 229, 66, 0.16);
  --danger: #ff5b7a;
  --success: #2eb85c;
  --food: #f59e0b;
  --drink: #38bdf8;
  --font: "Inter", "IBM Plex Sans JP", "Segoe UI", Meiryo, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --radius: 0.5rem;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}
.hidden { display: none !important; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
}
.brand { margin: 0; color: var(--accent); font-family: var(--mono); font-size: .8rem; }
.login-panel h1 { margin: 8px 0 4px; font-size: 1.6rem; }
.sub, .hint { color: var(--muted); font-size: .9rem; }
.error { color: var(--danger); font-size: .85rem; }

label { display: grid; gap: 6px; margin-bottom: 12px; color: var(--muted); font-size: .85rem; }
label.full { grid-column: 1 / -1; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; }
label b { color: var(--accent); font-family: var(--mono); font-weight: 600; }

input, textarea, select, button { font: inherit; }
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #171920;
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 12px;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }

.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn.primary { background: var(--accent); color: #1b1c1f; border-color: var(--accent); font-weight: 600; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 6px 10px; font-size: .8rem; }
.btn.sm { padding: 4px 10px; font-size: .75rem; }

.app { min-height: 100vh; display: flex; flex-direction: column; }
.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  height: 52px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand-row { display: flex; align-items: center; gap: 8px; }
.mark {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-dim);
}
.brand-row small { color: var(--muted); font-family: var(--mono); font-size: .75rem; }
.top-nav { display: flex; gap: 4px; flex: 1; }
.nav-link {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
}
.nav-link.active, .nav-link:hover { color: var(--text); background: var(--panel-2); }
.top-right { display: flex; align-items: center; gap: 8px; }
.user-chip { font-family: var(--mono); font-size: .8rem; color: var(--accent); }

.body { padding: 20px; max-width: 1200px; width: 100%; margin: 0 auto; }
.toolbar { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-left, .toolbar-right { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar-left input, .toolbar-left select { min-width: 180px; }

.item-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.item-row {
  display: grid;
  grid-template-columns: 48px 1fr 90px 70px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
}
.item-row:hover { background: var(--panel-2); }
.item-row:last-child { border-bottom: 0; }
.thumb {
  width: 40px; height: 40px; border-radius: 6px;
  background: #171920; border: 1px solid var(--line);
  display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: 10px;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.item-name .label { font-weight: 600; }
.item-name .id { font-family: var(--mono); font-size: .75rem; color: var(--muted); }
.cat {
  font-size: 11px; font-weight: 600; text-align: center;
  padding: 3px 8px; border-radius: 4px; text-transform: uppercase;
  background: var(--panel-2); color: var(--muted);
}
.cat-food { color: var(--food); background: rgba(245,158,11,.15); }
.cat-drink, .cat-alcohol { color: var(--drink); background: rgba(56,189,248,.15); }
.cat-tobacco, .cat-drug { color: #f472b6; background: rgba(244,114,182,.15); }
.effects { font-size: 12px; color: var(--muted); }
.row-actions { display: flex; gap: 4px; }

.empty { padding: 48px; text-align: center; color: var(--muted); }

.editor-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.editor-head h2 { margin: 0; font-size: 1.15rem; }
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
fieldset {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}
fieldset.full { grid-column: 1 / -1; }
legend { color: var(--accent); font-size: .8rem; font-weight: 600; padding: 0 6px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.image-row { display: flex; gap: 12px; align-items: flex-end; }
.image-preview {
  width: 72px; height: 72px; border-radius: 8px;
  background: #171920; border: 1px solid var(--line);
  display: grid; place-items: center; overflow: hidden; flex-shrink: 0;
  color: var(--muted); font-size: 11px;
}
.image-preview img { width: 100%; height: 100%; object-fit: contain; }
.grow { flex: 1; }
#f_emote { height: 220px; }

.emote-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(220px, 0.9fr);
  gap: 16px;
  align-items: stretch;
}
.emote-preview {
  border: 1px solid var(--line);
  background: #171920;
  border-radius: 8px;
  padding: 12px;
  min-height: 220px;
}
.emote-cmd {
  margin: 10px 0 6px;
  font-family: var(--mono);
  font-size: .8rem;
  color: var(--accent);
}
.emote-desc, .emote-meta {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.45;
}
.emote-meta { font-family: var(--mono); font-size: .72rem; word-break: break-all; }
.emote-3d {
  display: inline-block;
  margin-top: 4px;
  color: var(--accent);
  font-size: .8rem;
}
.emote-stage {
  height: 132px;
  border-radius: 8px;
  background: radial-gradient(ellipse at 50% 78%, rgba(241,229,66,.16), transparent 55%), #12141a;
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
}
.ped {
  position: absolute;
  left: 50%;
  top: 22px;
  width: 28px;
  height: 86px;
  margin-left: -14px;
  transform-origin: 50% 90%;
}
.ped .head {
  position: absolute; left: 7px; top: 0;
  width: 14px; height: 14px; border-radius: 50%;
  background: #e8ead1;
}
.ped .torso {
  position: absolute; left: 8px; top: 16px;
  width: 12px; height: 28px; border-radius: 5px;
  background: #c8b94a;
}
.ped .arm {
  position: absolute; top: 18px; width: 6px; height: 26px;
  border-radius: 4px; background: #d7d3a8;
  transform-origin: 50% 8%;
}
.ped .arm-l { left: 1px; }
.ped .arm-r { right: 1px; }
.ped .leg {
  position: absolute; top: 42px; width: 7px; height: 32px;
  border-radius: 4px; background: #8d9070;
  transform-origin: 50% 0;
}
.ped .leg-l { left: 6px; }
.ped .leg-r { right: 6px; }
.ped .shadow {
  position: absolute; left: -10px; bottom: -8px;
  width: 48px; height: 8px; border-radius: 50%;
  background: rgba(0,0,0,.35);
}
.ped .prop-dot {
  position: absolute; right: -10px; top: 22px;
  width: 12px; height: 12px; border-radius: 3px;
  background: #38bdf8;
  box-shadow: 0 0 0 3px rgba(56,189,248,.2);
}
.emote-stage[data-motion="idle"] .ped { animation: ped-idle 1.8s ease-in-out infinite; }
.emote-stage[data-motion="generic"] .ped { animation: ped-idle 1.4s ease-in-out infinite; }
.emote-stage[data-motion="eat"] .arm-r,
.emote-stage[data-motion="drink"] .arm-r,
.emote-stage[data-motion="smoke"] .arm-r { animation: arm-mouth 1.1s ease-in-out infinite; }
.emote-stage[data-motion="dance"] .ped { animation: ped-dance .7s ease-in-out infinite; }
.emote-stage[data-motion="dance"] .arm-l { animation: arm-out .7s ease-in-out infinite; }
.emote-stage[data-motion="dance"] .arm-r { animation: arm-out .7s ease-in-out infinite reverse; }
.emote-stage[data-motion="scenario"] .ped { animation: ped-idle 2.4s ease-in-out infinite; }
.emote-stage[data-moving="1"] .ped { animation: ped-walk .55s linear infinite; }
.emote-stage[data-moving="1"] .leg-l { animation: leg-step .55s linear infinite; }
.emote-stage[data-moving="1"] .leg-r { animation: leg-step .55s linear infinite reverse; }
@keyframes ped-idle {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}
@keyframes ped-dance {
  0%, 100% { transform: rotate(-8deg) translateY(0); }
  50% { transform: rotate(8deg) translateY(-8px); }
}
@keyframes ped-walk {
  0%, 100% { transform: translateX(-10px); }
  50% { transform: translateX(10px); }
}
@keyframes arm-mouth {
  0%, 100% { transform: rotate(8deg); }
  50% { transform: rotate(-70deg); }
}
@keyframes arm-out {
  0%, 100% { transform: rotate(25deg); }
  50% { transform: rotate(-35deg); }
}
@keyframes leg-step {
  0%, 100% { transform: rotate(18deg); }
  50% { transform: rotate(-18deg); }
}

@media (max-width: 900px) {
  .emote-layout { grid-template-columns: 1fr; }
}

.shop-list { display: grid; gap: 12px; }
.shop-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.shop-card h3 { margin: 0 0 6px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 4px; margin-left: 8px; background: var(--panel-2); color: var(--muted); }
.loc { font-family: var(--mono); font-size: .8rem; color: var(--muted); margin-top: 8px; }

.give-grid {
  display: grid;
  grid-template-columns: 1fr 120px 1fr auto;
  gap: 12px;
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.toast {
  position: fixed; right: 24px; bottom: 24px;
  padding: 10px 16px; border-radius: 8px; color: #fff;
  opacity: 0; transform: translateY(12px); transition: .2s; pointer-events: none; z-index: 20;
}
.toast.show { opacity: 1; transform: none; }
.toast.ok { background: var(--success); }
.toast.err { background: var(--danger); }

.confirm {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: grid; place-items: center; z-index: 30;
}
.confirm-box {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 24px; min-width: 320px; text-align: center;
}

@media (max-width: 900px) {
  .editor-grid, .give-grid, .item-row { grid-template-columns: 1fr; }
  .top { flex-wrap: wrap; height: auto; padding: 8px; }
}
