* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Noto Sans HK', 'Microsoft JhengHei', 'Segoe UI', sans-serif;
  background: #121214;
  color: #e2e8f0;
  height: 100vh;
  overflow: hidden;
  user-select: none;
}

.lang-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(30, 30, 36, 0.92);
  border: 1px solid #3f3f46;
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
}
.lang-switcher-start {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 5;
}
.lang-switcher .lang-label {
  font-size: 0.7rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 2px;
}
.lang-btn {
  border: 1px solid transparent;
  background: transparent;
  color: #cbd5e1;
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
}
.lang-btn:hover { background: #27272a; color: #fff; }
.lang-btn.active {
  background: #e94560;
  border-color: #e94560;
  color: #fff;
  font-weight: bold;
}

#screen-start, #screen-family, #screen-game, #screen-event, #screen-end {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.active { display: flex !important; }

/* 通用按鈕 */
.btn-action {
  background: #e94560;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.8rem 2rem;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all .15s;
  font-weight: bold;
}
.btn-action:hover { background: #c73652; transform: scale(1.02); }

/* ── START & FAMILY ── */
.title-area { text-align: center; max-width: 600px; margin-bottom: 2rem; }
.title-area h1 { font-size: 2.4rem; color: #e94560; margin-bottom: 1rem; }
.title-area p { color: #94a3b8; line-height: 1.6; }

.name-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 0 0 1.25rem;
  width: min(320px, 90vw);
}
.name-field label {
  font-size: 0.9rem;
  color: #94a3b8;
}
.name-field input {
  width: 100%;
  background: #1e1e24;
  border: 1px solid #3f3f46;
  border-radius: 8px;
  color: #e2e8f0;
  font-size: 1rem;
  padding: 10px 14px;
  text-align: center;
  outline: none;
}
.name-field input:focus {
  border-color: #e94560;
  box-shadow: 0 0 0 2px rgba(233, 69, 96, 0.25);
}

.family-box {
  background: #1e1e24;
  border: 2px solid #3f3f46;
  border-radius: 12px;
  padding: 2rem;
  max-width: 500px;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}
.family-identity { font-size: 3rem; margin-bottom: 0.5rem; }
.family-title { font-size: 1.6rem; color: #f5a623; margin-bottom: 1rem; font-weight: bold; }
.must-list { background: #2d2d35; padding: 1rem; border-radius: 8px; text-align: left; margin: 1rem 0; font-size: 0.95rem;}
.must-list li { margin: 0.4rem 0; color: #cbd5e1; }

/* ── GAME LAYOUT ── */
#screen-game { flex-direction: row; padding: 0; background: #151518; height: 100vh; }

#sidebar {
  width: 270px;
  background: #1e1e24;
  border-right: 1px solid #2d2d35;
  display: flex;
  flex-direction: column;
  padding: 15px 10px;
  gap: 12px;
  flex-shrink: 0;
  height: 0;
  min-height: 100%;
}
#sidebar h3 { font-size: .85rem; color: #64748b; text-align: center; text-transform: uppercase; letter-spacing: 1px; flex-shrink: 0; }
#core-items-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
#core-items-section:empty { display: none; }
#core-items-section .section-label {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 700;
  color: #f5a623;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 0;
  background: rgba(245, 166, 35, 0.08);
  border: 1px solid rgba(245, 166, 35, 0.2);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
}
#core-items-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  background: rgba(245, 166, 35, 0.06);
  border: 1px solid rgba(245, 166, 35, 0.2);
  border-top: none;
  border-radius: 0 0 6px 6px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
#core-items-list:empty { display: none; }
#core-items-list:empty + #core-items-section { display: none; }
.item-chip.core {
  background: rgba(245, 166, 35, 0.1);
  border-color: rgba(245, 166, 35, 0.35);
}
#items-list { flex: 1; overflow-y: auto; overflow-x: visible; display: flex; flex-direction: column; gap: 12px; min-height: 0; padding: 4px 4px 8px; }

.item-chip {
  background: #27272a;
  border: 1px solid #3f3f46;
  border-radius: 8px;
  padding: 10px;
  cursor: grab;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background .15s;
  overflow: visible;
}
.item-chip .details { flex: 1; min-width: 0; }

/* Mini 3D furniture icon — real footprint aspect, uniform scale (no stretch) */
.chip-3d {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  perspective: 200px;
  perspective-origin: 50% 40%;
  overflow: visible;
  pointer-events: none;
  background: transparent;
  border: none;
  position: relative;
}
.chip-3d-stage {
  width: var(--chip-w, 40px);
  height: var(--chip-h, 40px);
  position: absolute;
  left: 50%;
  top: 56%;
  margin: 0;
  transform-style: preserve-3d;
  transform: translate(-50%, -50%) rotateX(56deg) rotateZ(-28deg) scale(var(--chip-scale, 0.4));
  transform-origin: center center;
}
.chip-3d .pi-model {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}
.chip-3d .pi-shadow,
.chip-3d .pi-label-tag {
  display: none !important;
}
#drag-ghost.ghost-3d {
  font-size: inherit;
  width: 64px;
  height: 64px;
  transform: translate(-50%, -50%);
  background: transparent;
}
#drag-ghost.ghost-3d .chip-3d {
  width: 64px;
  height: 64px;
  overflow: visible;
  background: transparent;
  border: none;
}
.item-chip .name { font-size: 0.9rem; font-weight: bold; color: #f1f5f9; }
.item-chip .need { font-size: 0.75rem; color: #f5a623; margin-top: 2px; }
.item-chip .size-tag { font-size: 0.7rem; color: #94a3b8; background: #18181b; padding: 1px 4px; border-radius: 4px; float: right; }
.item-chip.used { opacity: .2; cursor: default; border-color: #27272a; }
.item-chip.banned {
  opacity: 0.35;
  cursor: not-allowed;
  border-color: #7f1d1d;
  background: rgba(233, 69, 96, 0.08);
}
.item-chip.banned .name { color: #fca5a5; }
.item-chip:not(.used):not(.banned):hover { background: #323238; border-color: #e94560; }
#timer-hud.timer-paused {
  opacity: 0.75;
  border-style: dashed;
}

#main-stage { flex: 1; display: flex; flex-direction: column; height: 100%; position: relative; }

#qol-panel {
  background: #1e1e24;
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  border-bottom: 1px solid #2d2d35;
  align-items: center;
}
.qol-metric { font-size: 0.85rem; color: #cbd5e1; display: flex; align-items: center; gap: 6px; }
.qol-stars { color: #f5a623; letter-spacing: 1px; }
#timer-hud {
  margin-left: auto;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
  color: #e2e8f0;
  background: rgba(148,163,184,0.15);
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 0.95rem;
  border: 1px solid #3f3f46;
  min-width: 72px;
  text-align: center;
}
#timer-hud.timer-urgent {
  color: #f5a623;
  border-color: #f5a623;
  background: rgba(245,166,35,0.12);
}
#timer-hud.timer-critical {
  color: #fff;
  border-color: #e94560;
  background: rgba(233,69,96,0.35);
  animation: timer-pulse 0.6s ease-in-out infinite alternate;
}
@keyframes timer-pulse {
  from { opacity: 1; }
  to { opacity: 0.7; }
}
#space-hud { font-weight: bold; color: #ff6b6b; background: rgba(233,69,96,0.1); padding: 4px 10px; border-radius: 6px; font-size: 0.9rem; }

#canvas-wrap {
  flex: 1;
  position: relative;
  background: #0b0b0e;
  overflow: hidden;
  touch-action: none;
}
#door-indicator {
  position: absolute;
  top: 10px; left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem; color: #e94560; font-weight: bold;
  background: #121214; padding: 2px 8px; border-radius: 10px; border: 1px solid #e94560;
  z-index: 30;
  max-width: 92%;
  text-align: center;
  pointer-events: none;
}
#view-hint {
  position: absolute;
  bottom: 14px; left: 50%;
  transform: translateX(-50%);
  font-size: 0.72rem;
  color: #94a3b8;
  background: rgba(18, 18, 20, 0.88);
  border: 1px solid #3f3f46;
  padding: 4px 10px;
  border-radius: 999px;
  z-index: 30;
  pointer-events: none;
  white-space: nowrap;
}
#room-viewport {
  position: absolute;
  inset: 0;
  perspective: 1100px;
  perspective-origin: 50% 42%;
  cursor: grab;
  overflow: hidden;
}
#room-viewport.orbiting { cursor: grabbing; }
#room-viewport.placing { cursor: crosshair; }
#room-world {
  position: absolute;
  left: 50%;
  top: 48%;
  width: 360px;
  height: 360px;
  margin-left: -180px;
  margin-top: -180px;
  transform-style: preserve-3d;
  transform: rotateX(var(--view-rx, 58deg)) rotateZ(var(--view-rz, -28deg)) scale(var(--view-zoom, 1));
  transition: none;
  will-change: transform;
}
#room-stage {
  position: relative;
  width: 360px;
  height: 360px;
  transform-style: preserve-3d;
}
#room-canvas {
  position: absolute;
  inset: 0;
  width: 360px;
  height: 360px;
  background: #f4ebe1;
  border: none;
  box-shadow:
    0 0 0 3px #4b5563,
    0 18px 40px rgba(0,0,0,0.55);
  transform: translateZ(0.5px);
  transform-style: preserve-3d;
}
#preview-canvas {
  position: absolute;
  inset: 0;
  width: 360px;
  height: 360px;
  pointer-events: none;
  z-index: 5;
  transform: translateZ(1px);
}
#placed-layer {
  position: absolute;
  inset: 0;
  width: 360px;
  height: 360px;
  pointer-events: none;
  transform-style: preserve-3d;
  z-index: 10;
}
.floor-corner {
  position: absolute;
  width: 1px;
  height: 1px;
  pointer-events: none;
  opacity: 0;
}
.floor-corner[data-corner="0"] { left: 0; top: 0; }
.floor-corner[data-corner="1"] { left: 100%; top: 0; }
.floor-corner[data-corner="2"] { left: 100%; top: 100%; }
.floor-corner[data-corner="3"] { left: 0; top: 100%; }

.room-wall {
  position: absolute;
  pointer-events: none;
  transform-style: preserve-3d;
  background: #323846;
  border: 1px solid rgba(255,255,255,0.08);
}
.room-wall-back {
  left: 0; top: 0;
  width: 360px; height: 120px;
  transform-origin: top center;
  transform: rotateX(90deg);
  background: #3a4250;
}
.room-wall-left {
  left: 0; top: 0;
  width: 120px; height: 360px;
  transform-origin: left center;
  transform: rotateY(-90deg);
  background: #2f3644;
}
.room-wall-right {
  right: 0; top: 0;
  width: 120px; height: 360px;
  transform-origin: right center;
  transform: rotateY(90deg);
  background: #2f3644;
}

/* ── 3D translucent exit door (door row = bottom edge; stands ABOVE floor) ── */
#room-door {
  --door-w: 88px;
  --door-h: 108px;
  position: absolute;
  left: 50%;
  top: auto;
  bottom: 0;
  width: var(--door-w);
  height: 12px;
  margin-left: calc(var(--door-w) / -2);
  transform-style: preserve-3d;
  pointer-events: none;
  z-index: 18;
}
#room-door .door-threshold {
  position: absolute;
  left: -2px;
  right: -2px;
  bottom: 0;
  height: 12px;
  background: rgba(120, 72, 36, 0.55);
  border-radius: 2px;
  transform: translateZ(1.5px);
}
/* Stand up from floor into +Z (same side as furniture), not under the pane */
#room-door .door-frame {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--door-h);
  transform-style: preserve-3d;
  transform-origin: bottom center;
  transform: rotateX(-90deg);
}
/* No gray outer frame — thin brown edge only */
#room-door .door-jamb,
#room-door .door-lintel {
  display: none;
}
#room-door .door-panel {
  position: absolute;
  inset: 0;
  border-radius: 3px 3px 1px 1px;
  background: rgba(139, 90, 43, 0.42);
  border: 2px solid #6b3f1a;
  overflow: hidden;
  transform-style: preserve-3d;
}
#room-door .door-glass {
  position: absolute;
  inset: 10px;
  border-radius: 2px;
  background: rgba(180, 130, 70, 0.22);
  border: 1px solid rgba(90, 50, 20, 0.35);
}
#room-door .door-mullion {
  position: absolute;
  background: rgba(90, 50, 20, 0.55);
  z-index: 1;
}
#room-door .door-mullion-h {
  left: 12px;
  right: 12px;
  top: 50%;
  height: 2px;
  margin-top: -1px;
}
#room-door .door-mullion-v {
  top: 12px;
  bottom: 12px;
  left: 50%;
  width: 2px;
  margin-left: -1px;
}
#room-door .door-handle {
  position: absolute;
  right: 12px;
  top: 52%;
  width: 5px;
  height: 14px;
  border-radius: 3px;
  background: #c9a227;
  z-index: 2;
}
#room-door .door-label {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%) translateZ(calc(var(--door-h) + 4px));
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #fff8f0;
  background: #8b5a2b;
  border-radius: 999px;
  padding: 1px 6px;
  white-space: nowrap;
}

#game-action-layer {
  position: absolute;
  bottom: 20px; right: 20px;
  z-index: 40;
}

/* placed-item 3D styles live in css/furniture3d.css */

/* ── EVENT ── */
#screen-event { background: rgba(10,10,12,0.96); z-index: 100; }
.event-modal {
  background: #1e1e24;
  border: 2px solid #e94560;
  border-radius: 16px;
  padding: 2.5rem;
  max-width: 550px;
  width: 100%;
  box-shadow: 0 20px 40px rgba(0,0,0,0.6);
}
.event-header { display: flex; align-items: center; gap: 15px; margin-bottom: 1.5rem; }
.event-header .icon { font-size: 3rem; }
.event-header h2 { font-size: 1.4rem; color: #e94560; }
.event-desc { color: #cbd5e1; line-height: 1.6; margin-bottom: 2rem; font-size: 1rem; }

.choice-container { display: flex; flex-direction: column; gap: 12px; }
.choice-btn {
  background: #27272a;
  border: 1px solid #3f3f46;
  color: #e2e8f0;
  padding: 1rem;
  border-radius: 8px;
  text-align: left;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.2s;
  line-height: 1.4;
}
.choice-btn:hover { background: #3f3f46; border-color: #f5a623; }

.reflection-box { display: none; margin-top: 1.5rem; border-top: 1px solid #3f3f46; padding-top: 1.5rem; text-align: center;}
.reflection-box p { font-style: italic; color: #a1a1aa; margin-bottom: 1rem; font-size: 0.95rem; }

/* ── END SCREEN ── */
#screen-end { background: #09090b; overflow-y: auto; justify-content: flex-start; padding-top: 3rem; }
.end-container { max-width: 650px; width: 100%; }
.end-container h2 { font-size: 2rem; color: #e94560; text-align: center; margin-bottom: 1rem; }
.no-win-msg {
  background: #1e1e24;
  border-left: 4px solid #e94560;
  padding: 1rem 1.2rem;
  margin: 1.2rem 0;
  color: #cbd5e1;
  line-height: 1.55;
  font-size: 0.95rem;
}
.no-win-msg ul {
  list-style: none;
  margin: 0.7rem 0 0;
  color: #f5a623;
}
.no-win-msg li { margin: 0.3rem 0; }
.no-win-msg .end-footer {
  margin-top: 0.8rem;
  font-weight: bold;
  color: #fff;
  font-size: 0.9rem;
}
#end-consequences {
  margin-top: 1rem;
  padding-top: 0.8rem;
  border-top: 1px solid #3f3f46;
}
#end-consequences h3 {
  font-size: 0.9rem;
  color: #f5a623;
  margin-bottom: 0.5rem;
}
.end-consequence-item {
  font-size: 0.82rem;
  color: #a1a1aa;
  margin: 0.4rem 0;
  line-height: 1.4;
  padding-left: 0.5rem;
  border-left: 2px solid #3f3f46;
}
.end-consequence-item strong {
  color: #e2e8f0;
}

.data-box-end { background: #1e1e24; border-radius: 10px; padding: 1rem; margin-top: 1rem; }
.data-grid-end { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; text-align: center; }
.data-item { background: #151518; padding: 10px; border-radius: 6px; }
.data-item .val { font-size: 1.15rem; font-weight: bold; color: #e94560; }
.data-item .lbl { font-size: 0.7rem; color: #71717a; margin-top: 2px; }
.end-actions { text-align: center; margin: 1.8rem 0 1rem; }

/* Leaderboard */
.data-section {
  background: #1e1e24;
  border-radius: 10px;
  padding: 1.2rem;
  margin-top: 1.5rem;
}
.data-section h3 { color: #e94560; margin-bottom: 1rem; font-size: 1.1rem; }
#leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: #151518;
  border-radius: 6px;
  font-size: 0.9rem;
}
.lb-row .lb-rank {
  font-weight: bold;
  color: #f5a623;
  min-width: 24px;
}
.lb-row .lb-name {
  flex: 1;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.lb-row .lb-player {
  font-weight: 600;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lb-row .lb-family {
  font-size: 0.75rem;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lb-row .lb-score {
  font-weight: bold;
  color: #e94560;
  font-size: 0.85rem;
}
.lb-loading {
  color: #71717a;
  font-size: 0.85rem;
  text-align: center;
  padding: 12px;
}

#drag-ghost { position: fixed; pointer-events: none; font-size: 2.2rem; z-index: 9999; transform: translate(-50%, -50%); display: none; }

.start-leaderboard {
  margin-top: 2rem;
  width: min(480px, 90vw);
  text-align: center;
}
.start-leaderboard h3 {
  color: #e94560;
  margin-bottom: 0.75rem;
  font-size: 1rem;
}
.start-leaderboard .lb-row {
  font-size: 0.8rem;
  padding: 6px 10px;
}
