/* ==========================================================================
   任天堂加強版 ‧ 極簡黑白剪影專業設計系統 (Minimalist Monochrome Icons)
   零廢話、純符號、防截斷、極致專業
   ========================================================================== */

:root {
  --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC", sans-serif;
  --font-mono: "SF Mono", "Menlo", "Consolas", monospace;

  /* 深邃曜石黑主題 */
  --bg-app: #08090b;
  --bg-viewport: #000000;
  --bg-panel: rgba(18, 20, 26, 0.88);
  --bg-hover: rgba(255, 255, 255, 0.1);
  --bg-active: rgba(255, 255, 255, 0.18);
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: rgba(255, 255, 255, 0.16);
  --border-focus: #0A84FF;

  --color-accent: #0A84FF;
  --color-green: #30D158;
  --color-red: #FF453A;

  --text-primary: #FFFFFF;
  --text-secondary: rgba(255, 255, 255, 0.65);
  --text-muted: rgba(255, 255, 255, 0.35);

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-window: 0 16px 40px rgba(0, 0, 0, 0.65);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

html, body {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden !important;
  font-family: var(--font-family);
  background: var(--bg-app);
  color: var(--text-primary);
}

/* ==========================================================================
   頂部動態通知島
   ========================================================================== */
.island-container {
  position: fixed;
  top: 8px;
  left: clamp(280px, 25vw, 380px);
  transform: translateX(-50%);
  z-index: 10000;
  pointer-events: none;
}

.dynamic-island {
  pointer-events: auto;
  background: rgba(14, 16, 22, 0.95);
  border: 1px solid var(--border-medium);
  border-radius: 18px;
  min-width: 140px;
  height: 32px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(20px);
  transition: all 0.25s ease;
}

.dynamic-island.expanded {
  min-width: 280px;
  height: 38px;
  border-color: var(--color-accent);
}

.island-icon { font-size: 0.95rem; }
.island-text { font-size: 0.78rem; font-weight: 500; white-space: nowrap; }
.island-badge {
  font-size: 0.68rem;
  padding: 1px 6px;
  background: rgba(48, 209, 88, 0.18);
  color: var(--color-green);
  border-radius: 6px;
  font-weight: 600;
}

/* ==========================================================================
   主佈局 (全自適應、絕無破版擠壓)
   ========================================================================== */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  padding: 10px;
  gap: 10px;
  box-sizing: border-box;
}

/* ==========================================================================
   遊戲主舞台
   ========================================================================== */
.game-viewport {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #0d0f14;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-window);
  overflow: hidden;
  position: relative;
}

/* 頂部極簡符號工具列 */
.viewport-header {
  height: 44px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(14, 16, 22, 0.7);
  backdrop-filter: blur(16px);
  flex-shrink: 0;
  gap: 8px;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  overflow: hidden;
}

.app-icon {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.app-icon svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.title-rom-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 黑白剪影純符號按鈕列 */
.toolbar-groups {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.tool-group {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 1px;
}

/* 純黑白剪影 Icon 按鈕 */
.icon-btn {
  width: 32px;
  height: 28px;
  background: transparent;
  border: none;
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  position: relative;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.icon-btn:active {
  background: var(--bg-active);
  transform: scale(0.95);
}

.icon-btn.primary {
  background: var(--color-accent);
  color: #ffffff;
}

.icon-btn.primary:hover {
  background: #2591FF;
}

.icon-btn.active {
  color: var(--color-accent);
  background: rgba(10, 132, 255, 0.15);
}

/* 縮放選擇器 */
.scale-select {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.74rem;
  font-family: var(--font-mono);
  padding: 0 4px;
  height: 28px;
  outline: none;
  cursor: pointer;
}

.scale-select option {
  background: #12141a;
  color: #fff;
}

.scale-select:hover {
  color: var(--text-primary);
}

/* 遊戲畫面舞台 */
.canvas-wrapper {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000000;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

#nes-canvas,
canvas,
.canvas-wrapper canvas {
  width: auto !important;
  height: auto !important;
  max-width: 100% !important;
  max-height: 100% !important;
  aspect-ratio: 4 / 3 !important;
  object-fit: contain !important;
  margin: auto !important;
  display: block !important;
  image-rendering: -webkit-optimize-contrast !important;
  image-rendering: crisp-edges !important;
  image-rendering: pixelated !important;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  user-select: none;
  -webkit-user-select: none;
}

#nes-canvas:focus,
#nes-canvas:focus-visible,
canvas:focus,
canvas:focus-visible,
.canvas-wrapper canvas:focus,
.canvas-wrapper canvas:focus-visible {
  outline: none !important;
  border: none !important;
  box-shadow: none !important;
}

.canvas-wrapper.crt::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.35) 50%);
  background-size: 100% 3px;
  pointer-events: none;
}

/* 拖曳 ROM 提示 */
.drop-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(8, 10, 14, 0.92);
  backdrop-filter: blur(16px);
  cursor: pointer;
  z-index: 20;
}

.drop-overlay.dragover {
  background: rgba(10, 132, 255, 0.15);
  border: 2px dashed var(--color-accent);
}

.drop-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
}

.drop-icon svg { width: 24px; height: 24px; fill: var(--text-secondary); }

.drop-badge {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 4px 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-medium);
  border-radius: 20px;
  color: var(--text-secondary);
}

/* 底部極簡細長條狀態列 */
.viewport-footer {
  height: 28px;
  padding: 0 12px;
  background: rgba(10, 12, 16, 0.85);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-mono);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #444;
}

.status-dot.active {
  background: var(--color-green);
  box-shadow: 0 0 6px var(--color-green);
}

/* ==========================================================================
   右側修改大師控制台 (Inspector Panel)
   ========================================================================== */
.modifier-panel {
  width: 380px;
  max-width: 380px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  backdrop-filter: blur(24px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-window);
  overflow: hidden;
  transition: all 0.25s ease;
  flex-shrink: 0;
}

.app-container.sidebar-collapsed .modifier-panel {
  display: none !important;
}

/* 四大純符號 Tab Bar */
.panel-tab-bar {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(10, 12, 16, 0.6);
  flex-shrink: 0;
}

.panel-tab-bar .tab-group {
  display: flex;
  background: rgba(0, 0, 0, 0.4);
  padding: 2px;
  border-radius: var(--radius-sm);
  gap: 2px;
}

.tab-btn {
  flex: 1;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-xs);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.tab-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.tab-btn:hover { color: var(--text-primary); }

.tab-btn.active {
  background: var(--bg-active);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

/* 內容容器 */
.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 卡片容器 */
.console-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 搜尋控制行：完全防擠壓 */
.search-bar-row {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 4px;
}

.search-bar-row:focus-within {
  border-color: var(--color-accent);
}

.search-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 0.85rem;
  padding: 0 8px;
  font-family: var(--font-mono);
  outline: none;
}

.search-select {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text-secondary);
  font-size: 0.72rem;
  padding: 0 4px;
  height: 26px;
  border-radius: var(--radius-xs);
  outline: none;
  cursor: pointer;
  flex-shrink: 0;
}

/* 純符號微型操作鈕 */
.symbol-btn {
  width: 28px;
  height: 26px;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text-primary);
  border-radius: var(--radius-xs);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.symbol-btn svg { width: 14px; height: 14px; fill: currentColor; }

.symbol-btn:hover { background: rgba(255, 255, 255, 0.18); }
.symbol-btn:active { transform: scale(0.92); }

.symbol-btn.primary {
  background: var(--color-accent);
  color: #fff;
}
.symbol-btn.primary:hover { background: #2591FF; }

/* 三鍵變動純符號欄 */
.fuzzy-trio-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

.fuzzy-btn {
  height: 26px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.fuzzy-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

/* 專業資料表格 (DataGrid) */
.data-table {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.3);
  overflow: hidden;
  max-height: 320px;
}

.data-table-head {
  display: grid;
  grid-template-columns: 68px 56px 1fr 36px;
  padding: 5px 8px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 600;
}

.data-table-body {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.data-row {
  display: grid;
  grid-template-columns: 68px 56px 1fr 36px;
  padding: 5px 8px;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  font-size: 0.74rem;
  transition: background 0.12s ease;
}

.data-row:hover { background: rgba(255, 255, 255, 0.04); }

.cell-addr {
  font-family: var(--font-mono);
  color: var(--color-accent);
  font-weight: 600;
}

.cell-val {
  font-family: var(--font-mono);
  color: #fff;
}

.cell-edit {
  display: flex;
  align-items: center;
  gap: 3px;
}

.mini-input {
  width: 50px;
  height: 22px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-subtle);
  border-radius: 3px;
  color: #fff;
  font-size: 0.72rem;
  text-align: center;
  font-family: var(--font-mono);
  outline: none;
}

.mini-btn {
  width: 22px;
  height: 22px;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: #fff;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mini-btn svg { width: 12px; height: 12px; fill: currentColor; }

.mini-btn:hover { background: rgba(255, 255, 255, 0.2); }
.mini-btn.primary { background: var(--color-accent); }

/* 鎖定清單行 */
.lock-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
}

.lock-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.lock-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 微型開關 */
.mini-switch {
  position: relative;
  width: 32px;
  height: 18px;
}
.mini-switch input { opacity: 0; width: 0; height: 0; }
.mini-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 18px;
  transition: .2s ease;
}
.mini-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background: white;
  border-radius: 50%;
  transition: .2s ease;
}
.mini-switch input:checked + .mini-slider { background: var(--color-green); }
.mini-switch input:checked + .mini-slider:before { transform: translateX(14px); }

/* Hex 熱圖 */
.hex-table {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  gap: 2px;
  background: rgba(0, 0, 0, 0.4);
  padding: 6px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-subtle);
}

.hex-cell {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  text-align: center;
  padding: 3px 0;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 2px;
  color: var(--text-muted);
  cursor: pointer;
}

.hex-cell:hover { background: rgba(255, 255, 255, 0.15); color: #fff; }
.hex-cell.pulsing { background: rgba(10, 132, 255, 0.45); color: #fff; font-weight: 700; }

/* 存檔卡片網格 */
.save-slots-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.slot-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.slot-box:hover { border-color: var(--border-medium); }

.slot-img {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.68rem;
  overflow: hidden;
}

.slot-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
