:root {
  --bg: #ffffff;
  --card: #f6f3ef;
  --text: #131313;
  --muted: #5f5f5f;
  --border: #d8d2cb;
  --accent: #131313;
  --radius: 20px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
body.no-scroll { overflow: hidden; }

.container { width: min(1200px, 92vw); margin: 0 auto; }
.site-header { border-bottom: 1px solid #efefef; background: #fff; position: sticky; top: 0; z-index: 20; }
.nav { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; position: relative; }
.main-nav { display: flex; gap: 16px; }
.nav-toggle { display: none; width: auto; padding: 8px 10px; border-radius: 10px; background: #fff; color: #111; border: 1px solid var(--border); }
.nav-overlay { display: none; }
.brand { text-decoration: none; font-weight: 700; color: var(--text); }
a { color: inherit; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-top: 24px;
}
.section-flat {
  margin-top: 18px;
  padding: 8px 0;
}
.profile-switcher {
  display: flex;
  gap: 8px;
  margin: 10px 0 12px;
}
.switch-btn {
  width: auto;
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
  position: relative;
}
.switch-btn.active {
  background: #111;
  color: #fff;
  border-color: #111;
}
.pane-section { display: none; }
.pane-section.active { display: block; }
.state-badge {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #d93025;
  margin-left: 8px;
  vertical-align: middle;
}

h1, h2, h3 { line-height: 1.2; }
input, textarea, button {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  background: #fff;
}
textarea { min-height: 90px; }
button {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  cursor: pointer;
  font-weight: 700;
}
.ghost,
button,
input,
textarea {
  font-size: 16px;
}
.stack { display: grid; gap: 12px; }
.notice { background: #dcfce7; padding: 10px; border-radius: 10px; }
.error { background: #fee2e2; padding: 10px; border-radius: 10px; }
.hint, .muted { color: var(--muted); }

.auth-wrap { min-height: calc(100vh - 90px); display: grid; place-items: center; }
.auth-card { width: min(500px, 100%); }

.dashboard-page {
  width: min(1680px, 96vw);
  margin-bottom: 40px;
}

.builder-flat {
  margin-top: 18px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  max-width: 100%;
  overflow: hidden;
}
.builder-header {
  text-align: center;
  margin-bottom: 10px;
}
.builder-header.compact {
  margin-bottom: 8px;
}
.builder-header h2 {
  margin: 0;
  font-size: 44px;
  letter-spacing: 0.2px;
}
.builder-header p {
  margin: 8px 0 0;
  color: var(--muted);
}

.builder-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 6px;
  scrollbar-width: thin;
}
.tab-btn {
  width: auto;
  white-space: nowrap;
  border-radius: 999px;
  padding: 8px 12px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
}
.tab-btn.active {
  background: #111;
  color: #fff;
  border-color: #111;
}
.tab-icon { font-size: 18px; line-height: 1; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.tab-panels {
  margin-top: 6px;
  width: 100%;
  max-width: 100%;
}
.tab-panel {
  display: none;
}
.tab-panel.active { display: block; }

.asset-grid.tabbed {
  max-height: 180px;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 6px;
}

.asset-chip {
  width: 100%;
  border: 1px solid #d1cbc4;
  border-radius: 8px;
  background: #fff;
  padding: 4px;
  display: grid;
  place-items: center;
}
.asset-chip img {
  width: 100%;
  height: 50px;
  object-fit: contain;
  pointer-events: none;
}
.builder-canvas-wrap {
  min-height: 460px;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 8px;
  position: relative;
  max-width: 100%;
  min-width: 0;
}
.builder-canvas-wrap.compact { gap: 5px; }
.avatar-canvas.large {
  height: 100%;
  min-height: 420px;
  background: #f6f6f6;
  touch-action: none;
}
.avatar-canvas.compact {
  min-height: 360px;
  width: 100%;
  max-width: 100%;
}
.avatar-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  max-width: 100%;
}
.builder-library {
  min-width: 0;
  max-width: 100%;
}
.builder-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.builder-actions.compact .ghost {
  padding: 8px 10px;
}
.ghost {
  width: auto;
  padding: 8px 12px;
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}

.avatar-canvas {
  position: relative;
  height: 560px;
  border: 2px dashed var(--border);
  border-radius: 14px;
  background: #fff;
  overflow: hidden;
  max-width: 100%;
}
.scale-controls {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 8;
}
.scale-controls.hidden { display: none; }
.scale-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
  color: #111;
  font-size: 22px;
  line-height: 1;
  padding: 0;
}
.item-controls {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  gap: 8px;
  z-index: 8;
}
.item-controls.hidden { display: none; }
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  color: #111;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}
.item-controls .icon-btn {
  flex: 0 0 auto;
}
.clear-btn {
  position: absolute;
  right: 8px;
  top: 8px;
  z-index: 9;
}
.canvas-item {
  position: absolute;
  cursor: move;
  user-select: none;
  will-change: left, top;
}
.canvas-item.selected {
  outline: 2px solid #222;
  outline-offset: 2px;
}

.search-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.playfield-surface-wrap {
  margin-bottom: 40px;
  padding: 14px;
}
.playfield-surface {
  position: relative;
  min-height: 980px;
  border-radius: 18px;
  background:
    radial-gradient(circle at 15% 20%, #f6f7f8 0, transparent 35%),
    radial-gradient(circle at 80% 70%, #f2f3f4 0, transparent 33%),
    #ffffff;
  overflow: hidden;
}
.figure-node {
  position: absolute;
  width: 180px;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  transition: transform .16s ease;
  touch-action: manipulation;
}
.figure-node:hover {
  transform: translate(-50%, -50%) scale(1.03);
}
.figure-avatar-free {
  position: relative;
  width: 180px;
  height: 220px;
  overflow: visible;
}
.figure-avatar-free img,
.profile-avatar img {
  position: absolute;
}
.figure-name {
  margin-top: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  font-weight: 700;
  font-size: 15px;
  text-align: center;
}
.profile-detail { display: grid; grid-template-columns: 340px 1fr; gap: 24px; }
.profile-avatar {
  position: relative;
  height: 420px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--border);
  overflow: hidden;
}
.wall-page { margin-bottom: 40px; }
.wall-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}
.wall-card {
  text-decoration: none;
  border: 1px solid #ececec;
  border-radius: 14px;
  background: #fff;
  padding: 12px;
}
.wall-card h3 { margin: 8px 0 4px; font-size: 18px; }
.wall-card p { margin: 0; font-size: 14px; }
.wall-avatar {
  position: relative;
  height: 220px;
  overflow: hidden;
  border-radius: 10px;
  background: #fafafa;
  display: flex;
  justify-content: center;
}
.wall-scene {
  position: relative;
  width: 420px;
  height: 520px;
  transform: scale(0.44);
  transform-origin: top center;
}
.wall-avatar img { position: absolute; }

@media (max-width: 980px) {
  .container { width: min(100%, 96vw); }
  .nav { gap: 10px; }
  .nav-toggle { display: inline-flex; }
  .main-nav {
    position: fixed;
    top: 0;
    right: 0;
    width: min(84vw, 320px);
    height: 100vh;
    background: #fff;
    border-left: 1px solid var(--border);
    transform: translateX(100%);
    transition: transform 0.22s ease;
    z-index: 60;
    display: flex;
    flex-direction: column;
    padding: 76px 16px 16px;
    gap: 10px;
  }
  .main-nav.open { transform: translateX(0); }
  .main-nav a {
    display: block;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    text-decoration: none;
  }
  .nav-overlay.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.26);
    z-index: 50;
  }

  .profile-detail,
  .wall-grid {
    grid-template-columns: 1fr;
  }
  .builder-header h2 { font-size: 34px; }
  .avatar-workspace {
    grid-template-columns: 1fr;
    gap: 5px;
  }
  .builder-library { order: 1; }
  .builder-canvas-wrap { order: 2; }
  .asset-grid.tabbed {
    max-height: 152px;
    grid-template-columns: repeat(8, minmax(48px, 1fr));
  }
  .asset-chip { min-height: 52px; padding: 3px; }
  .asset-chip img { height: 42px; }
  .builder-canvas-wrap.compact { min-height: 428px; }
  .avatar-canvas.compact { min-height: 300px; }
  .profile-switcher { overflow-x: auto; padding-bottom: 4px; }
  .scale-controls { right: 4px; }
  .scale-btn { width: 34px; height: 34px; font-size: 20px; }
  .item-controls { bottom: 6px; left: 6px; right: 6px; }
  .icon-btn { width: 36px; height: 36px; font-size: 18px; }

  .playfield-surface-wrap { padding: 8px; }
  .playfield-surface { min-height: 820px; }
  .figure-node { width: 144px; }
  .figure-avatar-free { width: 144px; height: 178px; }
  .figure-name { font-size: 13px; padding: 2px 6px; }
}

@media (max-width: 640px) {
  .card { padding: 16px; border-radius: 14px; }
  .builder-header h2 { font-size: 28px; }
  .builder-header p { font-size: 14px; }
  .builder-flat { margin-top: 10px; }
  .tab-btn { padding: 7px 10px; font-size: 14px; }
  .asset-grid.tabbed { max-height: 132px; grid-template-columns: repeat(6, minmax(44px, 1fr)); }
  .avatar-canvas.compact { min-height: 260px; width: 100%; }
  .builder-canvas-wrap.compact { min-height: 380px; width: 100%; }
  .tab-icon { font-size: 16px; }
  .scale-btn { width: 32px; height: 32px; font-size: 18px; }
  .icon-btn { width: 34px; height: 34px; font-size: 17px; }
  .wall-scene { transform: scale(0.36); }
  .search-row { grid-template-columns: 1fr; }
}
