:root {
  --bg: #16110e;
  --surface: #241c17;
  --line: #3b2f27;
  --text: #f3ece3;
  --muted: #b7a89a;
  --accent: #d4b483;
  --ok: #8fba84;
  --bad: #e07a5f;
  --tap: 52px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  padding: env(safe-area-inset-top) 16px calc(16px + env(safe-area-inset-bottom));
}
#app { max-width: 480px; margin: 0 auto; }
#app.wide { max-width: 1120px; }
h1 { font-size: 1.6rem; margin: 12px 0 8px; font-weight: 600; letter-spacing: -0.03em; }
h2 { margin: 4px 0 12px; font-size: 1.35rem; }
p { color: var(--muted); line-height: 1.4; }
button, input, select {
  font: inherit;
  width: 100%;
  min-height: var(--tap);
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
}
button { cursor: pointer; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: #1a1410; border-color: var(--accent); font-weight: 650; }
button.compact { width: auto; min-height: 40px; padding: 0 12px; }
button.text-button {
  width: auto;
  min-height: 36px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
}
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.stack { display: grid; gap: 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.muted { color: var(--muted); font-size: 0.92rem; }
.banner { padding: 10px 12px; border-radius: 12px; background: #3a211c; color: #f3c7ba; margin: 10px 0; }
.banner.ok { background: #1e2a1c; color: var(--ok); }
.kicker { text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.72rem; color: var(--accent); }
.list { display: grid; gap: 8px; }
.list button { text-align: left; }
video { width: 100%; border-radius: 16px; background: #000; min-height: 180px; object-fit: cover; }
.strip {
  position: relative;
  height: 104px;
  border-radius: 12px;
  background: repeating-linear-gradient(90deg, #2b221c, #2b221c 20px, #322820 20px, #322820 21px);
  border: 1px solid var(--line);
  overflow: hidden;
  touch-action: manipulation;
}
.strip-item {
  position: absolute;
  top: 8px;
  bottom: 8px;
  border-radius: 8px;
  background: #4a3a2a;
  color: var(--text);
  font-size: 0.72rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  text-align: center;
  overflow: hidden;
}
.strip-item.primary { background: #6a5133; }
.qty { font-variant-numeric: tabular-nums; }
.topbar { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.topbar a, .text-link { color: var(--accent); text-decoration: none; }
.app-footer { text-align: center; padding: 28px 0 8px; letter-spacing: 0.08em; }
.store-area-endpoint { fill: var(--accent); stroke: var(--bg); stroke-width: 12; cursor: ew-resize; }

.home-actions { display: grid; gap: 14px; margin-top: 22px; }
.home-action {
  min-height: 128px;
  padding: 20px;
  text-align: left;
  display: grid;
  align-content: center;
  gap: 8px;
}
.home-action-title { display: block; font-size: 1.35rem; font-weight: 700; }
.home-action-copy { display: block; font-size: 0.95rem; line-height: 1.35; opacity: 0.78; }
.home-map-link { text-align: center; margin: 18px 0 0; }
.home-status { text-align: center; margin-top: 18px; }
.step { color: var(--muted); font-size: 0.85rem; }
.selected-product {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  margin: 12px 0;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.selected-product span { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; }
.selected-product strong { font-size: 1.05rem; }
.tap-instruction { margin: 16px 0 8px; color: var(--text); }
.tap-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  transform: translateX(-1px);
  pointer-events: none;
}
.field-label { display: grid; gap: 6px; color: var(--text); }
.location-code { font-size: 1.2rem; font-weight: 700; letter-spacing: 0.02em; }

.map-title-row,
.map-inspector-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.map-title-row h1,
.map-inspector-head h2,
.map-title-row .kicker,
.map-inspector-head .kicker { margin-bottom: 0; }
.store-map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
  margin-top: 16px;
}
.store-map-canvas,
.store-map-inspector {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.store-map-canvas {
  min-height: 600px;
  padding: 14px;
  overflow: hidden;
}
.store-map-inspector {
  padding: 16px;
  position: sticky;
  top: 16px;
}
#store-map-svg {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  background:
    linear-gradient(rgba(212, 180, 131, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(212, 180, 131, 0.035) 1px, transparent 1px),
    #1b1613;
  background-size: 32px 32px;
}
#store-map-svg.editing { touch-action: none; }
.store-outline {
  fill: #1d1814;
  stroke: var(--muted);
  stroke-width: 28;
  vector-effect: non-scaling-stroke;
}
.store-area { cursor: pointer; outline: none; }
.store-area-segment {
  fill: #5a4634;
  stroke: #2c211a;
  stroke-width: 14;
  vector-effect: non-scaling-stroke;
  transition: opacity 120ms ease, fill 120ms ease;
}
.store-area:hover .store-area-segment,
.store-area:focus .store-area-segment { fill: #735a40; }
.store-area.selected .store-area-segment { fill: var(--accent); }
.store-area-label {
  fill: var(--text);
  font-size: 220px;
  font-weight: 800;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}
.store-area.selected .store-area-label { fill: #1a1410; }
.map-inspector-empty { padding: 10px 0; }
.map-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 16px;
}
.map-facts div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.map-facts dt { color: var(--muted); font-size: 0.75rem; }
.map-facts dd { margin: 4px 0 0; font-variant-numeric: tabular-nums; }
.segment-fields {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
}
.segment-fields legend { color: var(--accent); padding: 0 6px; }
.segment-fields .field-label + .field-label { margin-top: 10px; }

.area-front-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  margin: 12px 0 18px;
}
.area-front-head p { margin: 0 0 8px; }
.area-front {
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #1b1613;
}
.shelf-row {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}
.shelf-label {
  display: grid;
  gap: 3px;
  text-align: right;
  color: var(--text);
}
.shelf-label span { color: var(--muted); font-size: 0.78rem; }
.shelf-track {
  position: relative;
  min-height: 92px;
  overflow: hidden;
  border: 1px solid #4a382c;
  border-radius: 10px 10px 4px 4px;
  background: repeating-linear-gradient(90deg, #261d18, #261d18 38px, #2d231c 38px, #2d231c 39px);
  transition: border-color 100ms ease, background 100ms ease;
}
.shelf-track.drop-target {
  border-color: var(--accent);
  background: #30251d;
}
.shelf-rail {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 12px;
  background: #6b4b31;
  border-top: 1px solid #8a6848;
  pointer-events: none;
}
.shelf-product {
  position: absolute;
  z-index: 2;
  top: 10px;
  bottom: 16px;
  min-height: 0;
  min-width: 22px;
  padding: 5px;
  border-radius: 7px 7px 3px 3px;
  border: 1px solid #836b52;
  background: #544331;
  color: var(--text);
  display: grid;
  align-content: center;
  gap: 2px;
  overflow: hidden;
  text-align: center;
  touch-action: none;
  user-select: none;
  cursor: grab;
}
.shelf-product span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.72rem;
}
.shelf-product small { color: var(--accent); font-size: 0.68rem; }
.shelf-product.dragging {
  opacity: 0.5;
  cursor: grabbing;
  outline: 2px solid var(--accent);
}

.three-title {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin: 8px 0 14px;
}
.three-title p { margin: 0 0 8px; }
.three-menu-toggle { display: none; }
.three-mobile-menu[hidden] { display: block; }
.store-3d-shell {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #17120f;
}
.store-3d-mobile-fullscreen { min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
.store-3d-canvas {
  width: 100%;
  height: min(74vh, 780px);
  min-height: 520px;
  touch-action: none;
}
.store-3d-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}
.store-3d-canvas canvas:active { cursor: grabbing; }
.store-3d-note {
  position: absolute;
  left: 14px;
  bottom: 14px;
  max-width: calc(100% - 28px);
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(22, 17, 14, 0.82);
  color: var(--muted);
  font-size: 0.82rem;
  pointer-events: none;
  backdrop-filter: blur(8px);
}
.touch-joystick { display: none; }

@media (max-width: 799px) {
  #app.wide { max-width: 600px; }
  .store-map-layout { grid-template-columns: 1fr; }
  .store-map-canvas { min-height: auto; padding: 8px; }
  #store-map-svg { height: auto; min-height: 0; aspect-ratio: 1 / 1; }
  .store-map-inspector { position: static; }
  .map-facts { grid-template-columns: 1fr; }
  .area-front-head { display: block; }
  .shelf-row { grid-template-columns: 72px minmax(0, 1fr); gap: 7px; }
  .shelf-label { font-size: 0.78rem; }
  .shelf-label span { font-size: 0.68rem; }
  .shelf-track { min-height: 78px; }
  .shelf-product { top: 8px; bottom: 14px; padding: 3px; }
  .shelf-product span { font-size: 0.64rem; }
  .three-title { display: block; }
  .store-3d-canvas { height: 58vh; min-height: 430px; }
  .store-3d-note { left: 9px; bottom: 9px; max-width: calc(100% - 18px); }
}

@media (max-width: 699px) {
  body:has(.store-3d-shell) { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
  #app:has(.store-3d-shell) { max-width: none; }
  .store-3d-shell { border: 0; border-radius: 0; min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  .store-3d-canvas { height: calc(100dvh - 74px); min-height: 0; }
  .store-3d-canvas canvas { touch-action: none; }
  .three-title { margin: 8px 16px; }
  .three-title > p { display: none; }
  .three-menu-toggle { display: block; width: auto; margin: 6px 16px 10px auto; min-height: 40px; }
  .three-mobile-menu { margin: 0 16px 10px; }
  .three-mobile-menu[hidden] { display: none; }
  .three-editor-toolbar { margin-top: 0; }
  .touch-joystick {
    display: grid;
    place-items: center;
    position: absolute;
    z-index: 3;
    bottom: calc(16px + env(safe-area-inset-bottom));
    width: 112px;
    height: 112px;
    border: 1px solid rgba(243, 236, 227, 0.36);
    border-radius: 50%;
    background: rgba(36, 28, 23, 0.42);
    backdrop-filter: blur(5px);
    touch-action: none;
    user-select: none;
  }
  .touch-joystick-move { left: 16px; }
  .touch-joystick-look { right: 16px; }
  .touch-joystick-thumb {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(212, 180, 131, 0.72);
    color: #1a1410;
    pointer-events: none;
    transform: translate(var(--joystick-x, 0px), var(--joystick-y, 0px));
  }
}


.map-editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 14px 0 2px;
}
.map-editor-toolbar .toolbar-spacer { flex: 1 1 20px; }
.map-editor-toolbar button.active {
  border-color: var(--accent);
  color: var(--accent);
}
.map-editor-toolbar .danger { color: #f0a39b; }
.map-editor-toolbar button:disabled { opacity: 0.4; cursor: not-allowed; }


.three-editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 10px 0 12px;
}
.three-editor-toolbar .toolbar-spacer { flex: 1 1 20px; }
.three-editor-toolbar button.active {
  border-color: var(--accent);
  color: var(--accent);
}
.three-editor-toolbar .danger { color: #f0a39b; }
.three-editor-toolbar button:disabled { opacity: 0.4; cursor: not-allowed; }

.camera-editor {
  margin: 0 0 12px;
}
.camera-editor-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}
.camera-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.camera-grid input {
  min-height: 42px;
}
#three-lock.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

@media (max-width: 699px) {
  .camera-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
