:root {
  --ink: #e8edf1;
  --muted: #94a4ae;
  --canvas: #12191d;
  --panel: #1a2429;
  --panel-strong: #202d33;
  --line: #34434a;
  --accent: #65d6ba;
  --accent-ink: #10211e;
  --warning: #f3a85a;
  --danger: #ef817a;
  --blue: #7ec6e8;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.topbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px max(24px, calc((100vw - 1480px) / 2));
  border-bottom: 1px solid var(--line);
  background: #162025;
}

.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; background: var(--accent); color: var(--accent-ink); border-radius: 6px; }
.top-actions, .editor-actions { display: flex; align-items: center; gap: 10px; }

main { max-width: 1480px; margin: 0 auto; padding: 28px 24px; }
.hidden { display: none !important; }
.muted, .field-help { color: var(--muted); font-size: 0.88rem; }
.eyebrow { margin: 0 0 5px; color: var(--accent); font-size: 0.72rem; font-weight: 700; text-transform: uppercase; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

.auth-layout { min-height: calc(100vh - 150px); display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(320px, 430px); align-items: center; gap: clamp(36px, 8vw, 130px); }
.auth-intro h1 { max-width: 680px; margin: 0; font-size: clamp(2.3rem, 4.4vw, 4.5rem); line-height: 1.03; }
.auth-intro > p:not(.eyebrow) { max-width: 560px; color: var(--muted); font-size: 1.08rem; line-height: 1.7; }
.auth-intro code { color: var(--blue); }
.fact-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 28px; }
.fact-row span { padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); font-size: 0.82rem; }

.auth-panel { padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.auth-switch, .editor-tabs { display: flex; gap: 4px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.auth-switch button, .editor-tabs button { border: 0; background: transparent; color: var(--muted); padding: 8px 10px; border-radius: 5px; }
.auth-switch button.active, .editor-tabs button.active { color: var(--accent-ink); background: var(--accent); }
form { display: grid; gap: 15px; padding-top: 20px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 0.84rem; }
input, textarea { border: 1px solid var(--line); border-radius: 6px; background: #121b1f; color: var(--ink); outline: none; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px #65d6ba22; }
form input { min-height: 42px; padding: 10px 11px; }
.field-help { min-height: 20px; margin: 0; line-height: 1.4; }

.primary-button, .quiet-button, .square-button { border-radius: 6px; border: 1px solid transparent; min-height: 34px; padding: 7px 12px; }
.primary-button { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.primary-button:hover { background: #88e4cd; }
.quiet-button { background: transparent; color: var(--muted); border-color: var(--line); }
.quiet-button:hover { color: var(--ink); border-color: var(--muted); }
.quiet-link { color: var(--blue); font-size: 0.88rem; }
.full-width { width: 100%; min-height: 42px; }
.danger { color: var(--danger); }
.square-button { width: 34px; padding: 0; font-size: 1.4rem; line-height: 1; background: var(--panel-strong); color: var(--accent); border-color: var(--line); }

.app-shell { min-height: calc(100vh - 114px); display: grid; grid-template-columns: 240px minmax(360px, 1fr) 288px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.note-sidebar, .calculator-panel { background: #172126; }
.note-sidebar { border-right: 1px solid var(--line); }
.sidebar-heading, .calculator-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 15px; border-bottom: 1px solid var(--line); }
.note-list { padding: 8px; display: grid; gap: 3px; max-height: calc(100vh - 190px); overflow: auto; }
.note-item { width: 100%; text-align: left; padding: 10px; border: 1px solid transparent; border-radius: 6px; color: var(--ink); background: transparent; }
.note-item:hover { background: var(--panel-strong); }
.note-item.active { background: #24453f; border-color: #376b5f; }
.note-item strong, .note-item span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item span { margin-top: 3px; color: var(--muted); font-size: 0.75rem; }
.empty-list { padding: 18px 10px; color: var(--muted); font-size: 0.88rem; line-height: 1.5; }

.editor-panel { min-width: 0; display: flex; flex-direction: column; background: #192328; }
.editor-toolbar { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.editor-tabs { border: 0; padding: 0; }
.note-title { width: 100%; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 17px 18px; background: #1b272c; font-size: 1.34rem; font-weight: 700; }
.note-body, .note-preview { width: 100%; min-height: 520px; flex: 1; padding: 18px; border: 0; border-radius: 0; line-height: 1.65; resize: vertical; }
.note-body { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 0.92rem; }
.note-preview { overflow-wrap: anywhere; }
.note-preview h1, .note-preview h2, .note-preview h3 { color: var(--blue); }
.note-preview pre { padding: 12px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: #10171b; }
.note-preview code { color: var(--warning); }
.wiki-link { display: inline; padding: 0; border: 0; color: var(--accent); background: transparent; text-decoration: underline; }

.calculator-panel { border-left: 1px solid var(--line); padding-bottom: 12px; }
.calculator-heading h2 { margin: 0; font-size: 1.15rem; }
.calculator-heading .quiet-button { min-height: 28px; padding: 4px 7px; font-size: 0.72rem; }
.calc-display { width: calc(100% - 24px); margin: 12px; min-height: 52px; padding: 10px; text-align: right; font-family: "SFMono-Regular", Consolas, monospace; font-size: 1.35rem; }
.calc-memory, .calc-grid { display: grid; gap: 5px; padding: 0 12px; }
.calc-memory { grid-template-columns: repeat(4, 1fr); margin-bottom: 7px; }
.calc-grid { grid-template-columns: repeat(4, 1fr); }
.calc-memory button, .calc-grid button { min-height: 36px; border: 1px solid var(--line); border-radius: 5px; color: var(--ink); background: var(--panel-strong); }
.calc-memory button { min-height: 28px; color: var(--muted); font-size: 0.72rem; }
.calc-grid button:hover, .calc-memory button:hover { border-color: var(--blue); }
.calc-grid .calc-operator { color: var(--blue); }
.calc-grid .calc-special { color: var(--warning); }
.calc-grid .calc-equals { grid-column: span 4; background: var(--accent); color: var(--accent-ink); font-weight: 800; }
.calc-history { display: grid; gap: 5px; max-height: 150px; margin: 14px 12px 0; padding: 0; overflow: auto; list-style: none; }
.calc-history button { width: 100%; padding: 6px; overflow: hidden; border: 0; border-radius: 4px; color: var(--muted); background: transparent; text-align: right; text-overflow: ellipsis; white-space: nowrap; font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.74rem; }

.toast { position: fixed; right: 20px; bottom: 20px; max-width: min(360px, calc(100vw - 40px)); padding: 11px 13px; border: 1px solid #487d70; border-radius: 6px; color: var(--ink); background: #24453f; box-shadow: 0 8px 26px #0007; }
.toast.error { border-color: #8b4b49; background: #4e2929; }

.admin-shell { max-width: 960px; margin: 0 auto; }
.admin-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.admin-header h1 { margin: 0; font-size: 1.65rem; }
.admin-tools { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.admin-grid { display: grid; grid-template-columns: minmax(310px, 1fr) minmax(310px, 1.1fr); gap: 16px; }
.admin-section { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.admin-section h2 { margin: 0; padding: 14px; border-bottom: 1px solid var(--line); font-size: 1rem; }
.user-row, .admin-note-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 14px; border-bottom: 1px solid #2b383e; }
.user-row:last-child, .admin-note-row:last-child { border-bottom: 0; }
.user-row button, .admin-note-row button { border: 0; color: var(--blue); background: transparent; padding: 4px; }
.user-row .delete, .admin-note-row .delete { color: var(--danger); }
.admin-detail { padding: 14px; color: var(--muted); line-height: 1.6; }
.admin-note-content { min-height: 160px; margin: 14px; padding: 12px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: #121b1f; color: var(--ink); white-space: pre-wrap; }

@media (max-width: 1040px) {
  .app-shell { grid-template-columns: 210px minmax(0, 1fr); }
  .calculator-panel { grid-column: 1 / -1; border-top: 1px solid var(--line); border-left: 0; }
  .calc-grid { grid-template-columns: repeat(8, 1fr); }
  .calc-grid .calc-equals { grid-column: span 8; }
}

@media (max-width: 720px) {
  .topbar, main { padding-left: 14px; padding-right: 14px; }
  main { padding-top: 16px; padding-bottom: 16px; }
  .auth-layout, .app-shell, .admin-grid { grid-template-columns: 1fr; }
  .auth-layout { min-height: auto; }
  .auth-intro { padding: 18px 0; }
  .note-sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .note-list { max-height: 230px; }
  .editor-toolbar, .topbar { align-items: flex-start; flex-direction: column; }
  .editor-actions { width: 100%; justify-content: flex-end; }
  .admin-header { align-items: flex-start; flex-direction: column; }
  .admin-tools { justify-content: flex-start; }
  .note-body, .note-preview { min-height: 380px; }
  .calc-grid { grid-template-columns: repeat(4, 1fr); }
  .calc-grid .calc-equals { grid-column: span 4; }
}
