/* FeLeeCa app: phone first (iPhone in Bluefy, then Edge on Windows), light and dark, one column,
   large tap targets (at least 44 px), nothing that depends on hover. No web fonts, no images. */

:root {
  color-scheme: light dark;
  --bg: #f3f3f1; --fg: #1a1a1a; --muted: #5f5f5f; --line: #d4d4d1; --panel: #ffffff; --panel2: #e9e9e6;
  --btn: #e4e4e0; --btn-fg: #1a1a1a; --accent: #1b5fd0; --accent-fg: #ffffff;
  --ok: #157030; --bad: #b3261e; --warn: #8a5800; --warn-bg: #fff3d6; --bad-bg: #fde7e5; --info-bg: #e5eefc;
  --radius: 10px; --tabs-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111213; --fg: #e8e8e8; --muted: #a0a0a0; --line: #34363a; --panel: #1b1c1e; --panel2: #232528;
    --btn: #2c2e32; --btn-fg: #e8e8e8; --accent: #6ea2ff; --accent-fg: #0b1220;
    --ok: #63cf80; --bad: #ff8077; --warn: #e6b450; --warn-bg: #33290f; --bad-bg: #3a1a18; --info-bg: #17243a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden; overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: .2em 0 .4em; }
h2 { font-size: 1.1rem; margin: 0 0 .5em; }
p { margin: .5em 0; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }

/* Buttons: large, full contrast, no hover-only state. */
button {
  min-height: 48px; padding: 10px 16px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--btn); color: var(--btn-fg); cursor: pointer; touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:active { filter: brightness(.92); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; }
button.danger { background: var(--bad); color: #fff; border-color: transparent; font-weight: 600; }
button.big { display: block; width: 100%; min-height: 56px; margin: 10px 0; font-size: 1.1rem; }
button.small { min-height: 36px; padding: 4px 10px; font-size: .9rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---- shell ---- */
.app { min-height: 100vh; min-height: 100dvh; padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom, 0px)); }

.strip {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; min-height: 48px;
  padding: 6px max(14px, env(safe-area-inset-right, 0px)) 6px max(14px, env(safe-area-inset-left, 0px));
  padding-top: calc(6px + env(safe-area-inset-top, 0px));
  background: var(--panel2); border-bottom: 1px solid var(--line); font-size: .92rem;
}
.strip .who { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.strip .who > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.strip .job { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--accent); }
.dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--muted); }
[data-state="ready"] .dot { background: var(--ok); }
[data-state="connecting"] .dot, [data-state="choosing"] .dot, [data-state="closing"] .dot { background: var(--accent); }
[data-state="lost"] .dot { background: var(--bad); }
.strip[data-state="lost"] .state { color: var(--bad); }
.strip[data-state="ready"] .state { color: var(--ok); }

.banners { padding: 0 14px; }
.banner { margin: 10px 0 0; padding: 10px 14px; border-radius: var(--radius); background: var(--info-bg); }
.banner.warn { background: var(--warn-bg); }
.banner .row { display: flex; flex-wrap: wrap; gap: 8px; }
.banner .row > button { flex: 1 1 8em; }

.screens { padding: 8px max(14px, env(safe-area-inset-right, 0px)) 24px max(14px, env(safe-area-inset-left, 0px)); max-width: 40rem; margin: 0 auto; }
.screen[hidden] { display: none; }
.placeholder { padding: 24px 4px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  min-height: var(--tabs-h); padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--panel2); border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 0;
  min-height: var(--tabs-h); padding: 6px 2px; border: 0; border-radius: 0; background: transparent; color: var(--muted);
  font-size: .78rem;
}
.tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-selected="true"] { color: var(--accent); font-weight: 600; }
.tab[aria-selected="true"] svg { stroke-width: 2.2; }
.tab svg .fill { fill: currentColor; stroke: none; }

/* ---- the Board screen ---- */
.area { padding: 8px 0; }
.lead { font-size: 1.1rem; font-weight: 600; }
.msg { padding: 8px 12px; border-radius: var(--radius); background: var(--panel2); overflow-wrap: anywhere; }
.msg.bad { background: var(--bad-bg); color: var(--bad); }
.help { padding: 4px 0; }
.help a { display: inline-block; min-height: 44px; padding: 10px 0; }

ol.steps { list-style: none; margin: 12px 0; padding: 0; }
ol.steps li { position: relative; padding: 8px 0 8px 34px; color: var(--muted); }
ol.steps li::before {
  content: ""; position: absolute; left: 4px; top: 11px; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--line);
}
ol.steps li.done { color: var(--fg); }
ol.steps li.done::before { background: var(--ok); border-color: var(--ok); }
ol.steps li.active { color: var(--fg); font-weight: 600; }
ol.steps li.active::before { border-color: var(--accent); border-right-color: transparent; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { ol.steps li.active::before { animation: none; border-right-color: var(--accent); } }

.card { margin: 12px 0; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.card-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.card-title .title-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title .title-state { margin-left: auto; flex: none; font-size: .9rem; font-weight: 500; color: var(--muted); }
.card[data-state="ready"] .title-state { color: var(--ok); }
.card[data-state="lost"] .title-state { color: var(--bad); }
.card.stale dl, .card.stale .switch-row { opacity: .55; }
dl { margin: 6px 0; }
.kv { display: grid; grid-template-columns: 7.6em minmax(0, 1fr); gap: 2px 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.kv[hidden] { display: none; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.kv dd .sub { display: block; color: var(--muted); font-size: .9rem; }
@media (max-width: 340px) { .kv { grid-template-columns: minmax(0, 1fr); } }
.note { margin: 8px 0; padding: 8px 12px; border-radius: var(--radius); background: var(--panel2); font-size: .92rem; }
.note.warn { background: var(--warn-bg); color: var(--warn); }

.switch-row { padding: 6px 0; border-top: 1px solid var(--line); }
.switch-row[hidden] { display: none; }
.switch-row p { margin: 0 0 4px; }
button.switch {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  padding: 8px 0; border: 0; background: transparent; text-align: left; font-weight: 500;
}
.switch .knob { position: relative; flex: none; width: 52px; height: 32px; border-radius: 16px; background: var(--line); transition: background .15s; }
.switch .knob::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s;
}
.switch[aria-checked="true"] .knob { background: var(--ok); }
.switch[aria-checked="true"] .knob::after { transform: translateX(20px); }
.switch.busy .knob { opacity: .5; }
@media (prefers-reduced-motion: reduce) { .switch .knob, .switch .knob::after { transition: none; } }

.row { display: flex; flex-wrap: wrap; gap: 8px; }
.actions { margin-top: 10px; }
.actions[hidden] { display: none; }
.actions > button { flex: 1 1 9em; }
.version { margin-top: 24px; text-align: center; }

/* ---- dialogs ---- */
.dlg-backdrop {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center;
  padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); background: rgba(0, 0, 0, .45);
}
@media (min-width: 600px) { .dlg-backdrop { align-items: center; } }
.dlg {
  width: min(30rem, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 18px; border-radius: 14px;
  background: var(--panel); color: var(--fg); box-shadow: 0 10px 40px rgba(0, 0, 0, .35); outline: none;
}
.dlg-buttons { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.dlg-buttons button { width: 100%; }
.dlg-items { margin: 8px 0; padding: 0; list-style: none; }
.dlg-items li { margin: 6px 0; padding: 8px 10px; border-radius: 8px; background: var(--panel2); }
.dlg-items li.lvl-lock, .dlg-items li.lvl-permanent { background: var(--bad-bg); }
.dlg-items li.lvl-lock b, .dlg-items li.lvl-permanent b { color: var(--bad); }
.dlg-items li.lvl-warning { background: var(--warn-bg); }

.fatal { margin: 16px; padding: 12px; border-radius: var(--radius); background: var(--bad-bg); color: var(--bad); }

/* ---- fields (the new card form, dialogs) ---- */
.field { margin: 12px 0; }
.field[hidden] { display: none; }
.field > label, .field-title { display: block; margin-bottom: 4px; font-weight: 600; font-size: .95rem; }
input[type="text"] {
  width: 100%; min-width: 0; min-height: 48px; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--fg); font-size: 17px;
}
/* 16 px: a 32-digit block fits a 390 px wide phone, and iOS does not zoom into a field of 16 px or more. */
input.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 16px; }
.with-buttons { display: flex; flex-wrap: wrap; gap: 6px; align-items: stretch; }
.with-buttons input { flex: 1 1 13em; }
.with-buttons button { flex: none; min-height: 48px; min-width: 48px; padding: 6px 10px; }
.field-err { margin: 4px 0 0; color: var(--bad); font-size: .92rem; }
.field-err[hidden] { display: none; }
label.check { display: flex; align-items: center; gap: 10px; min-height: 48px; margin: 8px 0; }
label.check input { width: 22px; height: 22px; flex: none; }

/* ---- the Cards screen ---- */
.cardlist { list-style: none; margin: 10px 0; padding: 0; }
.cardlist.stale .card-entry { opacity: .55; }
.card-entry { margin: 8px 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.card-entry.active { border-color: var(--ok); box-shadow: inset 4px 0 0 var(--ok); }
.card-entry.open { border-color: var(--accent); }
button.entry-main {
  display: flex; flex-direction: column; align-items: stretch; gap: 2px; width: 100%; min-height: 60px; padding: 10px 14px;
  border: 0; border-radius: 0; background: transparent; text-align: left;
}
.entry-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; min-width: 0; }
.entry-top .num { color: var(--muted); font-variant-numeric: tabular-nums; }
.entry-top .name { min-width: 0; overflow-wrap: anywhere; }
.entry-top .badge {
  margin-left: auto; padding: 1px 8px; border-radius: 10px; background: var(--ok); color: var(--panel);
  font-size: .8rem; font-weight: 600;
}
.entry-sub { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.entry-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 0 12px 12px; }
.entry-actions[hidden] { display: none; }
@media (min-width: 520px) { .entry-actions { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
button.danger-outline { color: var(--bad); border-color: var(--bad); background: transparent; }
#cards-msg { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#cards-msg > span { flex: 1 1 12em; min-width: 0; }
#cards-msg button { min-height: 44px; }
.backup-note { margin-top: 16px; }

/* ---- the new card form ---- */
.type-list { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 12px; }
.type-opt {
  display: flex; align-items: flex-start; gap: 12px; min-height: 56px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--panel); cursor: pointer;
}
.type-opt input { flex: none; width: 22px; height: 22px; margin: 2px 0 0; }
.type-opt:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.type-opt.disabled { opacity: .6; cursor: default; }
.type-text { display: flex; flex-direction: column; min-width: 0; }
.type-text .why { color: var(--warn); font-size: .88rem; }
.type-text .why[hidden] { display: none; }

/* ---- the console tab (web/console/view.js binds to these ids) ---- */
.console-tab {
  display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto auto; grid-template-columns: minmax(0, 1fr); min-height: 300px;
}
.console-tab > * { min-width: 0; }
.console-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.console-head button { min-height: 44px; }
.console-tab > p { margin: 0 0 8px; }
.console-tab .outwrap { position: relative; min-height: 0; border: 1px solid var(--line); border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; }
#out {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; background: var(--panel);
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#out .entry { padding: 5px 10px; border-bottom: 1px solid var(--line); }
#out .entry .head { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
#out .entry .cmd { font-weight: 600; white-space: pre; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#out .entry .cmd::before { content: "› "; color: var(--accent); }
#out .entry .meta { margin-left: auto; flex: none; color: var(--muted); font-size: 12px; white-space: nowrap; }
#out .entry pre { margin: 2px 0 0; padding: 0; white-space: pre; overflow-x: auto; max-width: 100%; font: inherit; }
#out .entry .ln { display: block; }
#out .entry .ln.status { font-weight: 700; }
#out .entry .ln.status.ok { color: var(--ok); }
#out .entry .ln.status.err { color: var(--bad); }
#out .entry.timeout .meta, #out .entry.failed .meta { color: var(--bad); font-weight: 600; }
#out .entry.queued .meta, #out .entry.sent .meta { color: var(--accent); }
#out .entry.unasked .head { color: var(--warn); }
#out .entry.unasked .cmd::before { content: "‹ "; color: var(--warn); }
#out .entry.info { color: var(--muted); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 13px; }
#out .entry.info.ok { color: var(--ok); }
#out .entry.info.bad { color: var(--bad); }
#out .entry.info.warn { color: var(--warn); }
#jump {
  position: absolute; right: 12px; bottom: 12px; z-index: 4; min-height: 44px; border-radius: 22px;
  background: var(--accent); color: var(--accent-fg); border-color: transparent; box-shadow: 0 2px 10px rgba(0, 0, 0, .3);
}
#histPanel {
  position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 5; max-height: 60%; overflow-y: auto; padding: 6px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
}
#histPanel button {
  display: block; width: 100%; margin: 2px 0; text-align: left; white-space: pre; overflow: hidden; text-overflow: ellipsis;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.console-tab .quick {
  display: flex; gap: 6px; overflow-x: auto; padding: 6px 8px; background: var(--panel2); border: 1px solid var(--line);
  border-bottom: 0; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.console-tab .quick::-webkit-scrollbar { display: none; }
.console-tab .quick button {
  flex: none; min-height: 44px; min-width: 48px; padding: 4px 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px; white-space: nowrap;
}
form.cmdline {
  display: flex; gap: 6px; padding: 6px 8px; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
}
#line {
  flex: 1 1 auto; min-width: 0; min-height: 44px; padding: 6px 10px;
  font: 16px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#histBtn, #sendBtn { flex: none; min-height: 44px; padding: 6px 12px; }
