/* This file is part of PSMemoryManager. SPDX-License-Identifier: GPL-3.0-or-later */

:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #dfe2e8;
  --text: #1d2330;
  --muted: #667085;
  --accent: #2f6fed;
  --accent-soft: #e8efff;
  --accent-text: #ffffff;
  --danger: #d92d20;
  --danger-soft: #fdecea;
  --ok: #12a150;
  --warn: #d98a00;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --row-h: 34px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161b;
    --surface: #1c1f26;
    --surface-2: #22262e;
    --border: #2e333d;
    --text: #e6e9ef;
    --muted: #9aa3b2;
    --accent: #5b8cff;
    --accent-soft: #1f2a44;
    --danger: #f97066;
    --danger-soft: #3a1f1d;
    --ok: #32d583;
    --warn: #fdb022;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14161b;
  --surface: #1c1f26;
  --surface-2: #22262e;
  --border: #2e333d;
  --text: #e6e9ef;
  --muted: #9aa3b2;
  --accent: #5b8cff;
  --accent-soft: #1f2a44;
  --danger: #f97066;
  --danger-soft: #3a1f1d;
  --ok: #32d583;
  --warn: #fdb022;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
button { font: inherit; color: inherit; }
code { font-family: ui-monospace, "Cascadia Mono", "JetBrains Mono", Consolas, monospace; font-size: .92em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

/* --- top bar --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 650; font-size: 16px; letter-spacing: -.01em; }
.badge { font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 99px; padding: 1px 8px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.engine { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.engine .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.engine.ready .dot { background: var(--ok); }
.engine.error .dot { background: var(--danger); }
/* still loading: the dot pulses until Python is ready (then it turns green) */
.engine:not(.ready):not(.error) .dot { animation: engine-pulse 1.1s ease-in-out infinite; }
@keyframes engine-pulse { 50% { opacity: .35; transform: scale(.8); } }
@media (prefers-reduced-motion: reduce) { .engine .dot { animation: none !important; } }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.lang select {
  font: inherit; font-size: 13px; color: var(--text); background: var(--surface); cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; height: 32px; padding: 0 8px;
}
.lang select:hover { background: var(--surface-2); }
.icon-btn { background: none; border: 1px solid var(--border); border-radius: 8px; width: 32px; height: 32px; display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }

/* --- toolbar --- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.toolbar .group { display: flex; gap: 2px; }
.toolbar button {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 1px solid transparent; border-radius: 7px;
  padding: 5px 9px; cursor: pointer; white-space: nowrap;
}
.toolbar button:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border); }
.toolbar button:disabled { color: var(--muted); opacity: .5; cursor: default; }
.toolbar button.primary:not(:disabled) { background: var(--accent); color: var(--accent-text); }
.toolbar button.primary:not(:disabled):hover { filter: brightness(1.07); background: var(--accent); }
.toolbar button.danger:not(:disabled):hover { color: var(--danger); background: var(--danger-soft); }
i[data-icon] { display: inline-flex; width: 18px; height: 18px; }
i[data-icon] svg { width: 100%; height: 100%; }

/* --- main area --- */
main { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 16px; }
.empty { flex: 1; display: grid; place-items: center; }
.drop-hint {
  text-align: center; max-width: 560px; width: 100%;
  padding: 40px 28px; background: var(--surface); border: 2px dashed var(--border);
  border-radius: 16px;
}
.drop-hint h1 { margin: 14px 0 6px; font-size: 22px; letter-spacing: -.01em; }
.empty-actions { display: flex; gap: 10px; justify-content: center; margin: 20px 0 22px; flex-wrap: wrap; }
.facts { list-style: none; padding: 0; margin: 0; color: var(--muted); font-size: 13px; display: grid; gap: 4px; }

.btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 16px; cursor: pointer; font-weight: 550;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }

.workspace { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.cardbar {
  display: flex; gap: 20px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; box-shadow: var(--shadow);
}
.cardbar-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.card-name { font-weight: 650; font-size: 16px; word-break: break-all; }
.dirty { color: var(--warn); font-size: 12px; font-weight: 600; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chip { font-size: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); border-radius: 99px; padding: 1px 9px; }
.chip.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.chip.warn { color: var(--warn); border-color: var(--warn); }
.capacity { min-width: 240px; flex: 0 1 340px; }
.capacity-text { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 5px; gap: 8px; }
.bar { height: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .25s; }
.bar-fill.warn { background: var(--warn); }
.bar-fill.full { background: var(--danger); }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 12px; }
.layout.dual { grid-template-columns: minmax(0, 1fr); }
.layout.has-sd { grid-template-columns: 290px minmax(0, 1fr) 300px; }
.layout.has-sd.dual { grid-template-columns: 290px minmax(0, 1fr); }

/* --- SD card sidebar --- */
.sdbar {
  min-height: 0; overflow: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 10px;
}
.sdbar > * { flex-shrink: 0; } /* scroll the bar instead of squeezing its groups */
.sd-head { display: flex; align-items: center; gap: 8px; }
.sd-head .sd-icon { width: 22px; height: 22px; color: var(--accent); flex: none; }
.sd-head .sd-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sd-head .icon-btn { margin-left: auto; }
.sd-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.sd-tools button, .sd-variant-head button {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 7px; padding: 4px 8px; cursor: pointer;
}
.sd-tools button:hover:not(:disabled), .sd-variant-head button:hover:not(:disabled) { border-color: var(--accent); }
.sd-tools button:disabled, .sd-variant-head button:disabled { opacity: .5; cursor: default; }
.sd-tools i[data-icon], .sd-variant-head i[data-icon] { width: 15px; height: 15px; }
.sd-note { font-size: 12px; color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); border-radius: 8px; padding: 6px 8px; }
.sd-variant-head { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.sd-variant-head h3 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.sd-folder { border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.sd-folder-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; background: var(--surface-2); cursor: pointer; user-select: none; }
.sd-folder-head .twisty { flex: none; }
.sd-folder-head .lbl { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sd-folder-head .count { font-size: 12px; color: var(--muted); }
.sd-folder-head .kind { width: 16px; height: 16px; flex: none; color: var(--muted); display: grid; place-items: center; }
.sd-folder-head .kind.game { color: var(--accent); }
.sd-folder-head .kind svg { width: 16px; height: 16px; }
/* code on the first line, game title below it (full width, "…" when long) */
.sd-folder-head .names { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.sd-folder-head .gname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; font-weight: 400; }
.card-list .gname, .split-game { color: var(--muted); font-size: 12.5px; }
.sd-folder-head .mini { background: none; border: none; color: var(--muted); padding: 2px; border-radius: 5px; cursor: pointer; display: grid; place-items: center; }
.sd-folder-head .mini:hover:not(:disabled) { color: var(--text); background: var(--surface); }
.sd-folder-head .mini:disabled { opacity: .4; cursor: default; }
.sd-folder-head .mini svg { width: 15px; height: 15px; }
.sd-ch { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 30px; border-top: 1px solid var(--border); cursor: pointer; }
.sd-ch:hover { background: var(--surface-2); }
.sd-ch .num { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; width: 18px; flex: none; }
.sd-ch .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sd-ch .nm.none { color: var(--muted); font-style: italic; }
.sd-ch .sz { font-size: 12px; color: var(--muted); flex: none; }
.sd-ch .open-in { font-size: 11px; font-weight: 700; color: var(--accent-text); background: var(--accent); border-radius: 5px; padding: 0 5px; flex: none; }
.sd-ch .del { visibility: hidden; background: none; border: none; color: var(--muted); cursor: pointer; padding: 2px; border-radius: 5px; display: grid; place-items: center; }
.sd-ch:hover .del, .sd-ch:focus-within .del { visibility: visible; }
/* touch screens have no hover: always show it, with a finger-sized target */
@media (hover: none) {
  .sd-ch .del { visibility: visible; min-width: 32px; min-height: 32px; margin: -6px -4px -6px 0; }
}
.sd-ch .del:hover { color: var(--danger); }
.sd-ch .del svg { width: 14px; height: 14px; }
.sd-empty { color: var(--muted); font-size: 13px; padding: 4px 2px; }
.form-grid { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; }
.form-grid > span { font-size: 13px; color: var(--text); }
.form-grid select { width: auto; min-width: 110px; }
.rows-table { display: grid; gap: 6px; max-height: 45vh; overflow: auto; }
.rows-table .r { display: grid; grid-template-columns: 76px 1fr 1fr 30px; gap: 6px; align-items: start; }
.rows-table .gcell { display: grid; gap: 2px; min-width: 0; }
.rows-table .gcell .gname { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 1em; }
.rows-table .rm { margin-top: 4px; }
dialog .warnbox { padding: 9px 12px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); font-size: 12.5px; }
dialog .notebox { padding: 9px 12px; border-radius: 8px; background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--text); font-size: 12.5px; }
.rows-table .r.h { font-size: 12px; color: var(--muted); }
.rows-table input, .rows-table select { padding: 6px 8px !important; }
.rows-table .rm { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; }
.rows-table .rm:hover { color: var(--danger); }
.names-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; }
.names-grid span { font-size: 13px; color: var(--muted); }
dialog input[type="text"].mono { font-family: ui-monospace, Consolas, monospace; }
.path-preview { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--muted); word-break: break-all; }
.layout.dual .details { display: none; }
.panes { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.layout.dual .panes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pane { min-height: 0; min-width: 0; display: flex; flex-direction: column; gap: 12px; border-radius: 12px; }
.pane > .tree-wrap { flex: 1; }
.layout.dual .pane { padding: 6px; border: 2px solid transparent; }
.layout.dual .pane.active { border-color: var(--accent); }
.pane-empty {
  flex: 1; display: grid; place-content: center; justify-items: center; text-align: center; gap: 6px;
  background: var(--surface); border: 2px dashed var(--border); border-radius: var(--radius); padding: 24px;
}
.pane-empty h2 { margin: 6px 0 0; font-size: 17px; }
.pane-empty p { margin: 0; max-width: 340px; }
.pane-empty .empty-actions { margin: 14px 0 0; }
.slot-badge {
  font-size: 11px; font-weight: 700; color: var(--accent-text); background: var(--accent);
  border-radius: 6px; padding: 1px 7px; align-self: center;
}
.layout:not(.dual) .slot-badge { display: none; }
.cardbar-title .close-card { margin-left: auto; }
.icon-btn.small { width: 26px; height: 26px; border-color: transparent; color: var(--muted); }
.icon-btn.small:hover { color: var(--text); border-color: var(--border); }
.icon-btn.small svg { width: 16px; height: 16px; }
.layout.dual .capacity { flex-basis: 100%; }
.toolbar button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.row.dragging { opacity: .5; }
.save-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 40vh; overflow: auto; }
.save-list li { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--surface-2); }
.save-list li.bad { border-color: var(--danger); color: var(--danger); }
.save-list .t { font-weight: 600; color: var(--text); }
.save-list .m { font-size: 12px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; word-break: break-all; }
.choice { display: grid; gap: 8px; }
.choice label:has(input:disabled) { opacity: .55; cursor: default; }
.card-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 34vh; overflow: auto; }
.card-list li { border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px; background: var(--surface-2); display: grid; gap: 4px; }
.card-list .t { font-weight: 600; word-break: break-all; }
.card-list .m { font-size: 12px; color: var(--muted); }
.card-list .titles { font-size: 12.5px; }
.card-list label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.card-list input[type="text"] { width: 150px; padding: 5px 8px; }
.choice label {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: start; cursor: pointer;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; color: var(--text);
}
.choice label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { grid-row: span 2; margin-top: 3px; }
.choice b { font-weight: 650; }
.choice span { font-size: 12.5px; color: var(--muted); }
.tree-wrap {
  min-height: 0; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.tree-head, .row {
  display: grid; grid-template-columns: minmax(180px, 1.2fr) minmax(120px, 1.4fr) 90px 140px;
  align-items: center;
}
.tree-head { border-bottom: 1px solid var(--border); padding: 0 8px; }
.tree-head button {
  background: none; border: none; text-align: left; padding: 9px 8px; color: var(--muted);
  font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .03em; cursor: pointer;
}
.tree-head button:hover { color: var(--text); }
.tree-head button.sorted::after { content: " ▲"; font-size: 9px; }
.tree-head button.sorted.desc::after { content: " ▼"; }
.tree-head .col-size, .row .c-size { text-align: right; }
.tree { flex: 1; overflow: auto; padding: 4px 8px 8px; outline: none; }
.tree:focus-visible { box-shadow: inset 0 0 0 2px var(--accent-soft); }
.row {
  height: var(--row-h); border-radius: 6px; cursor: default; user-select: none;
}
.row > div { padding: 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row:hover { background: var(--surface-2); }
.row.selected { background: var(--accent-soft); }
.row.focused { box-shadow: inset 0 0 0 1px var(--accent); }
.row.drop-target { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.c-name { display: flex; align-items: center; gap: 6px; }
.twisty { width: 18px; height: 18px; flex: none; display: grid; place-items: center; border-radius: 4px; color: var(--muted); cursor: pointer; transition: transform .12s; }
.twisty svg { width: 14px; height: 14px; }
.twisty.open { transform: rotate(90deg); }
.twisty.leaf { visibility: hidden; }
.ricon { width: 18px; height: 18px; flex: none; color: var(--muted); }
.ricon.save { color: var(--accent); }
.ricon svg { width: 100%; height: 100%; }
.c-name .nm { overflow: hidden; text-overflow: ellipsis; }
.lock { width: 13px; height: 13px; color: var(--warn); flex: none; }
.c-title { color: var(--text); }
.c-size, .c-date { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.tree-empty { color: var(--muted); padding: 28px; text-align: center; }

.details {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; overflow: auto; min-height: 0;
}
.details h2 { margin: 0 0 4px; font-size: 17px; line-height: 1.3; word-break: break-word; }
.details .path { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--muted); word-break: break-all; }
.details dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 14px 0 0; font-size: 13px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; word-break: break-word; }
.details .notebox { margin-top: 14px; padding: 10px 12px; border-radius: 8px; background: var(--accent-soft); color: var(--text); font-size: 12.5px; }
.details .warnbox { margin-top: 14px; padding: 10px 12px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); font-size: 12.5px; }
.details .hint { margin-top: 16px; font-size: 12.5px; color: var(--muted); }

.statusbar {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 6px 16px; font-size: 12px; border-top: 1px solid var(--border); background: var(--surface);
}

/* --- overlays --- */
.drop-overlay {
  position: fixed; inset: 0; z-index: 40; background: color-mix(in srgb, var(--accent) 14%, transparent);
  display: grid; place-items: center; pointer-events: none;
}
.drop-overlay > div {
  background: var(--surface); border: 2px dashed var(--accent); border-radius: 14px;
  padding: 18px 28px; font-weight: 650; box-shadow: var(--shadow);
}
.menu {
  position: fixed; z-index: 50; min-width: 200px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 4px; box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.menu button {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; background: none; border: none;
  padding: 7px 10px; border-radius: 6px; cursor: pointer;
}
.menu button:hover:not(:disabled) { background: var(--accent); color: var(--accent-text); }
.menu button:disabled { color: var(--muted); opacity: .55; cursor: default; }
.menu button.danger:hover:not(:disabled) { background: var(--danger); }
.menu hr { border: none; border-top: 1px solid var(--border); margin: 4px 6px; }
.menu i[data-icon] { width: 16px; height: 16px; }

.toasts { position: fixed; right: 16px; bottom: 44px; z-index: 60; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 8px; padding: 10px 14px; box-shadow: 0 6px 20px rgba(0,0,0,.15); white-space: pre-line;
  animation: toast-in .18s ease-out;
}
.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

@keyframes spin { to { transform: rotate(360deg); } }

dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text);
  width: min(460px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(10, 12, 16, .45); }
dialog form { padding: 20px; display: grid; gap: 12px; }
dialog h3 { margin: 0; font-size: 17px; }
dialog .msg { white-space: pre-line; color: var(--muted); word-break: break-word; max-height: 50vh; overflow: auto; }
dialog label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
dialog label.inline { display: flex; align-items: center; gap: 8px; color: var(--text); }
dialog input[type="text"], dialog select {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
dialog input:focus, dialog select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
dialog .err { color: var(--danger); font-size: 12.5px; min-height: 1em; }

.update-bar {
  position: fixed; left: 50%; top: 12px; transform: translateX(-50%); z-index: 65;
  display: flex; align-items: center; gap: 12px; padding: 8px 10px 8px 16px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--accent); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.update-bar .btn { padding: 6px 12px; }

/* --- responsive --- */
@media (max-width: 900px) {
  /* Stacked layout: SD list, card(s), details one below the other. Every
     block keeps its own height and the whole area scrolls, so none gets
     squeezed or covered by the next one. */
  .layout, .layout.dual, .layout.has-sd, .layout.has-sd.dual {
    grid-template-columns: 1fr; grid-template-rows: none; grid-auto-rows: auto; overflow: auto;
  }
  .layout.dual .panes { grid-template-columns: 1fr; grid-auto-rows: auto; }
  /* desktop uses min-height: 0 so panes can shrink; here they must not */
  .panes, .pane { min-height: auto; }
  .pane > .tree-wrap { flex: none; height: max(320px, 60vh); }
  .pane-empty { min-height: 260px; }
  .sdbar { height: 340px; }
  .details { min-height: auto; max-height: none; overflow: visible; }
}
@media (max-width: 640px) {
  main { padding: 10px 16px; }
  .toolbar { padding: 6px 10px; gap: 4px 8px; }
  .toolbar button span { display: none; }
  .tree-head, .row { grid-template-columns: minmax(140px, 1fr) 76px; }
  .tree-head .col-title, .tree-head .col-date, .row .c-title, .row .c-date { display: none; }
  .capacity { min-width: 0; flex: 1 1 100%; }
  .statusbar > .muted { display: none; }
  #engineText { display: none; }
  .badge { display: none; }
  .brand { min-width: 0; }
  .brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar { gap: 8px; }
  .topbar-right { gap: 6px; flex: none; }
  .lang select { max-width: 104px; }
  .brand-name { font-size: 15px; }
}

/* PS1 cards ------------------------------------------------------------- */
.ricon.ps1 { width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; color: var(--accent); }
.ps1-icon, .ps1-big { image-rendering: pixelated; image-rendering: crisp-edges; }
.ps1-icon { width: 20px; height: 20px; }
.ps1-icon.none, .ps1-big.none { display: inline-flex; width: 20px; height: 20px; }
.ps1-icon.none svg, .ps1-big.none svg { width: 100%; height: 100%; }
.row.deleted .nm, .row.deleted .c-title { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.row.deleted .ps1-icon { opacity: .45; filter: grayscale(1); }
.tag { font-size: 11px; line-height: 16px; padding: 0 6px; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); flex: none; text-decoration: none; }
.tag.del { color: var(--warn); border-color: var(--warn); }
.blockmap { display: grid; grid-template-columns: repeat(15, 1fr); gap: 3px; }
.blk { height: 18px; border-radius: 4px; font-size: 10px; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); cursor: default; user-select: none; }
.blk[data-path] { cursor: pointer; }
.blk.del { border-style: dashed; }
.blk.odd { background: repeating-linear-gradient(135deg, var(--surface-2) 0 3px, var(--border) 3px 5px); color: var(--text); }
.blk.sel { outline: 2px solid var(--text); outline-offset: 1px; }
.blk.h0, .blk.h1, .blk.h2, .blk.h3, .blk.h4, .blk.h5 { color: #fff; border-color: transparent; }
.blk.h0 { background: #2f6fed; } .blk.h1 { background: #0f9d76; } .blk.h2 { background: #c2561a; }
.blk.h3 { background: #8a4fd8; } .blk.h4 { background: #c23a6b; } .blk.h5 { background: #4b7a12; }
.ps1-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.ps1-head h2 { margin: 0; }
.ps1-big { width: 48px; height: 48px; flex: none; border-radius: 6px; background: var(--surface-2); }
.det-actions { margin-top: 12px; display: flex; gap: 8px; }

/* PS2 save icons (3D, drawn with WebGL) */
.ricon.ps2 { width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; }
.ps2-icon { width: 22px; height: 22px; }
.ps2-slot { width: 100%; max-width: 260px; aspect-ratio: 1; margin: 0 auto 12px; border-radius: 10px; background: var(--surface-2); overflow: hidden; }
.ps2-slot:not(.ready) { opacity: .5; }
.ps2-view { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.ps2-view:active { cursor: grabbing; }

/* search in the card list */
.tree-filter { position: relative; display: flex; align-items: center; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.tree-filter .filter-icon { position: absolute; left: 18px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.tree-filter .filter-icon svg { width: 100%; height: 100%; }
.tree-filter input { flex: 1; min-width: 0; padding: 6px 10px 6px 32px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); font: inherit; font-size: 13px; }
.tree-filter input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* "All saves" (SD card) */
dialog.wide { width: min(980px, calc(100vw - 32px)); max-width: none; }
.as-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 8px 0 4px; }
.as-tools .tree-filter { flex: 1; min-width: 220px; padding: 0; border: 0; }
.as-tools .tree-filter .filter-icon { left: 10px; }
.as-count { font-size: 12px; margin: 4px 0; }
.as-list { max-height: min(60vh, 560px); overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.as-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.4fr) 80px 110px; gap: 10px; align-items: center; width: 100%; padding: 7px 10px; border: 0; border-bottom: 1px solid var(--border); background: none; color: var(--text); font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.as-row:last-child { border-bottom: 0; }
.as-row:hover, .as-row:focus-visible { background: var(--surface-2); }
.as-title { display: flex; flex-direction: column; min-width: 0; }
.as-title b, .as-title small, .as-where { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.as-title b { font-weight: 600; }
.as-title small, .as-where { color: var(--muted); font-size: 12px; }
.as-size { text-align: right; font-variant-numeric: tabular-nums; }
.as-row .tag { justify-self: start; }
@media (max-width: 640px) {
  .as-row { grid-template-columns: minmax(0, 1fr) auto; }
  .as-where { grid-column: 1 / -1; grid-row: 2; }
  .as-size { display: none; }
}

/* compare two cards (side-by-side view) */
.cmp-bar { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--accent-soft); font-size: 13px; }
.cmp-bar .cmp-sum { flex: 1 1 260px; min-width: 0; }
.cmp-bar .btn.small { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; font-size: 13px; }
.cmp-bar .btn.small svg { width: 15px; height: 15px; }
.cmp { flex: none; margin-right: 6px; vertical-align: 1px; font-size: 11px; line-height: 16px; padding: 0 7px; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.cmp-only { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.cmp-newer { color: var(--ok); border-color: var(--ok); }
.cmp-older, .cmp-diff { color: var(--warn); border-color: var(--warn); }

/* --- tight spaces: narrow card panes, short screens, folded SD list ------
   Large screens keep the usual look; these only kick in when space runs out. */
.pane { container: pane / inline-size; }
.cmp.in-name { display: none; margin: 0 0 0 4px; }
/* a pane too narrow for four columns: drop the date, then the title */
@container pane (max-width: 600px) {
  .tree-head, .row { grid-template-columns: minmax(150px, 1.1fr) minmax(0, 1.4fr) 80px; }
  .tree-head .col-date, .row .c-date { display: none; }
}
@container pane (max-width: 420px) {
  .tree-head, .row { grid-template-columns: minmax(0, 1fr) 76px; }
  .tree-head .col-title, .row .c-title { display: none; }
  .cmp.in-name { display: inline-block; }
}
/* short screens (laptops, zoomed pages): less chrome, more rows */
@media (max-height: 800px) and (min-width: 641px) {
  .toolbar { padding: 5px 12px; gap: 4px 8px; }
  main { padding: 10px 12px; }
  .workspace, .layout, .panes, .pane { gap: 8px; }
  .cardbar { padding: 8px 12px; gap: 6px 16px; }
  .card-name { font-size: 15px; }
  .chips { margin-top: 4px; }
  .layout.dual .chips { flex-wrap: nowrap; overflow: hidden; mask-image: linear-gradient(to right, #000 88%, transparent); }
  .layout.dual .chips > * { flex: none; white-space: nowrap; }
  .layout.dual .cardbar-main { flex: 1 1 100%; min-width: 0; }
  .capacity-text { margin-bottom: 3px; }
  .bar { height: 7px; }
  .cmp-bar { padding: 5px 10px; gap: 4px 12px; }
  .tree-filter { padding: 4px 6px; }
  .tree-filter input { padding-top: 4px; padding-bottom: 4px; }
  .tree-filter .filter-icon { left: 16px; }
  .tree-head button { padding: 6px 8px; }
  .sdbar { padding: 10px; gap: 8px; }
}
/* short and narrower than 1400 px (laptops): the toolbar shows icons only (names stay in
   the tooltips). A 1600 or 1440 px monitor keeps the names: its page area is a bit narrower
   than the screen (scroll bar, window borders), so the cut is well below those widths */
@media (max-height: 800px) and (min-width: 641px) and (max-width: 1399px) {
  .toolbar button span { display: none; }
  .toolbar button { padding: 5px 7px; }
}
/* SD card list folded into a rail */
.layout.has-sd.sd-collapsed { grid-template-columns: 48px minmax(0, 1fr) 300px; }
.layout.has-sd.sd-collapsed.dual { grid-template-columns: 48px minmax(0, 1fr); }
.sdbar.collapsed { padding: 6px; align-items: center; }
.sd-rail { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 34px; padding: 8px 0; border: 1px solid transparent; border-radius: 8px; background: none; color: var(--muted); cursor: pointer; }
.sd-rail:hover { border-color: var(--border); background: var(--surface-2); color: var(--text); }
.sd-rail .sd-icon { width: 22px; height: 22px; color: var(--accent); }
.sd-rail svg { width: 100%; height: 100%; }
.sd-rail .twisty { width: 16px; height: 16px; }
.sd-head .sd-fold { margin-left: auto; }
.sd-head .sd-fold svg { transform: rotate(180deg); }
.sd-head .sd-fold + .icon-btn { margin-left: 0; }
@media (max-width: 900px) {
  .layout.has-sd.sd-collapsed, .layout.has-sd.sd-collapsed.dual { grid-template-columns: 1fr; }
  .layout.sd-collapsed .sdbar { height: auto; }
  .sd-rail { flex-direction: row; width: auto; padding: 6px 10px; }
}
