:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efea;
  --border: #e2e0d8;
  --text: #1d1d1b;
  --muted: #6b6a63;
  --accent: #0f766e;
  --accent-soft: #d8efec;
  --accent-text: #ffffff;
  --danger: #b42318;
  --add: #e3f4e6;
  --del: #fbe4e2;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #141413;
  --surface: #1e1e1c;
  --surface-2: #262624;
  --border: #34332f;
  --text: #ecebe6;
  --muted: #9c9a92;
  --accent: #2dd4bf;
  --accent-soft: #123b37;
  --accent-text: #08201d;
  --danger: #f97066;
  --add: #16331f;
  --del: #3d1a17;
  --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
}
a { color: var(--accent); }
.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 268px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 12px; text-decoration: none; color: var(--text); }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-weight: 700; font-size: 13px; letter-spacing: .5px; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: -.2px; }
.search-wrap { padding: 4px 14px 10px; }
#search { width: 100%; }
nav { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.nav-group { margin-top: 10px; }
.nav-group h4 { margin: 8px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 8px; color: var(--text); text-decoration: none; font-size: 14px; }
.nav-link:hover { background: var(--surface-2); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-link .ic { width: 22px; text-align: center; font-size: 15px; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.status { font-size: 12px; color: var(--muted); }
.status.ok::before { content: "● "; color: #16a34a; }
.status.bad::before { content: "● "; color: var(--danger); }

/* Main */
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 14px 28px; border-bottom: 1px solid var(--border); background: var(--bg); position: sticky; top: 0; z-index: 5; }
.crumbs { flex: 1; font-size: 14px; color: var(--muted); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs b { color: var(--text); }
.icon-btn { background: none; border: 1px solid transparent; font-size: 20px; cursor: pointer; color: var(--text); border-radius: 8px; padding: 2px 8px; }
.icon-btn:hover { background: var(--surface-2); }
.fav.on { color: #d97706; }
#menuBtn { display: none; }
main { padding: 28px; max-width: 1100px; width: 100%; outline: none; }

/* Home */
.hero h1 { font-size: 30px; margin: 0 0 4px; letter-spacing: -.5px; }
.hero p { color: var(--muted); margin: 0 0 24px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 28px 0 10px; font-weight: 600; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.card-link { display: flex; gap: 12px; padding: 14px; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); text-decoration: none; color: var(--text); box-shadow: var(--shadow); transition: border-color .15s, transform .15s; }
.card-link:hover { border-color: var(--accent); transform: translateY(-1px); }
.card-link .ic { font-size: 22px; width: 36px; height: 36px; display: grid; place-items: center; background: var(--surface-2); border-radius: 8px; flex-shrink: 0; }
.card-link b { display: block; font-size: 14px; }
.card-link span.d { font-size: 12.5px; color: var(--muted); line-height: 1.35; }

/* Tool page */
.tool-head h1 { margin: 0 0 4px; font-size: 24px; letter-spacing: -.3px; }
.tool-head p { margin: 0 0 20px; color: var(--muted); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.row > * { flex: 1 1 160px; }
.row > .shrink { flex: 0 0 auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
label { display: block; font-size: 13px; color: var(--muted); font-weight: 500; }
label > input, label > select, label > textarea { margin-top: 4px; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=number], input[type=search], input[type=date], input[type=datetime-local], input[type=time], input[type=password], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 160px; resize: vertical; font-family: var(--mono); font-size: 13.5px; }
textarea.prose { font-family: inherit; font-size: 15px; }
input[type=color] { width: 48px; height: 38px; border: 1px solid var(--border); border-radius: 8px; background: none; padding: 2px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: 14px; margin-right: 14px; cursor: pointer; }
button { cursor: pointer; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 14px; }
button:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--text); border-color: var(--border); font-weight: 500; }
button.ghost:hover { background: var(--surface-2); }
button.small { padding: 4px 10px; font-size: 13px; }
button.danger { background: transparent; color: var(--danger); border-color: var(--border); }
button:disabled { opacity: .5; cursor: default; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.out { font-family: var(--mono); background: var(--surface-2); border-radius: 8px; padding: 12px; white-space: pre-wrap; word-break: break-all; min-height: 44px; font-size: 13.5px; }
.big { font-size: 32px; font-weight: 700; letter-spacing: -.5px; }
.muted { color: var(--muted); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 12px; }
.stat .v { font-size: 22px; font-weight: 700; }
.stat .k { font-size: 12px; color: var(--muted); }
.error { color: var(--danger); font-size: 14px; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); }
table.t th { color: var(--muted); font-weight: 600; font-size: 12.5px; }
.kv { display: grid; grid-template-columns: auto 1fr auto; gap: 6px 12px; align-items: center; }
.kv .k { color: var(--muted); font-size: 13px; }
.kv .v { font-family: var(--mono); font-size: 13px; word-break: break-all; }

/* Calculator */
.calc { min-width: 0; }
.calc-display { background: var(--surface-2); border-radius: 10px; padding: 14px; text-align: right; margin-bottom: 12px; }
.calc-display .expr { color: var(--muted); font-family: var(--mono); min-height: 20px; word-break: break-all; }
.calc-display .res { font-size: 34px; font-weight: 700; word-break: break-all; }
.keys { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.keys button { padding: 12px 0; background: var(--surface-2); color: var(--text); border-color: var(--border); font-weight: 500; }
.keys button.op { background: var(--accent-soft); color: var(--accent); }
.keys button.eq { background: var(--accent); color: var(--accent-text); }

/* Spell / diff */
.spell-out { line-height: 1.9; font-size: 15px; white-space: pre-wrap; }
.miss { background: var(--del); border-bottom: 2px solid var(--danger); cursor: pointer; border-radius: 3px; padding: 0 2px; position: relative; }
.sugg { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.diff-line { font-family: var(--mono); font-size: 13px; padding: 1px 8px; white-space: pre-wrap; }
.diff-line.add { background: var(--add); }
.diff-line.del { background: var(--del); }
.md-preview { line-height: 1.6; }
.md-preview pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow: auto; }
.md-preview code { font-family: var(--mono); }
.md-preview table { border-collapse: collapse; } .md-preview td, .md-preview th { border: 1px solid var(--border); padding: 4px 8px; }

/* Images */
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); cursor: pointer; background: var(--surface); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.preview-img { max-width: 100%; max-height: 420px; border-radius: 8px; display: block; margin: 0 auto; background: repeating-conic-gradient(var(--surface-2) 0 25%, transparent 0 50%) 0 0/16px 16px; }
.swatch { width: 100%; height: 120px; border-radius: 10px; border: 1px solid var(--border); }
.palette { display: flex; gap: 6px; margin-top: 10px; }
.palette div { flex: 1; height: 48px; border-radius: 8px; cursor: pointer; display: flex; align-items: flex-end; justify-content: center; font-size: 11px; font-family: var(--mono); padding-bottom: 3px; }

/* Notes */
.notes { display: grid; grid-template-columns: 260px 1fr; gap: 16px; }
.note-list { display: flex; flex-direction: column; gap: 6px; max-height: 560px; overflow: auto; }
.note-item { padding: 10px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; background: var(--surface); }
.note-item.active { border-color: var(--accent); background: var(--accent-soft); }
.note-item b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item small { color: var(--muted); }

.timer-face { font-size: 64px; font-weight: 700; font-family: var(--mono); text-align: center; letter-spacing: -1px; margin: 10px 0; }
.todo-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.todo-item span { flex: 1; } .todo-item.done span { text-decoration: line-through; color: var(--muted); }
.dice { font-size: 64px; text-align: center; letter-spacing: 8px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px; font-size: 14px; transition: transform .2s, opacity .2s; z-index: 50; pointer-events: none; opacity: 0; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.empty { color: var(--muted); padding: 20px 0; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .sidebar.open { transform: none; }
  #menuBtn { display: block; }
  main { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .grid2, .grid3, .notes { grid-template-columns: 1fr; }
  .keys button { padding: 14px 0; }
}
