:root {
  --bg: #0b1120;
  --bg-elevated: #111827;
  --bg-surface: #1e293b;
  --bg-hover: #263449;
  --bg-active: #1d4ed8;
  --bg-active-soft: rgba(59, 130, 246, 0.22);
  --border: rgba(148, 163, 184, 0.18);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #2563eb;
  --danger: #f87171;
  --warning-bg: rgba(245, 158, 11, 0.16);
  --warning-text: #fcd34d;
  --canvas-bg: #060a14;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  --topbar-h: 54px;
  --sidebar-w: 356px;
  --radius: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-elevated: #ffffff;
  --bg-surface: #f8fafc;
  --bg-hover: #e2e8f0;
  --bg-active: #2563eb;
  --bg-active-soft: rgba(37, 99, 235, 0.12);
  --border: rgba(15, 23, 42, 0.12);
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #0284c7;
  --accent-strong: #2563eb;
  --canvas-bg: #e2e8f0;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.12);
  --warning-bg: rgba(245, 158, 11, 0.15);
  --warning-text: #92400e;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  overscroll-behavior: none;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100dvw;
  overflow: hidden;
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
}

/* Top Bar */
.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  padding: 4px 6px;
  border-radius: 8px;
}

.brand:hover {
  background: var(--bg-hover);
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, #38bdf8, #6366f1);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.7);
}

.brand-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
}

.container-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--bg-active-soft);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

/* Breadcrumbs */
.breadcrumbs, .breadcrumbs-mobile {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.breadcrumbs::-webkit-scrollbar,
.breadcrumbs-mobile::-webkit-scrollbar {
  display: none;
}

.crumb-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.crumb-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.crumb-btn.current {
  color: var(--text);
  font-weight: 600;
}

.crumb-sep {
  color: var(--text-muted);
  opacity: 0.5;
  font-size: 12px;
  flex-shrink: 0;
}

/* Topbar Actions */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 9px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-wrap input {
  width: 190px;
  height: 34px;
  padding: 0 28px 0 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, width 0.2s;
}

.search-wrap input:focus {
  border-color: var(--accent);
}

.clear-search {
  position: absolute;
  right: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.sort-select {
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  outline: none;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.icon-btn.spinning svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.mobile-subbar {
  display: none;
}

/* Workspace */
.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-width: 240px;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  transition: width 0.2s ease, transform 0.2s ease;
}

.app-shell.sidebar-collapsed .sidebar {
  display: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.stats-text {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.filter-pills {
  display: inline-flex;
  gap: 4px;
  background: var(--bg-surface);
  padding: 2px;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.pill {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.pill.active {
  background: var(--accent-strong);
  color: #ffffff;
}

.file-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.32) transparent;
}

.file-list::-webkit-scrollbar,
.text-content-wrap::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.file-list::-webkit-scrollbar-track,
.text-content-wrap::-webkit-scrollbar-track {
  background: transparent;
}

.file-list::-webkit-scrollbar-thumb,
.text-content-wrap::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.32);
  border-radius: 999px;
}

/* List Items */
.list-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 6px 8px 4px;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  cursor: pointer;
  user-select: none;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
  min-height: 48px;
}

.list-item:hover {
  background: var(--bg-hover);
}

.list-item.selected {
  background: var(--bg-active-soft);
  border-color: rgba(56, 189, 248, 0.5);
}

.item-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  overflow: hidden;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--accent);
}

.item-icon.folder {
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
  border-color: rgba(251, 191, 36, 0.25);
}

.item-icon.text {
  color: #34d399;
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.25);
}

.item-icon.other {
  color: var(--text-muted);
}

.item-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.item-body {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Grid View Mode */
.file-list.grid-mode .grid-files {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 8px;
  padding-top: 4px;
}

.file-list.grid-mode .list-item.file-card {
  flex-direction: column;
  align-items: stretch;
  padding: 6px;
  gap: 6px;
  background: var(--bg-surface);
  border-color: var(--border);
}

.file-list.grid-mode .list-item.file-card.selected {
  border-color: var(--accent);
  background: var(--bg-active-soft);
}

.file-list.grid-mode .list-item.file-card .item-icon {
  width: 100%;
  height: 82px;
  border-radius: 6px;
}

.file-list.grid-mode .list-item.file-card .item-name {
  font-size: 12px;
}

.empty-list {
  padding: 36px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* Preview Pane */
.preview-pane {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--canvas-bg);
  position: relative;
}

.preview-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.empty-card {
  max-width: 420px;
  text-align: center;
  color: var(--text-muted);
  padding: 28px 24px;
  border-radius: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.empty-card svg {
  color: var(--accent);
  margin-bottom: 12px;
}

.empty-card h2 {
  margin: 0 0 8px;
  font-size: 17px;
  color: var(--text);
}

.empty-card p {
  margin: 6px 0;
  font-size: 13px;
}

.hint-keys {
  font-size: 12px !important;
  opacity: 0.78;
}

.preview-active {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 48px;
  transition: opacity 0.2s, transform 0.2s;
}

.preview-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.back-btn {
  display: none;
}

.preview-meta-col {
  min-width: 0;
  flex: 1;
}

.preview-filename {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-filemeta {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.preview-controls::-webkit-scrollbar {
  display: none;
}

.control-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.tool-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
  transition: background 0.12s, border-color 0.12s;
}

.tool-btn-text {
  font-size: 12px;
  font-weight: 500;
}

.tool-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.tool-btn.active {
  background: var(--bg-active-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.tool-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.counter-pill {
  font-size: 12px;
  color: var(--text-muted);
  padding: 0 6px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Preview Stage */
.preview-stage {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.preview-loading,
.preview-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(6, 10, 20, 0.72);
  color: var(--text);
  z-index: 10;
}

.spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid rgba(148, 163, 184, 0.25);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

/* Image Viewer */
.image-viewer {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  cursor: grab;
  background:
    radial-gradient(circle at center, rgba(30, 41, 59, 0.35), transparent 70%),
    var(--canvas-bg);
}

.image-viewer.dragging {
  cursor: grabbing;
}

.image-transform-layer {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
  will-change: transform;
}

#previewImage {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.image-viewer.actual-size #previewImage {
  max-width: none;
  max-height: none;
}

.stage-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 64px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(15, 23, 42, 0.58);
  color: #f8fafc;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 0.2s, background 0.15s;
  z-index: 5;
}

.stage-nav:hover {
  background: rgba(37, 99, 235, 0.78);
}

.stage-nav-prev { left: 12px; }
.stage-nav-next { right: 12px; }

.zoom-badge {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.82);
  color: #f8fafc;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
  z-index: 6;
}

/* Text Viewer */
.text-viewer {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
}

.text-search-box {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.text-search-box input {
  width: 130px;
  height: 32px;
  padding: 0 8px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  font-size: 12px;
  outline: none;
}

.text-search-box input:focus {
  border-color: var(--accent);
}

.text-search-count {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.truncated-banner {
  padding: 8px 14px;
  font-size: 12px;
  background: var(--warning-bg);
  color: var(--warning-text);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.text-content-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.6;
  -webkit-overflow-scrolling: touch;
}

.text-gutter {
  margin: 0;
  padding: 14px 10px 14px 12px;
  text-align: right;
  user-select: none;
  color: var(--text-muted);
  opacity: 0.65;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 100%;
  font: inherit;
}

.text-content-wrap:not(.show-lines) .text-gutter {
  display: none;
}

.text-code {
  margin: 0;
  padding: 14px 16px;
  flex: 1;
  min-width: 0;
  font: inherit;
  color: var(--text);
  tab-size: 4;
  white-space: pre;
}

.text-content-wrap.wrap-on .text-code {
  white-space: pre-wrap;
  word-break: break-word;
}

.text-content-wrap.wrap-on .text-gutter {
  display: none;
}

mark.hl {
  background: rgba(250, 204, 21, 0.38);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* Other Viewer */
.other-viewer {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.other-card {
  max-width: 400px;
  width: 100%;
  text-align: center;
  padding: 28px 24px;
  border-radius: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.other-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  height: 64px;
  padding: 0 14px;
  border-radius: 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--accent);
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 12px;
}

.other-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
  word-break: break-all;
}

.other-card p {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 13px;
}

.other-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.primary-btn,
.secondary-btn {
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
}

.primary-btn {
  background: var(--accent-strong);
  color: #ffffff;
}

.secondary-btn {
  background: var(--bg-surface);
  border-color: var(--border);
  color: var(--text);
}

/* Immersive Mode (PC & Mobile & Landscape) */
.app-shell.immersive .topbar,
.app-shell.immersive .mobile-subbar,
.app-shell.immersive .sidebar {
  display: none !important;
}

.app-shell.immersive .preview-toolbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  background: rgba(11, 17, 32, 0.78);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.app-shell.immersive.chrome-hidden .preview-toolbar,
.app-shell.immersive.chrome-hidden .stage-nav {
  opacity: 0;
  pointer-events: none;
}

.preview-locked {
  flex: 1;
  min-height: 0;
  width: 100%;
  background: var(--canvas-bg);
}

/* Passcode Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.modal-card {
  width: 100%;
  max-width: 340px;
  padding: 22px 20px 18px;
  border-radius: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.modal-subtitle {
  margin: -4px 0 2px;
  font-size: 13px;
  color: var(--text-muted);
}

.modal-input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  font-size: 18px;
  letter-spacing: 4px;
  text-align: center;
  outline: none;
}

.modal-input:focus {
  border-color: var(--accent);
}

.modal-error {
  font-size: 12px;
  color: var(--danger);
  text-align: center;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.modal-actions .primary-btn,
.modal-actions .secondary-btn {
  flex: 1;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.92);
  color: #f8fafc;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: var(--shadow);
  z-index: 100;
  pointer-events: none;
}

/* =========================================================
   Mobile Portrait (iPhone 16: ~393x852 CSS px, <= 768px)
   ========================================================= */
@media (max-width: 768px) and (orientation: portrait) {
  .topbar {
    height: auto;
    min-height: 0;
    flex-wrap: wrap;
    padding: 8px 10px;
    gap: 6px;
  }

  .topbar-left {
    flex: 1 1 auto;
    order: 1;
  }

  .sidebar-toggle,
  .topbar .breadcrumbs,
  .container-badge {
    display: none;
  }

  .brand-title {
    font-size: 15px;
  }

  .topbar-actions {
    display: contents;
  }

  .topbar-actions .icon-btn {
    order: 1;
    width: 34px;
    height: 34px;
  }

  .search-wrap {
    order: 2;
    flex: 1 1 calc(100% - 118px);
    min-width: 0;
  }

  .search-wrap input {
    width: 100%;
    height: 36px;
    font-size: 14px;
  }

  .sort-select {
    order: 2;
    height: 36px;
    width: 108px;
    flex-shrink: 0;
    font-size: 12px;
    padding: 0 6px;
  }

  .mobile-subbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  .stats-pill {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
  }

  .sidebar {
    width: 100%;
    max-width: none;
    border-right: none;
  }

  .sidebar-header .stats-text {
    display: none;
  }

  .sidebar-header {
    justify-content: center;
    padding: 6px 10px;
  }

  .filter-pills {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .pill {
    padding: 6px 8px;
    font-size: 13px;
  }

  .list-item {
    min-height: 54px;
    padding: 10px;
  }

  .preview-pane {
    position: fixed;
    inset: 0;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    z-index: 40;
    transform: translateX(100%);
    transition: transform 0.22s ease;
  }

  .app-shell.mobile-preview-open .preview-pane {
    transform: translateX(0);
  }

  .back-btn {
    display: inline-flex;
  }

  .preview-toolbar {
    flex-wrap: wrap;
    padding: 8px 10px;
    gap: 6px;
  }

  .preview-title-group {
    width: 100%;
  }

  .preview-controls {
    width: 100%;
    justify-content: space-between;
    gap: 4px;
  }

  .control-group {
    gap: 3px;
  }

  .tool-btn {
    min-width: 29px;
    height: 32px;
    padding: 0 5px;
    font-size: 13px;
  }

  .tool-btn-text {
    font-size: 11px;
    padding: 0 6px;
  }

  .counter-pill {
    font-size: 11px;
    padding: 0 3px;
  }

  .text-search-box input {
    width: 84px;
    height: 32px;
  }

  .stage-nav {
    width: 34px;
    height: 52px;
    font-size: 24px;
  }
}

/* =========================================================
   Mobile Landscape (iPhone 16 横屏: ~852x393 CSS px)
   Dedicated compact widescreen split & immersive layout
   ========================================================= */
@media (orientation: landscape) and (max-height: 540px) {
  :root {
    --topbar-h: 40px;
    --sidebar-w: 248px;
  }

  .topbar {
    padding: 0 8px;
    gap: 6px;
  }

  .brand-title {
    font-size: 13px;
  }

  .container-badge {
    display: none;
  }

  .search-wrap input {
    width: 130px;
    height: 30px;
    font-size: 12px;
    padding: 0 24px 0 26px;
  }

  .sort-select {
    height: 30px;
    font-size: 12px;
    padding: 0 6px;
  }

  .icon-btn {
    width: 30px;
    height: 30px;
  }

  .mobile-subbar {
    display: none !important;
  }

  .sidebar {
    width: var(--sidebar-w);
    min-width: 210px;
  }

  .sidebar-header {
    padding: 4px 8px;
  }

  .stats-text {
    font-size: 11px;
  }

  .file-list {
    padding: 4px 6px;
  }

  .list-item {
    min-height: 40px;
    padding: 6px 8px;
    gap: 8px;
  }

  .item-icon {
    width: 28px;
    height: 28px;
    font-size: 10px;
  }

  .item-name {
    font-size: 12px;
  }

  .item-meta {
    font-size: 10px;
  }

  .preview-toolbar {
    min-height: 38px;
    padding: 4px 8px;
    gap: 6px;
  }

  .preview-filename {
    font-size: 12px;
  }

  .preview-filemeta {
    font-size: 10px;
  }

  .tool-btn {
    min-width: 28px;
    height: 28px;
    padding: 0 6px;
    font-size: 13px;
  }

  .tool-btn-text {
    font-size: 11px;
  }

  .text-search-box input {
    width: 96px;
    height: 28px;
  }

  .stage-nav {
    width: 34px;
    height: 50px;
    font-size: 22px;
  }

  .empty-card {
    padding: 16px 18px;
  }

  .empty-card svg {
    width: 32px;
    height: 32px;
    margin-bottom: 6px;
  }

  .empty-card h2 {
    font-size: 15px;
  }

  .hint-keys {
    display: none;
  }

  .modal-card {
    max-width: 320px;
    padding: 14px 16px;
    gap: 8px;
  }

  .modal-input {
    height: 38px;
    font-size: 16px;
  }
}

/* Tablet range */
@media (min-width: 769px) and (max-width: 1080px) {
  :root {
    --sidebar-w: 290px;
  }

  .search-wrap input {
    width: 145px;
  }
}
