/* Mobile first: base styles are for a phone; wider screens are enhanced below. */
:root { --bg:#0f1115; --panel:#171a21; --fg:#e6e8ee; --muted:#8b93a7; --accent:#5b9dff; --border:#262b36; --tap:44px; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--fg); font: 16px system-ui, sans-serif; overscroll-behavior: none; }
[hidden] { display: none !important; }
input, button, textarea { font: inherit; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--fg); }
input { padding: 10px 12px; min-height: var(--tap); }   /* 16px font stops iOS zooming on focus */
button { min-height: var(--tap); padding: 0 14px; background: var(--panel); cursor: pointer; touch-action: manipulation; }
button:active { background: var(--border); }
button:disabled { opacity: .4; }

/* login */
#login { display: none; height: 100%; align-items: center; justify-content: center; padding: 16px; }
#login form { background: var(--panel); border: 1px solid var(--border); padding: 24px; border-radius: 12px; width: 100%; max-width: 360px; display: grid; gap: 12px; }
#login button { background: var(--accent); color: #fff; border: 0; }
#err, .err { color: #ff7b7b; min-height: 1.2em; margin: 0; }

/* app shell: header / scrolling main / bottom tab bar. --vvh follows the on-screen keyboard. */
#app { display: none; flex-direction: column; height: var(--vvh, 100dvh); }
header { display: flex; align-items: center; justify-content: space-between; padding: 6px 16px; padding-top: max(6px, env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--border); }
header button { min-height: 36px; background: transparent; color: var(--muted); }
main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
main > section { flex: 1; min-height: 0; overflow: auto; padding: 16px; }
#tabs { display: flex; background: var(--panel); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.tab { flex: 1; display: grid; justify-items: center; gap: 2px; min-height: 56px; padding: 6px 0; border: 0; border-radius: 0; background: transparent; color: var(--muted); font-size: 12px; }
.tab span { font-size: 18px; line-height: 1; }
.tab.active { color: var(--accent); }

/* stats */
#stats h2 { margin: 0 0 12px; font-size: 15px; color: var(--muted); font-weight: 500; word-break: break-all; }
.cards { display: grid; grid-template-columns: 1fr; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; display: grid; gap: 6px; }
.card span { color: var(--muted); font-size: 13px; }
.card b { font-size: 22px; font-weight: 600; }
.bar { display: block; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.bar u { display: block; height: 100%; width: 0; background: var(--accent); text-decoration: none; transition: width .4s; }

/* files: tappable list rows; actions sit under the row when expanded */
.path-row { display: flex; gap: 8px; margin-bottom: 8px; }
.path-row input { flex: 1; min-width: 0; font-family: ui-monospace, monospace; font-size: 15px; }
.path-row button:not(#up) { flex: 1; }
#fileList { list-style: none; margin: 0; padding: 0; }
#fileList li { border-bottom: 1px solid var(--border); }
.row { display: flex; align-items: center; gap: 8px; min-height: 52px; }
.row .main { flex: 1; min-width: 0; padding: 6px 0; cursor: pointer; }
.row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .nm.dir { color: var(--accent); }
.row .meta { color: var(--muted); font-size: 12px; }
.row .more { width: var(--tap); padding: 0; background: transparent; border: 0; font-size: 20px; color: var(--muted); }
.actions { display: flex; gap: 8px; padding: 0 0 10px; }
.actions button { flex: 1; }
.actions .danger { color: #ff7b7b; }

/* editor: full screen overlay */
#editor { position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column; z-index: 10; padding-top: env(safe-area-inset-top); height: var(--vvh, 100dvh); }
.ed-bar { display: flex; align-items: center; gap: 8px; padding: 8px; background: var(--panel); border-bottom: 1px solid var(--border); }
.ed-bar strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; direction: rtl; text-align: left; }
.ed-bar #editSave { background: var(--accent); color: #fff; border: 0; }
#editor textarea { flex: 1; border: 0; border-radius: 0; padding: 12px; font: 14px ui-monospace, monospace; tab-size: 4; resize: none; }

/* terminal + on-screen keys (phones lack Esc/Tab/Ctrl/arrows) */
#termWrap { padding: 0 !important; overflow: hidden !important; display: flex; flex-direction: column; }
#term { flex: 1; min-height: 0; padding: 4px; }
#keys { display: flex; gap: 6px; overflow-x: auto; padding: 6px; background: var(--panel); border-top: 1px solid var(--border); }
#keys button { flex: 0 0 auto; min-width: 48px; padding: 0 10px; }
#keys button.on { background: var(--accent); color: #fff; }

/* tablet / desktop enhancements */
@media (min-width: 720px) {
  .cards { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
  main > section { padding: 24px; }
  #keys { display: none; }
}
@media (min-width: 720px) and (pointer: fine) {
  button { min-height: 36px; }
  input { min-height: 36px; }
}
