* { box-sizing: border-box; margin: 0; padding: 0; }
  :root {
    --bg: #111;
    --bg2: #171717;
    --bg3: #222;
    --fg: #e7e7e7;
    --dim: #8a8a8a;
    --faint: #555;
    --accent: #7dd3c0;
    --accent2: #a7f3d0;
    --warn: #e8b842;
    --danger: #e57373;
    --border: #303030;
    --ok: #8bd48b;
    --shadow: rgba(0, 0, 0, 0.45);
    --glow-color: transparent;
    --fs-scale: 1;
  }

  /* Font size scale (S/M/L/XL) */
  html[data-size="S"]  { --fs-scale: 0.88; }
  html[data-size="M"]  { --fs-scale: 1;    }
  html[data-size="L"]  { --fs-scale: 1.15; }
  html[data-size="XL"] { --fs-scale: 1.32; }

  /* Themes (calm = default, plus 5 neon variants) */
  html[data-theme="green"]  { --accent:#39ff77; --accent2:#ffb000; --glow-color:#39ff77; }
  html[data-theme="amber"]  { --accent:#ffb000; --accent2:#ff26b3; --glow-color:#ffb000; }
  html[data-theme="red"]    { --accent:#ffc0b8; --accent2:#39ff77; --glow-color:#ff2020; }
  html[data-theme="pink"]   { --accent:#ffc8f0; --accent2:#39ff77; --glow-color:#ff26b3; }
  html[data-theme="cyber"]  { --accent:#B2FFCA; --accent2:#ff26b3; --glow-color:#39ff77; }

  /* Glow effects only on neon themes */
  html[data-theme] .brand,
  html[data-theme] .prompt,
  html[data-theme] #shell-prompt-symbol,
  html[data-theme] .vim-mode,
  html[data-theme] .modal-body h3 {
    text-shadow: 0 0 8px var(--glow-color), 0 0 16px var(--glow-color);
  }

  html, body { height: 100%; }
  body {
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--fg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
    display: grid;
    grid-template-rows: auto 1fr auto;
    overflow: hidden;
    font-size: calc(13px * var(--fs-scale));
  }

  button, input, textarea {
    font: inherit;
  }

  button {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--fg);
    border-radius: 5px;
    padding: 6px 11px;
    cursor: pointer;
    white-space: nowrap;
  }
  button:hover:not(:disabled) { border-color: var(--accent); background: #202020; }
  button:disabled { opacity: 0.42; cursor: not-allowed; }
  button.primary { background: var(--accent); color: #101010; border-color: var(--accent); font-weight: 700; }
  button.primary:hover:not(:disabled) { background: var(--accent2); }

  header {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 10px 14px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
  }
  .brand {
    color: var(--accent);
    font-size: 1em;
    font-weight: 800;
    letter-spacing: 1.2px;
    flex-shrink: 0;
  }
  #folder-label {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    color: var(--dim);
    min-width: 0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  main { min-height: 0; position: relative; overflow: hidden; }
  [hidden] { display: none !important; }

  #shell-view, #vim-view {
    position: absolute;
    inset: 0;
    min-height: 0;
    background: var(--bg);
  }

  #shell-view { display: block; }
  #terminal-screen {
    height: 100%;
    min-height: 0;
    overflow: auto;
    padding: 16px 18px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    cursor: text;
  }
  #terminal-output {
    font: inherit;
    line-height: inherit;
  }
  .output-line { min-height: 1.55em; }
  .output-line.cmd { color: var(--accent2); }
  .output-line.error { color: var(--danger); }
  .output-line.warn { color: var(--warn); }
  .output-line.ok { color: var(--ok); }
  .output-line.dim { color: var(--dim); }
  .output-line.banner { color: var(--accent); }
  .output-line.diff-file { color: var(--dim); }
  .output-line.diff-hunk { color: var(--accent); }
  .output-line.diff-add { color: var(--ok); }
  .output-line.diff-del { color: var(--danger); }
  .output-line.diff-meta { color: var(--warn); }

  #command-form {
    display: grid;
    grid-template-columns: auto minmax(2ch, 1fr);
    gap: 8px;
    align-items: baseline;
    min-height: 1.55em;
    margin: 0;
    padding: 0;
    background: transparent;
    font: inherit;
    line-height: inherit;
  }
  #prompt { color: var(--accent); white-space: nowrap; }
  #command-input {
    width: 100%;
    min-width: 2ch;
    border: none;
    outline: none;
    background: transparent;
    color: var(--fg);
    caret-color: var(--accent);
    font: inherit;
    line-height: inherit;
  }

  /* Vim screen */
  #vim-view {
    display: grid;
    grid-template-rows: auto 1fr auto auto;
  }
  .vim-topline, .vim-statusline, .vim-commandbar {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 10px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    border-bottom: 1px solid var(--border);
    background: var(--bg2);
  }
  .vim-topline { padding: 8px 12px; }
  .mode-badge {
    min-width: 76px;
    text-align: center;
    padding: 3px 9px;
    border-radius: 4px;
    background: var(--accent);
    color: #101010;
    font-weight: 800;
    letter-spacing: 0.5px;
  }
  .mode-badge.insert { background: var(--warn); }
  .mode-badge.command { background: #bda7ff; }
  .mode-badge.readonly { background: var(--danger); }
  #vim-file-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--fg);
  }
  #vim-meta { color: var(--dim); white-space: nowrap; }
  .vim-actions { display: flex; gap: 7px; flex-shrink: 0; }
  .vim-actions button { padding: 4px 9px; font-size: 0.9231em; }

  #vim-editor-wrap {
    --line-number-width: 7ch;
    position: relative;
    min-width: 0;
    min-height: 0;
    background: var(--bg);
    overflow: hidden;
  }
  #vim-line-numbers {
    position: absolute;
    z-index: 2;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--line-number-width);
    overflow: hidden;
    padding: 16px 8px 16px 0;
    border-right: 1px solid var(--border);
    background: var(--bg);
    color: var(--faint);
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    line-height: 1.65;
    text-align: right;
    white-space: pre;
    pointer-events: none;
    user-select: none;
  }
  #vim-line-numbers-inner { will-change: transform; }
  #vim-editor {
    position: relative;
    z-index: 1;
    display: block;
    width: 100%;
    height: 100%;
    resize: none;
    border: none;
    outline: none;
    background: var(--bg);
    color: var(--fg);
    padding: 16px 20px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    line-height: 1.65;
    tab-size: 2;
    white-space: pre;
    overflow: auto;
    caret-color: var(--accent);
  }
  #vim-editor-wrap.show-line-numbers #vim-editor { padding-left: calc(var(--line-number-width) + 20px); }
  #vim-editor[readonly] { color: #d9d9d9; }
  #vim-view.normal-mode #vim-editor { caret-color: transparent; }
  #vim-normal-cursor {
    position: absolute;
    z-index: 3;
    left: 0;
    top: 0;
    width: 0.6em;
    height: 1.65em;
    border: 1px solid var(--accent);
    background: rgba(125, 211, 192, 0.22);
    box-sizing: border-box;
    pointer-events: none;
    transform: translate(-9999px, -9999px);
    animation: vim-normal-cursor-blink 1s steps(1, end) infinite;
  }
  #vim-normal-cursor.hidden { display: none; }
  @keyframes vim-normal-cursor-blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0.18; }
  }

  .vim-statusline {
    justify-content: space-between;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 5px 12px;
    color: var(--dim);
    font-size: 0.9231em;
  }
  #vim-message { color: var(--warn); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #vim-linecol { flex-shrink: 0; }
  .vim-commandbar {
    border-bottom: none;
    padding: 8px 12px;
    min-height: 38px;
  }
  #vim-command-prefix { color: var(--accent); flex-shrink: 0; }
  #vim-command-input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    outline: none;
    color: var(--fg);
    font-family: inherit;
  }
  .vim-commandbar.hidden-input #vim-command-input,
  .vim-commandbar.hidden-input #vim-command-prefix { visibility: hidden; }

  footer {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
    padding: 6px 14px;
    color: var(--dim);
    background: var(--bg2);
    border-top: 1px solid var(--border);
    font-size: 0.9231em;
  }
  #status-info { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .kbd {
    display: inline-block;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.7692em;
    border: 1px solid var(--border);
    background: var(--bg3);
    border-radius: 3px;
    padding: 0 5px;
    color: var(--fg);
  }

  .unsupported {
    max-width: 560px;
    margin: 72px auto;
    padding: 24px;
    line-height: 1.8;
    color: var(--dim);
    text-align: center;
  }
  .unsupported h2 { color: var(--warn); margin-bottom: 12px; font-size: 1.3846em; }

  .modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.65);
  }
  .modal-backdrop.open { display: flex; }
  .modal {
    width: min(720px, 100%);
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg2);
    box-shadow: 0 30px 80px var(--shadow);
    overflow: hidden;
  }
  .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
  }
  .modal-title { color: var(--accent); font-weight: 800; letter-spacing: 0.6px; }
  .modal-body { overflow: auto; padding: 18px; line-height: 1.8; color: var(--fg); }
  .modal-body h3 { margin-top: 16px; margin-bottom: 6px; color: var(--accent); font-size: 1em; }
  .modal-body p, .modal-body li { color: var(--dim); }
  .modal-body ul { padding-left: 1.3em; }
  .modal-body code {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
    color: var(--fg);
  }
  .modal-body pre {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 12px;
    margin: 8px 0;
    overflow: auto;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.8462em;
    line-height: 1.5;
    color: var(--fg);
    white-space: pre;
  }
  .modal-body pre code {
    background: transparent;
    border: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
  }
  .modal-body a {
    color: var(--accent);
    text-decoration: underline;
  }
  .modal-body a:hover {
    color: var(--accent2);
  }
  .settings-modal { width: min(560px, 100%); }
  .diff-modal { width: min(1040px, 100%); }
  .diff-output {
    min-height: 240px;
    max-height: 72vh;
    overflow: auto;
    padding: 12px 14px;
    background: var(--bg);
    color: var(--fg);
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.9231em;
    line-height: 1.55;
    white-space: pre;
  }
  .diff-line { min-height: 1.55em; }
  .diff-line.diff-file { color: var(--dim); }
  .diff-line.diff-hunk { color: var(--accent); }
  .diff-line.diff-add { color: var(--ok); }
  .diff-line.diff-del { color: var(--danger); }
  .diff-line.diff-meta { color: var(--warn); }
  .setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-top: 14px;
    color: var(--fg);
  }
  .setting-input-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--dim);
    white-space: nowrap;
  }
  #settings-grep-max-mb {
    width: 7em;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--bg);
    color: var(--fg);
    outline: none;
    padding: 6px 8px;
  }
  #settings-grep-max-mb:focus { border-color: var(--accent); }
  .setting-note { margin-top: 8px; }
  .modal-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
  }

  /* ==== Settings: SIZE / THEME option rows ================================== */
  .opt-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 8px 0 12px 0;
  }
  .opt-btn {
    padding: 4px 12px;
    background: var(--bg);
    color: var(--dim);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    transition: color 120ms, border-color 120ms, background 120ms;
  }
  .opt-btn:hover {
    color: var(--fg);
    border-color: var(--accent);
  }
  .opt-btn.on {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--bg2);
  }

  /* ==== Folder warning modal ================================================ */
  .warn-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
  }
  .warn-modal {
    background: var(--bg2);
    border: 1px solid var(--danger);
    border-radius: 8px;
    padding: 24px;
    max-width: 520px;
    width: 100%;
    color: var(--fg);
    font-size: 1em;
    line-height: 1.7;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  }
  .warn-modal h2 {
    color: var(--danger);
    font-size: 1.1538em;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .warn-modal p { margin: 6px 0; }
  .warn-modal p.warn-spacer { margin-top: 10px; }
  .warn-modal ul { margin: 8px 0 12px 20px; color: var(--dim); }
  .warn-modal li { margin: 2px 0; }
  .warn-modal code {
    background: var(--bg);
    padding: 1px 6px;
    border-radius: 3px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.9231em;
    color: var(--accent);
  }
  .warn-modal .warn-note {
    color: var(--dim);
    font-size: 0.9231em;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
  }
  .warn-modal .warn-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
  }

  @media (max-width: 720px) {
    header { gap: 6px; padding: 8px; }
    .brand { font-size: 0.9231em; }
    header button { padding: 5px 8px; font-size: 0.9231em; }
    #folder-label { display: none; }
    #terminal-screen { padding: 12px; }
    .vim-topline { gap: 6px; padding: 7px; }
    #vim-meta { display: none; }
    .vim-actions button { padding: 4px 7px; }
    footer { font-size: 0.8462em; gap: 8px; }
  }
