/* ==========================================================================
   Mobile Code Editor — dark, touch-first UI
   ========================================================================== */

:root {
    color-scheme: dark;

    /* Surfaces */
    --bg: #0e1219;
    --panel: #141a24;
    --panel-raised: #1a212d;
    --panel-hover: #222b39;
    --border: #253040;
    --border-soft: #1c2532;

    /* Type */
    --text: #e6edf3;
    --text-muted: #9aa7b8;
    --text-faint: #6b7a8f;

    /* Accents */
    --accent: #6cb6ff;
    --accent-strong: #2f81f7;
    --accent-soft: rgba(108, 182, 255, 0.14);
    --danger: #f47067;
    --danger-soft: rgba(244, 112, 103, 0.14);
    --ok: #7ee787;

    /* Shape */
    --radius: 10px;
    --radius-sm: 8px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    /* Editor tuning */
    --editor-font-size: 14px;
    --gutter-text: #4b586b;
    --selection-bg: rgba(80, 140, 220, 0.35);
    --scroll-thumb: #2a3648;
    --active-line: rgba(108, 182, 255, 0.055);
    --active-gutter: rgba(108, 182, 255, 0.07);
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.5);

    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-code: "JetBrains Mono", "Fira Code", "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

/* Pin the app to the visual viewport while the on-screen keyboard is open.
   Some Android browsers shrink and pan the visual viewport instead of
   resizing the layout viewport; without this the file action bar floats
   above the keyboard and wastes a large part of the screen. */
body.viewport-pinned {
    /* The keyboard covers the gesture/navigation area, so keeping the
       safe-area inset would reintroduce a gap above the keyboard. */
    --safe-bottom: 0px;
    width: var(--app-width, 100%);
    height: var(--app-height, 100%);
    transform: translate(var(--app-left, 0px), var(--app-top, 0px));
    transform-origin: 0 0;
}

button,
select {
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

button {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

button:focus-visible,
select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

svg {
    display: block;
}

/* --------------------------------------------------------------------------
   Top bar: language, Vim, cursor position, save state, activity log
   -------------------------------------------------------------------------- */

#topbar {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    min-height: 42px;
    padding: 5px 8px;
    padding-top: max(5px, var(--safe-top));
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

#language-select {
    flex: 0 0 auto;
    width: 92px;
    height: 30px;
    margin: 0;
    padding: 0 18px 0 8px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background-color: var(--panel-raised);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239aa7b8' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 5px center;
    background-size: 11px;
    color: var(--text);
    font-size: 11px;
    font-weight: 600;
    appearance: none;
    -webkit-appearance: none;
}

.chip {
    flex: 0 0 auto;
    height: 30px;
    padding: 0 11px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--panel-raised);
    color: var(--text-muted);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.chip:active {
    background: var(--panel-hover);
}

#vim-mode.active {
    background: var(--accent-soft);
    border-color: rgba(108, 182, 255, 0.45);
    color: var(--accent);
}

.topbar-spacer {
    flex: 1 1 auto;
    min-width: 4px;
}

.topbar-meta {
    flex: 0 0 auto;
    color: var(--text-faint);
    font-size: 10.5px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: 10.5px;
    white-space: nowrap;
}

.status-chip::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ok);
    box-shadow: 0 0 6px rgba(126, 231, 135, 0.6);
}

.status-chip[data-state="dirty"],
.status-chip[data-state="saving"] {
    color: var(--accent);
}

.status-chip[data-state="dirty"]::before,
.status-chip[data-state="saving"]::before {
    background: var(--accent);
    box-shadow: 0 0 6px rgba(108, 182, 255, 0.6);
}

.status-chip[data-state="error"] {
    color: var(--danger);
}

.status-chip[data-state="error"]::before {
    background: var(--danger);
    box-shadow: none;
}

.topbar-button {
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--text-muted);
}

.topbar-button svg {
    width: 15px;
    height: 15px;
    margin: auto;
}

.topbar-button:active,
.topbar-button.active {
    background: var(--panel-raised);
    border-color: var(--border);
    color: var(--accent);
}

/* --------------------------------------------------------------------------
   File tabs
   -------------------------------------------------------------------------- */

#tabbar {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    height: 38px;
    padding: 4px 6px;
    background: var(--panel);
    border-bottom: 1px solid var(--border-soft);
}

#tab-list {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    gap: 4px;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#tab-list::-webkit-scrollbar {
    display: none;
}

.tab {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    max-width: 160px;
    height: 30px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: var(--panel-raised);
    color: var(--text-muted);
    overflow: hidden;
}

.tab.active {
    border-color: rgba(108, 182, 255, 0.32);
    background: var(--accent-soft);
    color: var(--text);
}

.tab.long-press,
.tab.renaming {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--text);
}

.tab.renaming {
    min-width: 140px;
    max-width: 220px;
}

.tab-rename {
    flex: 1 1 auto;
    width: 140px;
    min-width: 60px;
    height: 100%;
    padding: 0 6px;
    border: 0;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    outline: none;
}

.tab-label {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
    height: 100%;
    padding: 0 4px 0 9px;
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 10.5px;
    font-weight: 600;
    white-space: nowrap;
}

.tab-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.tab-dirty {
    flex: 0 0 5px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0;
}

.tab.dirty .tab-dirty {
    opacity: 1;
}

.tab-close {
    flex: 0 0 22px;
    width: 22px;
    height: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text-faint);
    font-size: 14px;
    line-height: 1;
}

.tab-close:active {
    color: var(--danger);
}

.tab-actions {
    display: flex;
    align-items: center;
    gap: 3px;
    flex: 0 0 auto;
}

.tab-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--text-muted);
}

.tab-action svg {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tab-action:active {
    background: var(--panel-raised);
    color: var(--accent);
}

/* --------------------------------------------------------------------------
   Editor
   -------------------------------------------------------------------------- */

#editor-container {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    overflow: hidden;
    background: var(--bg);
}

.cm-editor {
    height: 100%;
}

.cm-editor .cm-scroller {
    font-family: var(--font-code);
    font-size: var(--editor-font-size);
    line-height: 1.6;
    overscroll-behavior: contain;
}

.cm-editor .cm-content {
    padding: 8px 0 32px;
}

.cm-editor .cm-line {
    padding-left: 2px;
}

/* Blend One Dark with the app's deeper background. */
body .cm-editor {
    background-color: var(--bg);
    color: var(--text);
}

body .cm-editor .cm-gutters {
    background-color: var(--bg);
    color: var(--gutter-text);
    border-right: 1px solid var(--border-soft);
}

body .cm-editor .cm-activeLine {
    background-color: var(--active-line);
}

body .cm-editor .cm-activeLineGutter {
    background-color: var(--active-gutter);
    color: var(--text-muted);
}

body .cm-editor .cm-cursor,
body .cm-editor .cm-dropCursor {
    border-left-color: var(--accent);
    border-left-width: 2px;
}

body .cm-editor .cm-selectionBackground,
body .cm-editor .cm-content ::selection {
    background-color: var(--selection-bg) !important;
}

body .cm-editor .cm-focused .cm-matchingBracket,
body .cm-editor .cm-focused .cm-nonmatchingBracket {
    background-color: rgba(108, 182, 255, 0.16);
    outline: 1px solid rgba(108, 182, 255, 0.3);
}

/* Panels (search, Vim status) */
body .cm-editor .cm-panels {
    background-color: var(--panel);
    color: var(--text);
}

body .cm-editor .cm-panels-top {
    border-bottom: 1px solid var(--border);
}

body .cm-editor .cm-panels-bottom {
    border-top: 1px solid var(--border);
}

body .cm-editor .cm-search {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
    padding: 7px 8px;
    font-family: var(--font-ui);
    font-size: 12px;
}

body .cm-editor .cm-search .cm-textfield {
    min-width: 0;
    height: 30px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 12px;
}

body .cm-editor .cm-search .cm-button {
    height: 30px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background-color: var(--panel-raised);
    background-image: none;
    color: var(--text);
    font-size: 11px;
    font-weight: 600;
}

body .cm-editor .cm-search label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    font-size: 11px;
}

body .cm-editor .cm-search [name="close"] {
    height: 30px;
    padding: 0 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: 16px;
}

body .cm-editor .cm-vim-panel {
    padding: 3px 9px;
    background: var(--panel);
    color: var(--text-muted);
    font-family: var(--font-code);
    font-size: 11px;
    letter-spacing: 0.04em;
}

body .cm-editor .cm-tooltip {
    border: 1px solid var(--border) !important;
    border-radius: 8px;
    background: var(--panel-raised) !important;
    color: var(--text);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    overflow: hidden;
}

body .cm-editor .cm-tooltip-autocomplete > ul > li[aria-selected] {
    background: var(--accent-soft) !important;
    color: var(--text) !important;
}

.cm-editor ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.cm-editor ::-webkit-scrollbar-thumb {
    background: var(--scroll-thumb);
    border-radius: 999px;
}

.cm-editor ::-webkit-scrollbar-track {
    background: transparent;
}

/* --------------------------------------------------------------------------
   Activity log drawer
   -------------------------------------------------------------------------- */

#console-drawer {
    flex-shrink: 0;
    padding: 6px 8px;
    background: var(--panel);
    border-top: 1px solid var(--border);
}

#log-output {
    display: block;
    width: 100%;
    height: 88px;
    padding: 7px 9px;
    resize: none;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text-faint);
    font-family: var(--font-code);
    font-size: 10.5px;
    line-height: 1.5;
}

/* --------------------------------------------------------------------------
   Extra keys
   -------------------------------------------------------------------------- */

#extra-keys {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    width: 100%;
    padding: 0 0 4px;
    background: var(--panel);
    border-top: 1px solid var(--border);
    touch-action: pan-x;
}

.keys-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    height: 15px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text-faint);
}

.keys-handle svg {
    width: 13px;
    height: 13px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform 0.18s ease;
}

.keys-grip {
    width: 18px;
    height: 2px;
    border-radius: 999px;
    background: var(--border);
}

#extra-keys.collapsed .keys-handle svg {
    transform: rotate(180deg);
}

#extra-keys.collapsed .key-row {
    display: none;
}

body.hide-modifiers .key-row.modifiers,
body.hide-nav .key-row.navigation {
    display: none;
}

.key-row {
    display: flex;
    align-items: center;
    gap: 3px;
    width: 100%;
    height: 46px;
    padding: 0 6px;
}

.key {
    flex: 1 1 0;
    min-width: 0;
    height: 38px;
    padding: 0 2px;
    overflow: hidden;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--panel-raised);
    color: var(--text);
    font-size: 11.5px;
    font-weight: 600;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: background-color 0.12s, transform 0.06s, border-color 0.12s;
}

.key:active {
    background: var(--panel-hover);
    transform: scale(0.94);
}

.key-esc {
    border-color: rgba(108, 182, 255, 0.28);
    color: var(--accent);
}

.key.is-active {
    background: var(--accent-strong);
    border-color: transparent;
    color: #fff;
}

.key.modifier.active,
.key.modifier.is-active {
    background: var(--accent-strong);
    border-color: transparent;
    color: #fff;
}

.key.modifier.active:active,
.key.modifier.is-active:active {
    background: #2568c4;
}

.nav-key {
    flex: 0.8 1 0;
    color: var(--text-muted);
    font-size: 13px;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0.72 1 0;
    min-width: 0;
    height: 38px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--panel-raised);
    color: var(--text-muted);
    transition: background-color 0.12s, color 0.12s, transform 0.06s;
}

.icon-button svg {
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon-button:active {
    background: var(--panel-hover);
    color: var(--text);
    transform: scale(0.94);
}

.icon-button.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.row-button {
    flex: 1 1 0;
}

/* --------------------------------------------------------------------------
   File actions
   -------------------------------------------------------------------------- */

#file-io {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    width: 100%;
    height: calc(52px + var(--safe-bottom));
    padding: 6px 8px calc(6px + var(--safe-bottom));
    background: var(--panel);
    border-top: 1px solid var(--border);
}

.action {
    display: flex;
    flex: 1 1 0;
    min-width: 0;
    height: 40px;
    padding: 4px 2px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--panel-raised);
    color: var(--text-muted);
    transition: background-color 0.12s, color 0.12s, transform 0.06s;
}

.action svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.action span {
    display: block;
    max-width: 100%;
    overflow: hidden;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
}

.action:active {
    background: var(--panel-hover);
    color: var(--text);
    transform: scale(0.95);
}

.action-primary {
    border-color: rgba(108, 182, 255, 0.28);
    background: var(--accent-soft);
    color: var(--accent);
}

.action-primary:active {
    background: rgba(108, 182, 255, 0.22);
    color: var(--accent);
}

.action-danger:active {
    background: var(--danger-soft);
    color: var(--danger);
}

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */

#toast {
    position: absolute;
    left: 50%;
    bottom: 12px;
    z-index: 50;
    max-width: calc(100% - 32px);
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--panel-raised);
    color: var(--text);
    font-size: 12px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 10px);
    transition: opacity 0.18s ease, transform 0.18s ease;
}

#toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* --------------------------------------------------------------------------
   Bottom sheet / command palette
   -------------------------------------------------------------------------- */

.sheet {
    position: fixed;
    inset: auto 0 0 0;
    width: min(540px, 100%);
    max-width: 100%;
    max-height: min(84vh, 680px);
    margin: 0 auto;
    padding: 0;
    border: 1px solid var(--border);
    border-bottom: 0;
    border-radius: 16px 16px 0 0;
    background: var(--panel);
    color: var(--text);
    box-shadow: 0 -18px 48px rgba(0, 0, 0, 0.45);
    overflow: hidden;
}

.sheet[open] {
    animation: sheet-up 0.18s ease;
}

.sheet:focus {
    outline: none;
}

.sheet::backdrop {
    background: rgba(3, 6, 12, 0.58);
    backdrop-filter: blur(2px);
}

@keyframes sheet-up {
    from { transform: translateY(18px); opacity: 0.6; }
    to { transform: translateY(0); opacity: 1; }
}

.sheet-inner {
    display: flex;
    flex-direction: column;
    max-height: inherit;
}

.sheet-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    padding: 10px 12px 8px 16px;
    border-bottom: 1px solid var(--border-soft);
}

.sheet-header h2 {
    flex: 1 1 auto;
    margin: 0;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--text);
}

.sheet-close {
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: 18px;
    line-height: 1;
}

#sheet-body {
    min-height: 0;
    padding: 10px 14px calc(14px + var(--safe-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sheet-section-title {
    margin: 14px 2px 7px;
    color: var(--text-faint);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.sheet-section-title:first-child {
    margin-top: 2px;
}

.sheet-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin-top: 10px;
}

.sheet-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--panel-raised);
    color: var(--text);
    font-size: 11.5px;
    font-weight: 600;
    text-align: center;
}

.sheet-button svg {
    width: 15px;
    height: 15px;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sheet-button:active {
    background: var(--panel-hover);
}

.sheet-button.primary {
    border-color: rgba(108, 182, 255, 0.32);
    background: var(--accent-soft);
    color: var(--accent);
}

.sheet-button.danger {
    color: var(--danger);
}

.sheet-button.wide {
    grid-column: 1 / -1;
}

/* Files list */

.file-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.file-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 8px 8px 11px;
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    background: var(--bg);
}

.file-row.active {
    border-color: rgba(108, 182, 255, 0.36);
    background: var(--accent-soft);
}

.file-main {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    text-align: left;
}

.file-name {
    overflow: hidden;
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-meta {
    color: var(--text-faint);
    font-size: 10px;
    font-variant-numeric: tabular-nums;
}

.file-badge {
    flex: 0 0 auto;
    padding: 2px 6px;
    border-radius: 999px;
    background: var(--panel-raised);
    color: var(--text-muted);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.file-row.active .file-badge {
    background: rgba(108, 182, 255, 0.18);
    color: var(--accent);
}

.file-actions {
    display: flex;
    flex: 0 0 auto;
    gap: 2px;
}

.file-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--text-faint);
}

.file-action svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.file-action:active {
    background: var(--panel-hover);
    color: var(--text);
}

.file-action.danger:active {
    color: var(--danger);
}

/* Settings */

.setting-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 42px;
    padding: 2px 2px;
    border-bottom: 1px solid var(--border-soft);
}

.setting-row:last-of-type {
    border-bottom: 0;
}

.setting-label {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    font-size: 12px;
    font-weight: 600;
}

.setting-hint {
    color: var(--text-faint);
    font-size: 10px;
    font-weight: 400;
}

.setting-row input[type="checkbox"] {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    margin: 0;
    accent-color: var(--accent-strong);
}

.setting-row input[type="range"] {
    flex: 0 0 108px;
    width: 108px;
    accent-color: var(--accent-strong);
}

.setting-row-controls {
    display: flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
}

.setting-value {
    flex: 0 0 30px;
    color: var(--text-muted);
    font-size: 11px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.segmented {
    display: inline-flex;
    flex: 0 0 auto;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
}

.segmented button {
    min-width: 30px;
    height: 24px;
    padding: 0 7px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 700;
}

.segmented button.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.settings-footer {
    position: sticky;
    bottom: 0;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 14px;
    padding: 8px 0 2px;
    border-top: 1px solid var(--border-soft);
    background: var(--panel);
}

.settings-footer .sheet-button {
    flex: 1 1 0;
}

/* Command palette */

.sheet.palette {
    top: max(12px, var(--safe-top));
    bottom: auto;
    max-height: min(74vh, 560px);
    border-bottom: 1px solid var(--border);
    border-radius: 14px;
}

.sheet.palette[open] {
    animation: palette-in 0.14s ease;
}

@keyframes palette-in {
    from { transform: translateY(-8px); opacity: 0.6; }
    to { transform: translateY(0); opacity: 1; }
}

.palette-input {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 13px;
}

.palette-input::placeholder {
    color: var(--text-faint);
}

.palette-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: transparent;
}

.palette-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 8px;
}

.palette-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 38px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font-size: 12px;
    text-align: left;
}

.palette-item svg {
    flex: 0 0 15px;
    width: 15px;
    height: 15px;
    fill: none;
    stroke: var(--text-faint);
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.palette-item .palette-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.palette-item .palette-hint {
    flex: 0 0 auto;
    color: var(--text-faint);
    font-size: 9.5px;
    font-variant-numeric: tabular-nums;
}

.palette-item.active {
    border-color: rgba(108, 182, 255, 0.32);
    background: var(--accent-soft);
}

.palette-item.active svg {
    stroke: var(--accent);
}

.palette-empty {
    padding: 22px 10px;
    color: var(--text-faint);
    font-size: 12px;
    text-align: center;
}

/* Light theme */

body.theme-light {
    color-scheme: light;
    --bg: #ffffff;
    --panel: #f6f8fa;
    --panel-raised: #eef1f4;
    --panel-hover: #e4e8ed;
    --border: #d0d7de;
    --border-soft: #e4e8ed;
    --text: #1f2328;
    --text-muted: #57606a;
    --text-faint: #8c959f;
    --accent: #0969da;
    --accent-strong: #0969da;
    --accent-soft: rgba(9, 105, 218, 0.1);
    --danger: #cf222e;
    --danger-soft: rgba(207, 34, 46, 0.1);
    --ok: #1a7f37;
    --gutter-text: #8c959f;
    --selection-bg: rgba(9, 105, 218, 0.2);
    --scroll-thumb: #c4ccd6;
    --active-line: #f0f4f9;
    --active-gutter: #eaeef2;
    --shadow: 0 12px 32px rgba(31, 35, 40, 0.18);
}

body.theme-light .status-chip::before {
    box-shadow: none;
}

body.theme-light .tab.active {
    border-color: rgba(9, 105, 218, 0.25);
}

body.theme-light .key-esc {
    border-color: rgba(9, 105, 218, 0.3);
}

body.theme-light .action-primary {
    border-color: rgba(9, 105, 218, 0.3);
}

body.theme-light .sheet {
    box-shadow: 0 -18px 48px rgba(31, 35, 40, 0.18);
}

body.theme-light .sheet::backdrop {
    background: rgba(31, 35, 40, 0.35);
}

/* --------------------------------------------------------------------------
   Compact phones / landscape
   -------------------------------------------------------------------------- */

@media (max-height: 480px) {
    #topbar {
        min-height: 36px;
        padding-top: max(2px, var(--safe-top));
        padding-bottom: 2px;
    }

    #language-select,
    .chip,
    .topbar-button {
        height: 28px;
    }

    #language-select {
        width: 88px;
    }

    .topbar-button {
        flex-basis: 28px;
        width: 28px;
    }

    #tabbar {
        height: 34px;
        padding-top: 2px;
        padding-bottom: 2px;
    }

    .tab {
        height: 28px;
    }

    .tab-action {
        width: 28px;
        height: 28px;
    }

    .keys-handle {
        height: 12px;
    }

    .key-row {
        height: 40px;
    }

    .key,
    .icon-button {
        height: 33px;
    }

    #file-io {
        height: calc(44px + var(--safe-bottom));
        padding-top: 4px;
        padding-bottom: calc(4px + var(--safe-bottom));
    }

    .action {
        height: 34px;
        flex-direction: row;
        gap: 4px;
    }

    .action span {
        font-size: 9.5px;
    }

    .sheet {
        max-height: 92vh;
    }
}

@media (max-width: 360px) {
    #topbar {
        gap: 4px;
        padding-left: 6px;
        padding-right: 6px;
    }

    #language-select {
        width: 88px;
        font-size: 10.5px;
    }

    .tab {
        max-width: 128px;
    }

    .tab-action {
        width: 28px;
        height: 28px;
    }

    .key-row {
        gap: 2px;
        padding: 0 4px;
    }

    .key {
        font-size: 10.5px;
    }

    .nav-key {
        font-size: 11px;
    }
}

@media (max-width: 340px) {
    #status-pos {
        display: none;
    }

    #language-select {
        width: 88px;
    }

    .key {
        font-size: 10px;
    }
}
