:root {
  --bg: #0b0e13;
  --bg-2: #10141b;
  --panel: #151a22;
  --panel-2: #1b212b;
  --panel-3: #232a36;
  --line: #262e3a;
  --text: #e8ebf0;
  --muted: #8a94a4;
  --accent: #4f8cff;
  --accent-2: #7c5cff;
  --live: #ff4757;
  --win: #2ecc71;
  --lose: #ff5c6c;
  --star: #f7b733;
  --gold: #f7c948;
  --silver: #c0c7d2;
  --bronze: #d38b4f;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f2f4f8;
  --bg-2: #e9edf3;
  --panel: #ffffff;
  --panel-2: #f4f6fa;
  --panel-3: #e9edf3;
  --line: #dde2ea;
  --text: #18202b;
  --muted: #677285;
  --accent: #2563eb;
  --accent-2: #6d4aff;
  --live: #e11d48;
  --win: #16a34a;
  --lose: #dc2626;
  --star: #c98a00;
  --gold: #c99a06;
  --silver: #8b95a5;
  --bronze: #b4652a;
  --shadow: 0 8px 24px rgba(20,30,50,.08);
  color-scheme: light;
}
/* Installed on an iPhone the page runs under the status bar (black-translucent) and above the
   home indicator; these keep the bars and menus clear of them. 0 everywhere else. */
:root { --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px); }
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1200px 500px at 10% -10%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 60%),
    radial-gradient(900px 400px at 100% 0%, color-mix(in srgb, var(--accent-2) 10%, transparent), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
button, input { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { display: block; }
[hidden] { display: none !important; }

/* ---------- Header ---------- */
header {
  position: sticky; top: 0; z-index: 10;
  padding-top: var(--safe-top);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.bar {
  max-width: 1100px; margin: 0 auto; padding: 10px 16px;
  display: flex; gap: 12px; align-items: center;
}
.page-title { display: flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 800; white-space: nowrap; min-width: 0; }
.page-title .ic { font-size: 18px; }
.bar-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }
body[data-search] .search-wrap + .bar-actions { margin-left: 0; }
.icon-btn.capture-btn { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; font-weight: 600; }
.icon-btn.menu-btn { display: none; position: relative; font-size: 16px; }
.menu-btn.alert::after { content: ""; position: absolute; right: 4px; top: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--lose); }

/* ---------- Side menu ---------- */
:root { --side-w: 220px; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 15;
  display: flex; flex-direction: column; gap: 6px;
  padding: calc(14px + var(--safe-top)) 10px calc(14px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg-2) 92%, transparent); backdrop-filter: blur(12px);
  border-right: 1px solid var(--line); overflow-y: auto;
}
.sidebar .brand { padding: 2px 8px 10px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-group { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .7px; padding: 12px 10px 4px; }
.module-btn, .side-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: none; border: 0; border-radius: 9px; padding: 8px 10px; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: 14px;
}
.module-btn .ic, .side-btn .ic { width: 22px; text-align: center; font-size: 16px; flex: none; }
.module-btn .lbl, .side-btn .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.module-btn:hover, .side-btn:hover { color: var(--text); background: var(--panel); }
.module-btn[aria-pressed="true"] { color: var(--text); background: color-mix(in srgb, var(--accent) 16%, var(--panel)); box-shadow: inset 3px 0 0 var(--accent); }
.module-btn .count { flex: none; }
.side-foot { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--line); padding-top: 8px; }
.side-backdrop { position: fixed; inset: 0; z-index: 14; background: rgba(0,0,0,.45); }
/* Wide screens: the menu is always there and the page makes room for it. */
@media (min-width: 1001px) {
  body { padding-left: var(--side-w); }
  .side-backdrop { display: none !important; }
}
/* Narrow screens: a drawer opened from ☰. */
@media (max-width: 1000px) {
  .icon-btn.menu-btn { display: inline-grid; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); z-index: 25; }
  .sidebar.open { transform: none; }
  @media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
  .side-backdrop { z-index: 24; }
}
@media (max-width: 720px) {
  .capture-btn .lbl { display: none; }
  .icon-btn.capture-btn { padding: 0 10px; }
  .page-title { font-size: 16px; }
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: .2px; white-space: nowrap; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-size: 12px;
}
.brand-text span { color: var(--accent); }
.search-wrap { position: relative; flex: 1; max-width: 420px; margin-left: auto; }
.search {
  width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px 8px 34px; outline: none;
}
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.kbd { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; }
.suggest {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  max-height: 70vh; overflow-y: auto; padding: 6px;
}
.suggest-title { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; padding: 8px 8px 4px; }
.suggest-item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.suggest-item:hover, .suggest-item.active { background: var(--panel-2); }
.suggest-item .sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  height: 36px; min-width: 36px; padding: 0 10px; cursor: pointer; display: inline-grid; place-items: center;
}
.icon-btn:hover { border-color: var(--accent); text-decoration: none; }

nav.tabs-bar { max-width: 1100px; margin: 0 auto; padding: 0 16px; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
nav.tabs-bar::-webkit-scrollbar { display: none; }
.tab {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 12px; cursor: pointer;
  color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-weight: 500;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.count { font-size: 11px; padding: 0 6px; border-radius: 99px; background: var(--live); color: #fff; font-weight: 700; }

main { max-width: 1100px; margin: 0 auto; padding: 18px 16px 60px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  background: var(--panel); border: 1px solid var(--line); border-radius: 99px;
  padding: 6px 13px; cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.meta { color: var(--muted); font-size: 12px; }
.spacer { flex: 1; }
.section-head { display: flex; align-items: baseline; gap: 10px; margin: 26px 0 10px; }
.section-head:first-child { margin-top: 4px; }
.section-head h2 { margin: 0; font-size: 15px; font-weight: 700; }

/* Cloud sync status in the side menu: a dot (green ok, blue syncing, red error) and a short text. */
.sync-badge .ic { position: relative; }
.sync-badge .ic::after { content: ""; position: absolute; right: 0; bottom: 0; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 2px var(--bg-2); }
.sync-badge.ok .ic::after { background: var(--win); }
.sync-badge.busy .ic::after { background: var(--accent); animation: pulse 1s infinite; }
.sync-badge.err .ic::after { background: var(--lose); }
.sync-badge.err .lbl { color: var(--lose); }

body:not([data-module="cs2"]) .cs2-only, body:not([data-search]) .module-search { display: none; }

/* Command palette (Ctrl+K) */
.icon-btn.palette-btn { display: inline-flex; align-items: center; gap: 6px; padding: 0 10px; color: var(--muted); }
.palette-btn .lbl { color: var(--text); font-weight: 600; }
.kbd-inline { font-size: 11px; border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; }
#palette .palette-box {
  position: fixed; z-index: 31; top: 12vh; left: 50%; transform: translateX(-50%); width: min(640px, calc(100% - 24px));
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 10px; display: grid; gap: 8px;
}
#palette .backdrop { z-index: 30; }
#palette-q { padding: 12px 14px; font-size: 15px; color: var(--text); }
.palette-list { max-height: min(56vh, 460px); overflow-y: auto; display: grid; gap: 2px; }
.pl-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; border-radius: 9px; padding: 8px 10px; cursor: pointer; color: var(--text); }
.pl-item:hover, .pl-item.active { background: var(--panel-2); }
.pl-item.active { box-shadow: inset 3px 0 0 var(--accent); }
.pl-ic { width: 24px; text-align: center; font-size: 16px; flex: none; }
.pl-t { min-width: 0; display: grid; gap: 1px; font-size: 14px; }
.pl-t .meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-empty { padding: 14px 10px; }
.palette-foot { padding: 2px 6px; }
@media (max-width: 720px) {
  .palette-btn .lbl, .kbd-inline { display: none; }
  #palette .palette-box { top: calc(8px + var(--safe-top)); }
}

/* Local AI assistant window */
#ai .ai-box {
  position: fixed; z-index: 33; top: 8vh; left: 50%; transform: translateX(-50%); width: min(720px, calc(100% - 24px)); max-height: 84vh;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 14px 16px; display: grid; grid-template-rows: auto 1fr auto auto; gap: 10px;
}
#ai .backdrop { z-index: 32; }
.ai-head { display: flex; align-items: center; gap: 8px; }
.ai-head b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.ai-out { overflow-y: auto; min-height: 120px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font-size: 14.5px; }
.ai-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ai-acts { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.ai-note { font-size: 11px; }
.ai-btn { display: inline-flex; align-items: center; gap: 5px; }

/* Giriş: the whole page waits behind the password on a server (core/auth.js). */
#login { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login-box { width: min(360px, 100%); display: grid; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.login-box .brand { justify-content: center; margin-bottom: 4px; }
.login-box p { margin: 0; text-align: center; }
.login-box input { padding-left: 12px; font-size: 16px; } /* 16px keeps iOS from zooming in */
.login-box button { justify-content: center; }
.login-err { min-height: 18px; color: var(--lose); font-size: 13px; text-align: center; }
/* A server without the local model hides the assistant's buttons. */
body.no-ai [data-action^="ai-"], body.no-ai .ai-only { display: none !important; }
