/* =========================================================
   THE CHRONO POST — 1998 Diegetic Post Office Desk UI
   ========================================================= */

:root {
  --wood-darkest: #140c08;
  --wood-dark: #231712;
  --wood-mid: #332118;
  --wood-light: #4a3123;
  --wood-rim: #5d3e2c;

  --paper-aged: #efe6d5;
  --paper-cream: #f5eedc;
  --paper-warm: #e4d5b7;
  --paper-future: #dde3e6;

  --brass: #b8860b;
  --brass-bright: #d4a238;
  --brass-dark: #7a5807;

  --ink: #2b2118;
  --ink-muted: #6b5846;
  --wax-red: #8b261d;
  --wax-red-bright: #a83226;
  --moss-green: #2c5234;

  --font-serif: "Lora", Georgia, serif;
  --font-mono: "IBM Plex Mono", "Courier New", monospace;
  --font-stamp: "Lora", Georgia, serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Custom vintage scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: rgba(20, 12, 8, 0.45);
}
::-webkit-scrollbar-thumb {
  background: #6e4e35;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--brass);
}

body {
  font-family: var(--font-serif);
  background: radial-gradient(circle at 50% 35%, #2a1b14 0%, #160e0a 75%, #0e0805 100%);
  color: var(--paper-aged);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Viền tối nhẹ 4 góc màn hình (Atmosphere Vignette) */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 48%, transparent 56%, rgba(6, 3, 1, 0.52) 100%);
  z-index: 45;
}

/* =========================================================
   1. HEADER — NẸP GỖ SẪM & THẺ ĐỒNG THAU
   ========================================================= */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: linear-gradient(180deg, #322017 0%, #231712 58%, #1a100c 100%);
  border-bottom: 2px solid var(--brass-dark);
  box-shadow:
    inset 0 1px 0 rgba(255, 224, 150, 0.14),
    0 4px 12px rgba(0, 0, 0, 0.65);
  z-index: 20;
  flex-shrink: 0;
}

.hud-title {
  font-family: var(--font-stamp);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #f3dfb6;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.hud-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 12.5px;
}

.stat {
  font-family: var(--font-mono);
  background: linear-gradient(180deg, #3d291a 0%, #291b11 100%);
  border: 1px solid #8c6514;
  border-radius: 3px;
  padding: 4px 9px;
  color: #dccbb0;
  box-shadow:
    inset 0 1px 0 rgba(255, 224, 150, 0.18),
    inset 0 -1px 2px rgba(0, 0, 0, 0.5),
    0 2px 4px rgba(0, 0, 0, 0.45);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.stat strong {
  color: #f4cf75;
  font-weight: 700;
}

.stat-steam .hud-icon {
  color: #9dd4e8;
  filter: drop-shadow(0 0 3px rgba(157, 212, 232, 0.45));
}

.hud-actions,
.modal-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* =========================================================
   BUTTONS & BADGES (ĐỒNG THAU, DA & SÁP NIÊM PHONG)
   ========================================================= */
.btn {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 12.5px;
  color: #f3e8d2;
  background: linear-gradient(180deg, #4b3324 0%, #332117 100%);
  border: 1px solid #7d5b3a;
  border-radius: 3px;
  padding: 6px 11px;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 232, 185, 0.18),
    0 2px 4px rgba(0, 0, 0, 0.45);
  transition: transform 0.08s ease, filter 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.12);
  border-color: var(--brass-bright);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, #8c6010 0%, #5e3e06 100%);
  border-color: #d4a238;
  color: #fdf6e3;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
}

.btn-primary:disabled {
  opacity: 0.72;
  background: linear-gradient(180deg, #5e4312 0%, #3d2a09 100%);
  border-color: #946f24;
  color: #efe2c4;
}

.btn-warn {
  background: linear-gradient(180deg, #a6621c 0%, #7a420d 100%);
  border-color: #cf8534;
  color: #fdf2dc;
}

.btn-danger {
  background: linear-gradient(180deg, var(--wax-red-bright) 0%, var(--wax-red) 100%);
  border-color: #c74b3e;
  color: #fdf0ed;
}

.badge {
  display: inline-block;
  font-family: var(--font-mono);
  padding: 2px 6px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  border-radius: 2px;
  background: #3a271c;
  border: 1px solid #6e4e35;
  color: #efe6d5;
}

.badge-brass {
  background: linear-gradient(180deg, #7a540b 0%, #523605 100%);
  border-color: #d9ac3e;
  color: #fdf6e3;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.8);
}

.badge-warn {
  background: var(--wax-red);
  border-color: #b83b30;
  color: #fdf0ed;
}

.muted {
  color: #b7a289;
  font-size: 12.5px;
}

/* =========================================================
   2. WORKSPACE GRID (GỌN TRONG 100VH)
   ========================================================= */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 295px 1fr 305px;
  gap: 12px;
  padding: 10px 14px;
  background:
    radial-gradient(ellipse at center, rgba(58, 38, 25, 0.25) 0%, rgba(14, 8, 5, 0.75) 100%);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.box {
  background: linear-gradient(180deg, #2d1e16 0%, #231712 100%);
  border: 1px solid #593d2b;
  border-radius: 5px;
  padding: 10px 12px;
  box-shadow:
    inset 0 1px 0 rgba(255, 224, 170, 0.08),
    0 4px 10px rgba(0, 0, 0, 0.55);
}

.box h2 {
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-bottom: 6px;
  color: #f0dfc0;
  border-bottom: 1px solid rgba(184, 134, 11, 0.35);
  padding-bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.box h3 {
  font-family: var(--font-serif);
  font-size: 12.5px;
  font-weight: 700;
  margin: 6px 0 3px;
  color: #5c4028;
}

/* =========================================================
   3. CỘT TRÁI — KHAY GỖ & SỔ TAY BÌA DA
   ========================================================= */
.panel-left {
  position: relative;
}

/* Khay gỗ đựng hồ sơ nhìn từ trên xuống */
.tray-box {
  background: linear-gradient(180deg, #221610 0%, #170e0a 100%);
  border: 3px solid #4d3323;
  box-shadow:
    inset 0 8px 18px rgba(0, 0, 0, 0.88),
    inset 0 0 0 1px rgba(184, 134, 11, 0.22),
    0 5px 12px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  flex: 1.05;
  min-height: 0;
}

.tray-count-pill {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--brass-bright);
}

.tray-hint {
  font-size: 11.5px;
  margin-bottom: 6px;
  color: #a99278;
}

.tray-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow-y: auto;
  padding: 2px 4px 4px 2px;
  flex: 1;
  min-height: 0;
}

/* Xấp giấy/hồ sơ xếp chồng trong khay */
.tray-item {
  position: relative;
  background: linear-gradient(135deg, var(--paper-cream) 0%, var(--paper-aged) 100%);
  color: var(--ink);
  border: 1px solid #b9a482;
  border-left: 5px solid #8a6b48;
  border-radius: 2px;
  padding: 7px 9px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12.5px;
  box-shadow:
    2px 2px 0 #cbb897,
    3px 4px 7px rgba(0, 0, 0, 0.55);
  transition: transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.tray-item:nth-child(even) {
  transform: rotate(-0.4deg);
}

.tray-item:nth-child(odd) {
  transform: rotate(0.35deg);
}

.tray-item:hover {
  transform: translateY(-1px) rotate(0deg);
  border-color: var(--brass);
  box-shadow:
    2px 2px 0 #d4be96,
    0 0 10px rgba(212, 162, 56, 0.35);
}

.tray-item.active {
  transform: translateX(3px) rotate(0deg);
  background: linear-gradient(135deg, #fbf4e4 0%, #f1e3c4 100%);
  border-color: var(--wax-red);
  border-left-color: var(--wax-red);
  box-shadow:
    0 0 0 2px rgba(184, 134, 11, 0.45),
    3px 5px 10px rgba(0, 0, 0, 0.65);
}

.tray-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.tray-item .badge {
  background: #3d2c1e;
  border-color: #6b5039;
  color: #f5eedc;
  font-size: 10px;
}

.tray-item .muted {
  color: var(--ink-muted);
  font-size: 11.5px;
  font-family: var(--font-mono);
}

/* Sổ tay bìa da mở sẵn */
.notebook-box {
  background: linear-gradient(160deg, #472a1b 0%, #2c1910 100%);
  border: 2px solid #633d27;
  border-radius: 6px;
  padding: 9px 10px 10px;
  box-shadow:
    inset 0 1px 0 rgba(255, 220, 175, 0.15),
    inset 0 -3px 8px rgba(0, 0, 0, 0.6),
    0 6px 14px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.notebook-box h2 {
  color: #f3dfb6;
  border-bottom-color: rgba(212, 162, 56, 0.35);
  margin-bottom: 6px;
  font-size: 13.5px;
}

.notebook-pages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background-color: #f4ebd8;
  background-image:
    linear-gradient(90deg, transparent 22px, rgba(168, 50, 38, 0.25) 22px, rgba(168, 50, 38, 0.25) 23px, transparent 23px),
    repeating-linear-gradient(
      to bottom,
      transparent 0px,
      transparent 20px,
      rgba(120, 92, 62, 0.2) 21px
    );
  color: var(--ink);
  border-radius: 3px;
  border: 1px solid #cbb795;
  padding: 6px 10px 10px 28px;
  box-shadow:
    inset 4px 0 10px rgba(60, 36, 18, 0.18),
    0 2px 5px rgba(0, 0, 0, 0.4);
}

.notebook-pages .simple-list {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 21px;
  color: var(--ink);
  gap: 0;
}

.notebook-pages .muted {
  color: var(--ink-muted);
  font-style: italic;
  font-size: 11.5px;
}

/* Debug panel ẩn mặc định + nút kín đáo */
.debug-box {
  background: #1a110c;
  border: 1px dashed #6b4e35;
  max-height: 120px;
  overflow-y: auto;
  flex-shrink: 0;
}

.debug-box .simple-list {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: #dccbb0;
}

.debug-toggle-btn {
  align-self: flex-start;
  background: transparent;
  border: 1px solid rgba(184, 134, 11, 0.25);
  color: #8b765d;
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 2px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.debug-toggle-btn:hover {
  color: var(--brass-bright);
  border-color: var(--brass);
}

/* =========================================================
   4. CỘT GIỮA — 3 CÔNG CỤ KIM LOẠI & DA + MẶT BÀN GỖ
   ========================================================= */
.tools-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  flex-shrink: 0;
  z-index: 15;
}

.tool-zone {
  position: relative;
  background: linear-gradient(180deg, #3b271c 0%, #261811 100%);
  border: 1px solid #7d5b32;
  border-bottom: 2px solid #4d341f;
  border-radius: 4px;
  padding: 7px 10px;
  min-height: 46px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  box-shadow:
    inset 0 1px 0 rgba(255, 224, 155, 0.18),
    0 3px 6px rgba(0, 0, 0, 0.55);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
  cursor: default;
}

/* Đinh tán đồng ở góc thẻ công cụ */
.tool-zone::before,
.tool-zone::after {
  content: "";
  position: absolute;
  top: 5px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: radial-gradient(circle, #e5be5c 0%, #7d590a 100%);
  opacity: 0.75;
}
.tool-zone::before { left: 5px; }
.tool-zone::after { right: 5px; }

.tool-badge-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 4px;
}

.tool-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #5c3f28 0%, #24170f 100%);
  border: 1px solid var(--brass);
  color: #f2cf7e;
  flex-shrink: 0;
}

.tool-title {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: #f0dfc0;
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.tool-tag {
  font-size: 9.5px;
  padding: 1px 4px;
  border-radius: 2px;
  background: rgba(184, 134, 11, 0.22);
  border: 1px solid rgba(212, 162, 56, 0.45);
  color: #f4cf75;
}

.tool-zone.drag-over,
.tool-zone:hover {
  border-color: var(--brass-bright);
  box-shadow:
    inset 0 1px 0 rgba(255, 224, 155, 0.28),
    0 0 14px rgba(212, 162, 56, 0.32);
}

.tool-lamp:hover .tool-icon,
.tool-lamp.drag-over .tool-icon {
  background: radial-gradient(circle, #fde08d 0%, #b8860b 100%);
  color: #2b1a0c;
  box-shadow: 0 0 10px rgba(254, 224, 130, 0.7);
}

/* Tooltip hướng dẫn & kết quả chỉ hiện khi hover / focus / drag-over */
.tool-desc {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  background: var(--paper-cream);
  color: var(--ink);
  border: 1px solid #9c7e54;
  border-left: 3px solid var(--brass);
  border-radius: 3px;
  padding: 6px 9px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.35;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.65);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0.14s;
  pointer-events: none;
  z-index: 40;
}

.tool-zone:hover .tool-desc,
.tool-zone.drag-over .tool-desc {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.steam-bar-wrap {
  height: 5px;
  background: #140c08;
  border: 1px solid #593d2b;
  border-radius: 3px;
  overflow: hidden;
  margin: 1px 4px 0;
}

.steam-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #74b9d4 0%, #d8f1fa 100%);
  transition: width 0.05s linear;
}

/* Mặt bàn gỗ làm việc */
.desk-stage {
  position: relative;
  overflow: hidden;
  flex: 1;
  min-height: 0;
  background-color: #3d2817;
  background-image: url("Model_Props 2D/coated_pine_diff_2k.jpg");
  background-size: cover;
  background-position: center;
  box-shadow:
    inset 0 0 120px rgba(0, 0, 0, 0.82),
    inset 0 2px 6px rgba(0, 0, 0, 0.7),
    0 6px 16px rgba(0, 0, 0, 0.65);
  border: 3px solid #4d3321;
  border-radius: 6px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 800px;
}

.desk-stage.lamp-lit::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 45%, rgba(254, 240, 138, 0.32) 0%, rgba(254, 240, 138, 0.08) 48%, transparent 72%);
  pointer-events: none;
}

/* Ánh sáng đèn bàn vàng ấm nhẹ chiếu từ trên xuống giữa mặt bàn */
.desk-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 68% 58% at 50% 24%, rgba(255, 218, 138, 0.16) 0%, rgba(255, 195, 95, 0.05) 48%, rgba(10, 5, 2, 0.36) 100%);
  pointer-events: none;
  z-index: 2;
}

.desk-stage.shake {
  animation: desk-shake 0.14s ease-in-out;
}

@keyframes desk-shake {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-2px, 1px); }
  50% { transform: translate(2px, -1px); }
  75% { transform: translate(-1px, 2px); }
}

#empty-desk-msg {
  background: rgba(24, 15, 10, 0.72);
  border: 1px dashed rgba(212, 162, 56, 0.4);
  padding: 12px 18px;
  border-radius: 4px;
  color: #e4d5b7;
  font-style: italic;
  text-align: center;
  max-width: 380px;
}

/* =========================================================
   PHONG BÌ & BƯU THIẾP (3 NIÊN ĐẠI)
   ========================================================= */
.mail-card {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 100%;
  margin: auto;
  overflow-y: auto;
  background: var(--paper-cream);
  color: var(--ink);
  border: 2px solid #b59d79;
  border-radius: 3px;
  padding: 16px;
  cursor: grab;
  display: flex;
  flex-direction: column;
  gap: 9px;
  filter: drop-shadow(8px 14px 18px rgba(0, 0, 0, 0.72));
  transition: transform 0.12s ease, filter 0.2s ease;
  transform: rotate(-0.6deg) rotateX(var(--curl-deg, 0deg));
  z-index: 5;
}

.mail-postage-decor {
  position: absolute;
  top: 8px;
  right: 12px;
  pointer-events: none;
  z-index: 1;
}

.mail-card.is-flyer .mail-postage-decor {
  display: none;
}

.mail-card.era-past {
  background: #ead9b4;
  border-color: #a87f4f;
  color: #361e0b;
  font-family: var(--font-mono);
}

.mail-card.era-present {
  background: #f5eedc;
  border-color: #b59d79;
  color: var(--ink);
}

.mail-card.era-future {
  background: var(--paper-future);
  border-color: #7e8b91;
  color: #1f272b;
  filter: grayscale(0.28) contrast(1.06) drop-shadow(8px 14px 18px rgba(0, 0, 0, 0.72));
}

.mail-card:active {
  cursor: grabbing;
}

.mail-header {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mail-meta {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  border-bottom: 1px dashed #a89274;
  padding-bottom: 7px;
}

.mail-body {
  background: #fbf5e6;
  border: 1px solid #cbb389;
  border-left: 3px solid var(--brass);
  padding: 9px 11px;
  border-radius: 2px;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--ink);
}

.mail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.reroute-panel {
  border-top: 1px dashed #9e8767;
  padding-top: 8px;
  font-size: 12.5px;
}

.reroute-row {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.reroute-row select {
  flex: 1;
  padding: 5px 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  background: #fbf5e6;
  color: var(--ink);
  border: 1px solid #8a6e4b;
  border-radius: 2px;
}

.xray-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(24, 15, 10, 0.92);
  color: #f4cf75;
  border: 1px dashed var(--brass-bright);
  border-radius: 3px;
  padding: 8px 10px;
}

.envelope-xray-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: blur(1.6px);
  mix-blend-mode: multiply;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.envelope-xray-layer.visible {
  opacity: 0.85;
}

.xray-svg-wrap {
  width: 80px;
  height: 52px;
  flex-shrink: 0;
}

.xray-svg {
  width: 100%;
  height: 100%;
}

.xray-hint-text {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.35;
}

.stamp-overlay {
  position: absolute;
  top: 14px;
  right: 16px;
  padding: 5px 11px;
  border: 3px dashed var(--wax-red);
  color: var(--wax-red);
  font-family: var(--font-stamp);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 1px;
  transform: rotate(-11deg);
  mix-blend-mode: multiply;
  pointer-events: none;
  animation: stamp-slam 0.14s ease-out;
}

.stamp-overlay.stamp-normal {
  border-color: var(--moss-green);
  color: var(--moss-green);
}

.stamp-overlay.stamp-crooked {
  transform: rotate(-19deg) translate(2px, 3px);
}

.desk-sensory-note {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 7px 14px;
  border-radius: 6px;
  background: rgba(20, 14, 9, 0.82);
  border: 1px solid rgba(212, 168, 83, 0.42);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.55);
  text-align: center;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.45;
  color: #f6e7c8;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75);
  pointer-events: none;
  z-index: 2;
}

.desk-sensory-note.is-freezing {
  color: #e0f2fe;
  background: rgba(12, 24, 42, 0.88);
  border-color: rgba(125, 211, 252, 0.55);
}

@keyframes stamp-slam {
  0% { transform: scale(1.6) rotate(-18deg); opacity: 0.2; }
  100% { transform: scale(1) rotate(-11deg); opacity: 0.95; }
}

.steam-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.steam-puff {
  position: absolute;
  width: 90px;
  height: 90px;
  opacity: 0.35;
  animation: steam-rise 1.1s ease-out forwards;
}

@keyframes steam-rise {
  0% { transform: translateY(20px) scale(0.5) rotate(0deg); opacity: 0.38; }
  100% { transform: translateY(-130px) scale(1.4) rotate(28deg); opacity: 0; }
}

/* =========================================================
   5. CỘT PHẢI — HỘC TỦ CHIA THƯ GỖ & NGĂN KÉO RIÊNG
   ========================================================= */
.pigeonhole-box {
  background: linear-gradient(180deg, #332017 0%, #241610 100%);
  border: 3px solid #593b28;
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.65),
    0 5px 14px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  flex: 1.1;
  min-height: 0;
}

.bins-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  overflow-y: auto;
  padding-right: 2px;
}

/* Hộc gỗ lõm sâu + bảng tên đồng thau */
.town-bin {
  position: relative;
  background: linear-gradient(180deg, #120a07 0%, #1d120c 100%);
  border: 2px solid #593b28;
  border-top-color: #362216;
  border-radius: 4px;
  padding: 14px 12px;
  min-height: 76px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  box-shadow:
    inset 0 10px 18px rgba(0, 0, 0, 0.94),
    inset 0 0 0 1px rgba(184, 134, 11, 0.14),
    0 2px 0 rgba(255, 220, 170, 0.08);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.town-bin strong {
  display: inline-block;
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 700;
  color: #1f140a;
  background: linear-gradient(180deg, #d9ab43 0%, #a57814 100%);
  border: 1px solid #f0cb6e;
  border-radius: 2px;
  padding: 3px 10px;
  box-shadow:
    inset 0 1px 0 rgba(255, 245, 210, 0.45),
    0 2px 4px rgba(0, 0, 0, 0.6);
}

.town-bin .muted {
  display: none;
}

.town-bin:hover,
.town-bin.drag-over {
  border-color: var(--brass-bright);
  box-shadow:
    inset 0 8px 16px rgba(0, 0, 0, 0.85),
    0 0 16px rgba(212, 162, 56, 0.48),
    inset 0 0 14px rgba(212, 162, 56, 0.22);
}

/* Ngăn kéo riêng có tay nắm đồng */
.drawer-box {
  position: relative;
  background: linear-gradient(180deg, #2d1d15 0%, #21140e 100%);
  border: 3px solid #593b28;
  border-bottom: 6px solid #3f291c;
  padding-bottom: 22px;
  display: flex;
  flex-direction: column;
  flex: 0.9;
  min-height: 0;
  box-shadow:
    inset 0 5px 12px rgba(0, 0, 0, 0.72),
    0 8px 16px rgba(0, 0, 0, 0.65);
}

.drop-zone {
  background: #140c08;
  border: 2px dashed #7a5828;
  border-radius: 3px;
  padding: 14px 10px;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #cbb799;
  margin: 8px 0;
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.85);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.drop-zone.drag-over {
  border-color: var(--brass-bright);
  color: #f4cf75;
  box-shadow:
    inset 0 4px 10px rgba(0, 0, 0, 0.85),
    0 0 14px rgba(212, 162, 56, 0.45);
}

.drawer-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.drawer-item {
  background: var(--paper-aged);
  color: var(--ink);
  border: 1px solid #b59d79;
  border-left: 4px solid var(--brass);
  padding: 6px 8px;
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.45);
}

/* Tay nắm đồng thau ở mép dưới ngăn kéo */
.drawer-brass-handle {
  position: absolute;
  left: 50%;
  bottom: 5px;
  transform: translateX(-50%);
  width: 78px;
  height: 10px;
  border-radius: 0 0 8px 8px;
  background: linear-gradient(180deg, #e5be5c 0%, #9b7010 55%, #5c4005 100%);
  border: 1px solid #f0cb6e;
  box-shadow:
    0 3px 5px rgba(0, 0, 0, 0.75),
    inset 0 1px 0 rgba(255, 245, 210, 0.5);
  pointer-events: none;
}

.simple-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12.5px;
}

/* =========================================================
   6. MODALS — SỔ CÁI, BẢNG ĐIỀU TRA (CORKBOARD) & CA ĐÊM
   ========================================================= */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 7, 4, 0.82);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-card {
  background: linear-gradient(180deg, #f3ead6 0%, #e7d7b9 100%);
  color: var(--ink);
  border: 3px solid #593b28;
  outline: 1px solid var(--brass);
  border-radius: 4px;
  padding: 20px 22px;
  width: 440px;
  max-width: 92vw;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.85);
}

.modal-card h2 {
  font-family: var(--font-stamp);
  color: #2b1a0e;
  font-size: 18px;
  border-bottom: 2px solid #b59d79;
  padding-bottom: 6px;
}

.modal-card .muted {
  color: var(--ink-muted);
}

.ledger-lines {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  border-top: 1px dashed #8a7254;
  border-bottom: 1px dashed #8a7254;
  padding: 10px 0;
}

.ledger-row {
  display: flex;
  justify-content: space-between;
}

.ledger-total {
  font-family: var(--font-mono);
  font-size: 15px;
}

.hidden {
  display: none !important;
}

/* Pinboard — Bảng bần & hồ sơ */
.pinboard-card {
  width: 920px;
  max-width: 95vw;
  max-height: 88vh;
  overflow-y: auto;
  background: linear-gradient(180deg, #3c2618 0%, #2a1a10 100%);
  color: var(--paper-aged);
  border: 4px solid #593b28;
}

.pinboard-card h2,
.pinboard-card h3 {
  color: #f4e4c4;
  border-bottom-color: rgba(212, 162, 56, 0.35);
}

.pinboard-card .muted {
  color: #c5b197;
}

.pinboard-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.pinboard-slots {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 8px;
  align-items: center;
  background: #1a100b;
  border: 1px solid #6e4e35;
  padding: 10px;
  border-radius: 4px;
}

.pin-slot {
  font-family: var(--font-mono);
  font-size: 12px;
  background: #2b1c13;
  color: #efe6d5;
  padding: 6px 8px;
  border-radius: 3px;
  border: 1px solid #7d5b32;
}

.pinboard-feedback {
  font-family: var(--font-mono);
  font-size: 13px;
  min-height: 18px;
}

.pinboard-columns {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 14px;
}

.pinboard-clues-grid,
.pinboard-solved-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.clue-card {
  background: var(--paper-cream);
  color: var(--ink);
  border: 2px solid #b59d79;
  border-radius: 3px;
  padding: 10px;
  cursor: pointer;
  font-size: 13px;
  box-shadow: 2px 3px 6px rgba(0, 0, 0, 0.45);
}

.clue-card.selected {
  border-color: var(--brass-bright);
  background: #fbf2d4;
  box-shadow: 0 0 0 2px rgba(212, 162, 56, 0.55);
}

.clue-card.invalidated .clue-orig {
  text-decoration: line-through;
  color: var(--wax-red);
}

.clue-overwrite {
  color: var(--moss-green);
  margin-top: 4px;
  font-weight: 700;
}

.solved-card {
  background: #e6edd8;
  color: #1c2d19;
  border: 1px solid #59824f;
  border-left: 4px solid var(--moss-green);
  border-radius: 3px;
  padding: 10px;
  font-size: 13px;
}

/* Ending tones */
.ending-box {
  border-radius: 3px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.45;
  background: #efe6d5;
  color: var(--ink);
  border: 2px solid #8a6b48;
}

.ending-box.tone-good {
  background: #e6edd8;
  border-color: var(--moss-green);
}

.ending-box.tone-warn {
  background: #f5e6c8;
  border-color: #b8730b;
}

.ending-box.tone-info {
  background: #e2e8ea;
  border-color: #4f6d7a;
}

.ending-box.tone-bad {
  background: #f3dedc;
  border-color: var(--wax-red);
}

.ending-finance {
  margin-top: 6px;
  color: var(--wax-red);
  font-family: var(--font-mono);
  font-weight: 700;
}

/* =========================================================
   7. INTRO SPLASH & DOSSIER (ẢNH BÌA, MỞ ĐẦU & HƯỚNG DẪN)
   ========================================================= */
.modal-intro-backdrop {
  background:
    linear-gradient(180deg, rgba(10, 6, 4, 0.55) 0%, rgba(10, 6, 4, 0.78) 100%),
    url("Model_Props 2D/Dr.Watermark_Gemini_1796460877715.jpg") center / cover no-repeat;
}

.intro-splash {
  position: relative;
  width: min(1060px, 92vw);
  aspect-ratio: 16 / 9;
  max-height: 88vh;
  background: url("Model_Props 2D/Dr.Watermark_Gemini_1796460877715.jpg") center / cover no-repeat;
  border: 3px solid #6e4e35;
  outline: 1px solid var(--brass);
  border-radius: 6px;
  box-shadow:
    inset 0 -90px 100px rgba(8, 4, 2, 0.85),
    0 24px 60px rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 26px;
}

.intro-splash-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.btn-splash-main {
  padding: 10px 22px;
  font-size: 14.5px;
  letter-spacing: 0.4px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.75);
}

.btn-splash-skip {
  background: rgba(24, 15, 10, 0.82);
  border-color: #8a6b48;
  color: #e4d5b7;
  padding: 10px 16px;
  font-size: 13px;
}

.intro-card {
  width: 560px;
  max-width: 94vw;
}

.intro-step {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.intro-kicker {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--wax-red);
}

.intro-story {
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: rgba(255, 250, 238, 0.55);
  border: 1px solid #cbb795;
  border-left: 3px solid var(--brass);
  padding: 12px 14px;
  border-radius: 2px;
}

.intro-guide-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13.5px;
  line-height: 1.48;
  color: var(--ink);
  background: rgba(255, 250, 238, 0.55);
  border: 1px solid #cbb795;
  border-left: 3px solid var(--wax-red);
  padding: 12px 14px;
  border-radius: 2px;
}

.intro-actions {
  justify-content: flex-end;
  margin-top: 4px;
}

/* =========================================================
   8. RESPONSIVE — TỐI ƯU CHO LAPTOP NHỎ, TABLET & ĐIỆN THOẠI
   ========================================================= */
@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 255px 1fr 265px;
    gap: 10px;
    padding: 8px 10px;
  }
}

@media (max-width: 960px) {
  body {
    height: auto;
    min-height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .hud {
    flex-wrap: wrap;
    padding: 10px 12px;
    gap: 8px;
  }

  .hud-stats {
    order: 3;
    width: 100%;
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr 1fr;
    overflow: visible;
  }

  .panel-center {
    grid-column: 1 / -1;
    order: 1;
  }

  .panel-left {
    order: 2;
  }

  .panel-right {
    order: 3;
  }

  .desk-stage {
    min-height: 360px;
  }

  .tray-list {
    max-height: 280px;
  }
}

@media (max-width: 720px) {
  .hud-title {
    font-size: 14.5px;
    width: 100%;
    justify-content: center;
  }

  .hud-actions {
    width: 100%;
    justify-content: space-between;
  }

  .hud-actions .btn {
    flex: 1;
    text-align: center;
    padding: 8px 6px;
    font-size: 12px;
  }

  .hud-stats {
    gap: 6px;
  }

  .stat {
    font-size: 11.5px;
    padding: 4px 7px;
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 10px;
  }

  .panel-center {
    order: 1;
  }

  .panel-right {
    order: 2;
  }

  .panel-left {
    order: 3;
  }

  .tools-row {
    gap: 6px;
  }

  .tool-zone {
    padding: 6px 5px;
    min-height: 44px;
  }

  .tool-title {
    font-size: 10.5px;
  }

  .tool-tag {
    display: none;
  }

  .desk-stage {
    min-height: 300px;
    padding: 12px 10px;
  }

  .mail-card {
    padding: 13px;
    transform: rotate(0deg) rotateX(var(--curl-deg, 0deg));
  }

  .mail-actions .btn,
  .town-bin .btn,
  #btn-store-drawer {
    min-height: 38px;
  }

  .town-bin {
    min-height: 62px;
    padding: 10px;
  }

  .pinboard-slots {
    grid-template-columns: 1fr;
  }

  .pinboard-columns {
    grid-template-columns: 1fr;
  }

  .intro-splash {
    width: 95vw;
    aspect-ratio: auto;
    min-height: 54vh;
    padding: 16px;
  }

  .intro-splash-actions {
    flex-direction: column;
    width: 100%;
  }

  .intro-splash-actions .btn {
    width: 100%;
  }
}

/* ===== BẢN ĐỒ ĐỊA HÌNH & BÚT CHÌ ĐỎ ===== */
.notes-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.btn-mini {
  padding: 3px 8px;
  font-size: 11px;
  line-height: 1.2;
}

.map-card {
  width: min(1140px, 96vw);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.map-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(45, 34, 24, 0.08);
  border: 1px dashed rgba(120, 90, 58, 0.4);
  border-radius: 6px;
}

.map-selection-hint {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  color: #3f2b1d;
}

.map-toolbar-actions {
  display: flex;
  gap: 8px;
}

.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 14px;
  align-items: start;
  overflow-y: auto;
}

.map-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 2400 / 1792;
  background: #e8dec9;
  border: 2px solid #7d5b3b;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  user-select: none;
}

.map-stage img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  pointer-events: none;
}

.map-svg-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-hotspot-group {
  cursor: pointer;
}

.map-hotspot-hit {
  fill: transparent;
}

.map-hotspot-ring {
  fill: rgba(255, 248, 232, 0.65);
  stroke: #8f1d1d;
  stroke-width: 6;
  transition: transform 0.15s ease, fill 0.15s ease, stroke-width 0.15s ease;
}

.map-hotspot-dot {
  fill: #b42318;
}

.map-hotspot-group:hover .map-hotspot-ring {
  fill: rgba(254, 226, 226, 0.9);
  stroke-width: 9;
}

.map-hotspot-group.is-selected .map-hotspot-ring {
  fill: rgba(254, 202, 202, 0.92);
  stroke: #dc2626;
  stroke-width: 11;
}

.map-hotspot-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 32px;
  font-weight: 700;
  fill: #2d1b10;
  paint-order: stroke;
  stroke: rgba(248, 241, 225, 0.92);
  stroke-width: 10px;
  stroke-linejoin: round;
  pointer-events: none;
}

.red-pencil-line {
  fill: none;
  stroke: #c81e1e;
  stroke-width: 11;
  stroke-linecap: round;
  stroke-dasharray: 28 14;
  opacity: 0.9;
  pointer-events: none;
}

.red-pencil-line.is-solved {
  stroke-dasharray: none;
  stroke: #b91c1c;
}

.red-pencil-circle {
  fill: rgba(220, 38, 38, 0.08);
  stroke: #c81e1e;
  stroke-width: 10;
  stroke-linecap: round;
  opacity: 0.92;
  pointer-events: none;
}

.map-deductions-side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(247, 239, 222, 0.72);
  border: 1px solid rgba(132, 100, 68, 0.35);
  border-radius: 6px;
  padding: 10px 12px;
  max-height: 100%;
  overflow-y: auto;
}

.map-deductions-side h3 {
  margin: 0 0 4px;
  font-size: 14px;
}

.map-deductions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-deduction-item {
  padding: 8px 10px;
  border-radius: 5px;
  border: 1px solid rgba(132, 100, 68, 0.3);
  background: rgba(255, 252, 245, 0.7);
  font-size: 12px;
}

.map-deduction-item.is-found {
  border-color: #b91c1c;
  background: rgba(254, 242, 242, 0.92);
}

.map-deduction-item strong {
  display: block;
  margin-bottom: 3px;
  color: #7f1d1d;
}

@media (max-width: 960px) {
  .map-layout {
    grid-template-columns: 1fr;
  }
}
