:root {
  color-scheme: light;
  --ink: #252933;
  --muted: #77746f;
  --panel: #ffffff;
  --line: #e4e2dc;
  --soft: #f8f7f4;
  --rail: #1e2430;
  --rail-active: #2f3a4d;
  --accent: oklch(0.58 0.14 12);
  --accent-soft: oklch(0.95 0.035 12);
}

* { box-sizing: border-box; }

html,
body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: #f4f3f0;
  color: var(--ink);
  font-family: "Zen Kaku Gothic New", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  font-size: 13px;
}

body::before {
  position: fixed;
  z-index: -1;
  inset: 0;
  background:
    linear-gradient(rgba(244, 243, 240, .58), rgba(244, 243, 240, .58)),
    url("assets/site/bg.jpg") center / cover no-repeat;
  content: "";
}

button,
input,
select { font: inherit; }

button {
  min-height: 34px;
  border: 1px solid #dedbd4;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 11px;
  cursor: pointer;
}

button:hover { border-color: var(--accent); }

.app {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) 316px;
  width: min(1320px, 100%);
  max-width: 1320px;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: var(--panel);
  box-shadow: none;
}

.category-rail {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 16px;
  padding: 14px 10px;
  background: var(--rail);
}

.rail-logo {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: 0 auto;
}

.rail-logo img {
  display: block;
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
}

.part-tabs {
  display: grid;
  gap: 6px;
}

.visitor-counter {
  margin-top: auto;
  color: #8d96a3;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1;
  text-align: center;
  letter-spacing: 0;
}

.part-tab[data-kind="hair"] {
  margin-top: 26px;
}

.part-tab {
  display: grid;
  justify-items: center;
  gap: 4px;
  min-height: 60px;
  padding: 7px 3px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #b9c1cc;
  font-size: 11px;
}

.part-tab:hover,
.part-tab.active {
  background: var(--rail-active);
  color: #fff;
}

.rail-icon {
  display: block;
  width: 32px;
  height: 32px;
  object-fit: contain;
  image-rendering: pixelated;
}

.rail-icon-placeholder {
  background: transparent;
}

.item-browser {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: 72px minmax(0, 1fr);
  background: #fff;
}

.item-catalog {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.browser-header {
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
}

h1,
h2 { margin: 0; }

h1 { font-size: 17px; }
h2 { font-size: 12px; color: #68645e; }

input[type="search"],
select {
  width: 100%;
  height: 34px;
  border: 1px solid #dfdcd6;
  border-radius: 8px;
  background: #faf9f7;
  color: var(--ink);
  padding: 0 10px;
}

input[type="search"]:focus,
select:focus {
  outline: 2px solid oklch(0.8 0.06 12);
  border-color: var(--accent);
}

#itemCount {
  color: #9c9891;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
  white-space: nowrap;
}

.equipment-list {
  display: grid;
  align-content: start;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 12px;
  flex: 0 1 auto;
  max-height: 70%;
  min-height: 0;
  overflow: hidden;
  padding: 16px 20px 24px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 52px;
  padding: 8px 20px;
}

.page-button {
  min-width: 34px;
  min-height: 34px;
  padding: 0 9px;
  border-radius: 8px;
  color: #787168;
  font-size: 12px;
}

.page-button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.page-button:disabled {
  cursor: default;
  opacity: .42;
}

.equipment-item {
  display: grid;
  grid-template-rows: 64px minmax(18px, auto);
  justify-items: center;
  align-content: center;
  gap: 7px;
  min-width: 0;
  min-height: 112px;
  padding: 8px;
  border-color: #e8e5df;
  border-radius: 12px;
  background: #fff;
  text-align: center;
}

.equipment-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.equipment-item img,
.equipment-item .empty-icon,
.equipment-item .part-thumb,
.equipment-item .inventory-icon {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
}

.inventory-icon {
  display: block;
  object-fit: contain;
}

.equipment-item > span:last-child {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.equipment-item small { display: none; }

.empty-icon {
  display: block;
  border: 1px dashed #d3cfc7;
  border-radius: 8px;
  background: #f7f6f3;
}

.part-thumb {
  display: block;
  border-radius: 6px;
  background: #f7f6f3;
}

.inspector {
  display: grid;
  align-content: start;
  min-height: 0;
  gap: 12px;
  overflow-y: auto;
  padding: 14px;
  border-left: 1px solid var(--line);
  background: var(--soft);
}

/* Preview actions stay first; the working controls follow in usage order. */
.appearance-panel { order: 1; }
.equipped-panel { order: 2; }
.random-panel { order: 3; }

.preview-card,
.inspector-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.preview-card { padding: 9px; }

.stage-wrap {
  position: relative;
  display: grid;
  place-items: center;
  height: 300px;
  overflow: hidden;
  border-radius: 9px;
  background: repeating-linear-gradient(-45deg, #f5f4f1 0 7px, #f9f8f6 7px 14px);
}

.stage-background-control {
  position: absolute;
  z-index: 1;
  top: 8px;
  left: 8px;
  padding: 4px;
  border: 1px solid rgba(222, 219, 212, .85);
  border-radius: 8px;
  background: rgba(255, 255, 255, .82);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.action-row button { padding: 0 7px; font-size: 12px; }

.primary-action {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary-action:hover { color: #fff; filter: brightness(.96); }

.inspector-card { padding: 12px; }

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.panel-actions .primary-action { min-height: 29px; padding: 0 9px; font-size: 11px; }

.icon-button {
  display: grid;
  place-items: center;
  width: 29px;
  min-height: 29px;
  padding: 0;
  color: #847d73;
}

.random-panel.collapsed .panel-heading { margin-bottom: 0; }
.random-panel.collapsed .random-panel-content { display: none; }
.equipped-panel.collapsed .panel-heading { margin-bottom: 0; }
.equipped-panel.collapsed .equipped-panel-content { display: none; }
.appearance-panel.collapsed .panel-heading { margin-bottom: 0; }
.appearance-panel.collapsed .appearance-panel-content { display: none; }

.random-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 10px;
}

.check-option {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: #4e4a45;
  font-size: 12px;
}

.check-option input,
.toggle-control input { accent-color: var(--accent); }

.check-option.fixed { color: #b5b0a8; }

.fixed-badge {
  margin-left: auto;
  color: #aaa49b;
  font-size: 9px;
}

.equipped-list { display: grid; gap: 5px; }

.equipped-item {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 45px;
  padding: 5px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  text-align: left;
}

.equipped-item:hover,
.equipped-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.equipped-item img,
.equipped-item .empty-icon,
.equipped-item .part-thumb,
.equipped-item .inventory-icon {
  width: 32px;
  height: 32px;
}

.equipped-item .part-thumb,
.equipped-item .inventory-icon {
  border: 1px solid #dfdcd6;
  border-radius: 6px;
  background: #faf9f7;
}

.equipped-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.equipped-item b {
  display: block;
  color: #969087;
  font-size: 10px;
  font-weight: 500;
}

.remove-equipped {
  min-height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #bbb4ab;
  font-size: 17px;
  line-height: 1;
}

.remove-equipped:hover { color: var(--accent); }

.appearance-panel-content {
  display: grid;
  gap: 9px;
}

.appearance-panel-content > label {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  color: #6e6961;
  font-size: 12px;
}

.appearance-panel-content > label.range-control {
  grid-template-columns: 42px minmax(0, 1fr);
}

.appearance-panel-content select { height: 31px; font-size: 12px; }

.range-control .range-label { grid-column: 1; }

.range-control select {
  grid-column: 2;
  width: 100%;
}

.swatches { display: flex; gap: 6px; }

.swatch {
  width: 22px;
  height: 22px;
  min-height: 22px;
  padding: 0;
  border-radius: 6px;
  background: var(--swatch);
}

.swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px oklch(0.8 0.06 12);
}

.stage-background-control .swatch {
  width: 18px;
  height: 18px;
  min-height: 18px;
  border-radius: 5px;
}

.appearance-actions {
  display: grid;
  grid-template-columns: 118px 74px;
  justify-content: start;
  column-gap: 14px;
  row-gap: 6px;
  padding-top: 2px;
}

.toggle-control {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 29px;
  color: #69645d;
  font-size: 11px;
  white-space: nowrap;
}

.toggle-control span {
  white-space: nowrap;
}

.flip-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  grid-column: 1 / -1;
}


.control-button,
.reset-button {
  min-height: 29px;
  padding: 0 8px;
  font-size: 11px;
}

.control-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.reset-button { color: #888178; }

.rights-notice {
  margin: 0;
  padding: 1px 20px 8px;
  color: #aaa49b;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 10px;
  line-height: 1.55;
  text-align: center;
}

@media (max-width: 960px) {
  .app {
    grid-template-columns: 76px minmax(0, 1fr) 280px;
    width: 100%;
    height: 100dvh;
    margin: 0;
  }
}

@media (max-width: 600px) {
  body {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .app {
    grid-template-columns: 54px minmax(0, 1fr);
    grid-template-rows: auto 100dvh;
    width: 100%;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .category-rail {
    position: sticky;
    z-index: 3;
    top: 0;
    grid-column: 1;
    grid-row: 1 / span 2;
    align-self: start;
    height: 100dvh;
    gap: 10px;
    padding: 10px 4px;
  }

  .rail-logo,
  .rail-logo img {
    width: 26px;
    height: 26px;
  }

  .part-tabs { gap: 2px; }

  .part-tab[data-kind="hair"] { margin-top: 14px; }

  .part-tab {
    gap: 2px;
    min-height: 46px;
    padding: 4px 1px;
    border-radius: 6px;
    font-size: 9px;
  }

  .rail-icon {
    width: 25px;
    height: 25px;
  }

  .visitor-counter { font-size: 9px; }

  .inspector {
    grid-column: 2;
    grid-row: 1;
    gap: 8px;
    overflow: visible;
    padding: 8px;
  }

  .preview-card { padding: 7px; }

  .stage-wrap {
    height: min(300px, calc(100vw - 92px));
  }

  .item-browser {
    grid-column: 2;
    grid-row: 2;
    grid-template-rows: 58px minmax(0, 1fr);
    height: 100dvh;
  }

  .browser-header {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px;
    padding: 0 10px;
  }

  .browser-header h1 { font-size: 14px; }
  #itemCount { display: none; }

  .equipment-list {
    grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
    gap: 8px;
    padding: 10px 10px 16px;
  }

  .equipment-item {
    grid-template-rows: 56px minmax(18px, auto);
    min-height: 100px;
    padding: 6px;
    border-radius: 8px;
  }

  .equipment-item img,
  .equipment-item .empty-icon,
  .equipment-item .part-thumb,
  .equipment-item .inventory-icon {
    width: 56px;
    height: 56px;
  }

  .pagination {
    min-height: 48px;
    padding: 6px 10px;
  }

  .rights-notice { padding-inline: 10px; }
}
