/* Java Practice prototype - design tokens and shared components.
   Light surfaces, one blue accent, thin separators, system sans-serif for UI
   and a monospace stack for code. Page-specific rules live in css/<page>.css. */

:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fafafb;
  --surface-3: #f0f1f4;
  --border: #e3e5e9;
  --border-strong: #cfd3da;
  --text: #1d1d1f;
  --text-2: #4f5358;
  --text-3: #7b7f86;
  --accent: #0b5fcc;
  --accent-hover: #0a52b0;
  --accent-soft: #e8f0fc;
  --accent-ring: rgba(11, 95, 204, 0.32);
  --ok: #1a7f37;
  --ok-soft: #e6f4ea;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --err: #b42318;
  --err-soft: #fdecec;
  --info: #0b5fcc;
  --info-soft: #e8f0fc;
  --neutral: #5a5f66;
  --neutral-soft: #eceef1;
  --code-bg: #1e1f24;
  --code-text: #e8e9ec;
  --code-gutter: #2a2b31;
  --code-line: #2c2d34;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 1px 2px rgba(20, 22, 26, 0.06);
  --shadow-lg: 0 12px 32px rgba(20, 22, 26, 0.16);
  --topbar-h: 52px;
  --content-max: 1200px;
  --ease: 160ms ease;
}

*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body.has-overlay { overflow: hidden; }

h1, h2, h3, h4, h5 { margin: 0; font-weight: 600; line-height: 1.3; color: var(--text); }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 15px; }
h4 { font-size: 14px; }
h5 { font-size: 13px; }
p { margin: 0 0 10px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono, kbd { font-family: var(--mono); }
code { font-size: 0.92em; background: var(--surface-3); padding: 1px 5px; border-radius: 4px; color: var(--text); }
pre { margin: 0; }
button { font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--text); }
.hidden, [hidden] { display: none !important; }
.muted { color: var(--text-3); }
.text-2 { color: var(--text-2); }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 6px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.divider { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:focus:not(:focus-visible) { outline: none; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; color: var(--text); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 5px; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 12px; font-weight: 700; }
.demo-badge { font-size: 11px; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; color: var(--warn); background: var(--warn-soft); border: 1px solid #f1dfae; border-radius: 4px; padding: 1px 6px; }
.nav { display: flex; align-items: center; gap: 2px; margin-left: 8px; }
.nav-link { color: var(--text-2); padding: 6px 10px; border-radius: var(--radius); font-weight: 500; text-decoration: none; position: relative; }
.nav-link:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
.nav-link[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.nav-count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 600; text-align: center; line-height: 18px; vertical-align: 1px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.user-chip { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; margin-right: 4px; }
.user-chip .user-name { font-weight: 600; font-size: 13px; }
.user-chip .user-role { font-size: 11.5px; color: var(--text-3); }
.topbar .nav-toggle { display: none; }

/* ---------- Layout ---------- */
.page { max-width: var(--content-max); margin: 0 auto; padding: 24px 20px 48px; }
.page-wide { max-width: none; }
.page-narrow { max-width: 760px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-title { font-size: 22px; }
.page-subtitle { color: var(--text-2); margin: 4px 0 0; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); margin-bottom: 4px; }
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.section { margin-bottom: 28px; }
.section-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-title { font-size: 15px; }
.section-actions { display: flex; gap: 8px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.panel-body { padding: 16px 18px; }
.panel-header { padding: 12px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-title { font-size: 14px; font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border-radius: var(--radius); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background-color var(--ease), border-color var(--ease), color var(--ease);
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--surface); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-danger { color: var(--err); border-color: #e9b8b3; background: var(--surface); }
.btn-danger:hover { background: var(--err-soft); }
.btn-link { border: 0; background: none; color: var(--accent); padding: 0; height: auto; font-weight: 500; }
.btn-link:hover { text-decoration: underline; background: none; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-lg { height: 40px; padding: 0 20px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-link.btn-sm, .btn-link.btn-lg { height: auto; padding: 0; }
a.btn:hover, .btn:hover { text-decoration: none; }
.btn .spinner { width: 12px; height: 12px; }

/* ---------- Pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 600; line-height: 1; white-space: nowrap; border: 1px solid transparent; }
.pill-ok { color: var(--ok); background: var(--ok-soft); }
.pill-warn { color: var(--warn); background: var(--warn-soft); }
.pill-err { color: var(--err); background: var(--err-soft); }
.pill-info { color: var(--info); background: var(--info-soft); }
.pill-neutral { color: var(--neutral); background: var(--neutral-soft); }
.pill-outline { background: transparent; border-color: var(--border-strong); color: var(--text-2); }

/* ---------- Notices ---------- */
.notice { padding: 10px 12px; border-radius: var(--radius); border: 1px solid; font-size: 13.5px; }
.notice-compact { padding: 6px 10px; font-size: 13px; }
.notice-info { background: var(--info-soft); border-color: #c9dbf6; color: #123d7a; }
.notice-ok { background: var(--ok-soft); border-color: #bfe3c8; color: #14532d; }
.notice-warn { background: var(--warn-soft); border-color: #f1dfae; color: #5c3d00; }
.notice-err { background: var(--err-soft); border-color: #f3c1bd; color: #7a1c14; }
.notice-neutral { background: var(--surface-3); border-color: var(--border); color: var(--text-2); }
.notice strong { font-weight: 600; }

.demo-label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--warn); background: var(--warn-soft); border: 1px solid #f1dfae; border-radius: 4px; padding: 2px 7px; }
.demo-label::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--warn); }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field-label { display: block; font-weight: 500; margin-bottom: 5px; font-size: 13.5px; }
.field-label .req { color: var(--err); }
.field-hint { margin-top: 5px; font-size: 12.5px; color: var(--text-3); }
.field-error { margin-top: 5px; font-size: 12.5px; color: var(--err); min-height: 0; }
.field-error:empty { display: none; }
.field.has-error .input, .field.has-error .textarea, .field.has-error .select { border-color: var(--err); }
.input, .select, .textarea {
  width: 100%; height: 36px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  transition: border-color var(--ease), box-shadow var(--ease);
}
.textarea { height: auto; padding: 8px 10px; line-height: 1.45; resize: vertical; }
.textarea.mono { font-family: var(--mono); font-size: 13px; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-3); color: var(--text-3); }
.select { padding-right: 28px; appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%234f5358' stroke-width='1.6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.checkbox { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.checkbox-label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.field-checkbox { margin-bottom: 10px; }
.field-inline { display: flex; align-items: center; gap: 8px; margin: 0; }
.field-inline .field-label { margin: 0; white-space: nowrap; }
.field-inline .select, .field-inline .input { width: auto; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 14px; }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.form-error { color: var(--err); font-size: 13px; }
.form-note { font-size: 12.5px; color: var(--text-3); }
.search { position: relative; }
.search .input { padding-left: 10px; }

/* ---------- Tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; color: var(--text-3); background: var(--surface-2); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table-clickable tbody tr { cursor: pointer; }
.table-clickable tbody tr:hover { background: var(--surface-2); }
.table-clickable tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.table td.align-right, .table th.align-right { text-align: right; }
.table td.align-center, .table th.align-center { text-align: center; }
.table-empty { color: var(--text-3); text-align: center; padding: 28px 12px !important; }
.table .cell-title { font-weight: 500; color: var(--text); }
.table .cell-sub { display: block; font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.table-compact th, .table-compact td { padding: 7px 10px; }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-weight: 500; }
.list-item-sub { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.list-item-aside { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.list-plain { background: none; border: 0; }
.list-plain .list-item { padding-left: 0; padding-right: 0; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.tab { position: relative; background: none; border: 0; padding: 10px 12px; color: var(--text-2); font-weight: 500; cursor: pointer; border-radius: var(--radius) var(--radius) 0 0; transition: color var(--ease), background-color var(--ease); }
.tab:hover { color: var(--text); background: var(--surface-3); }
.tab[aria-selected="true"] { color: var(--accent); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; background: var(--accent); border-radius: 1px; }
.tab-badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px; background: var(--neutral-soft); color: var(--text-2); font-size: 11px; font-weight: 600; line-height: 18px; text-align: center; }
.tab[aria-selected="true"] .tab-badge { background: var(--accent-soft); color: var(--accent); }
.tab-panel { padding-top: 16px; }
.tab-panel[hidden] { display: none; }
.tabs-compact .tab { padding: 8px 10px; font-size: 13px; }

/* ---------- Prose (lesson text) ---------- */
.prose { font-size: 14px; line-height: 1.6; color: var(--text); }
.prose p { margin: 0 0 10px; }
.prose h3 { font-size: 15px; margin: 18px 0 8px; }
.prose h4 { font-size: 14px; margin: 16px 0 6px; }
.prose h5 { font-size: 13px; margin: 12px 0 6px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.03em; }
.prose ul, .prose ol { margin: 0 0 10px; padding-left: 22px; }
.prose li { margin-bottom: 4px; }
.prose pre.code { margin: 8px 0 12px; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }

/* ---------- Code blocks ---------- */
pre.code { background: var(--code-bg); color: var(--code-text); border-radius: var(--radius); padding: 10px 12px; overflow-x: auto; font-size: 12.5px; line-height: 1.55; tab-size: 4; }
pre.code code { background: none; padding: 0; color: inherit; font-size: inherit; }
pre.code-compact { padding: 6px 10px; font-size: 12px; }
pre.code-light { background: var(--surface-3); color: var(--text); border: 1px solid var(--border); }
pre.code-text, pre.code-io { background: var(--surface-3); color: var(--text); border: 1px solid var(--border); white-space: pre-wrap; word-break: break-word; }
.code-wrap { border-radius: var(--radius); overflow: hidden; }
.code-caption { background: var(--code-gutter); color: #aeb1b8; font-size: 11.5px; padding: 4px 12px; }
.tok-kw { color: #7fb4ff; }
.tok-str { color: #c8e58f; }
.tok-cmt { color: #8b909a; font-style: italic; }
.tok-num { color: #f2b56b; }
.tok-type { color: #9ee3d8; }
.tok-ann { color: #d3a5ff; }

/* ---------- Key-value ---------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 13.5px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; }

/* ---------- Progress ---------- */
.progress { height: 6px; background: var(--neutral-soft); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 240ms ease; }
.progress-sm { height: 4px; }

/* ---------- Empty states ---------- */
.empty { padding: 32px 20px; text-align: center; color: var(--text-2); background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); }
.empty-title { font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-text { font-size: 13.5px; }
.empty-action { margin-top: 12px; }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(20, 22, 26, 0); display: flex; align-items: center; justify-content: center; padding: 20px; transition: background-color 160ms ease; }
.overlay.open { background: rgba(20, 22, 26, 0.38); }
.overlay.closing { background: rgba(20, 22, 26, 0); }
.dialog { width: 560px; max-width: 100%; max-height: calc(100vh - 40px); display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(8px); transition: opacity 160ms ease, transform 160ms ease; }
.overlay.open .dialog { opacity: 1; transform: none; }
.overlay.closing .dialog { opacity: 0; transform: translateY(8px); }
.dialog-header, .drawer-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dialog-title, .drawer-title { font-size: 16px; }
.dialog-body { padding: 18px; overflow-y: auto; }
.dialog-footer, .drawer-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.dialog-text { margin: 0; color: var(--text-2); }
.dialog-lg { width: 760px; }

.overlay-drawer { justify-content: flex-end; padding: 0; }
.drawer { width: 560px; max-width: 100%; height: 100%; display: flex; flex-direction: column; background: var(--surface); box-shadow: var(--shadow-lg); transform: translateX(24px); opacity: 0; transition: transform 180ms ease, opacity 180ms ease; }
.overlay.open .drawer { transform: none; opacity: 1; }
.overlay.closing .drawer { transform: translateX(24px); opacity: 0; }
.drawer-body { padding: 18px; overflow-y: auto; flex: 1; }
.drawer-wide { width: 720px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 360px; }
.toast { background: var(--text); color: #fff; padding: 10px 14px; border-radius: var(--radius); box-shadow: var(--shadow-lg); font-size: 13.5px; opacity: 0; transform: translateY(6px); transition: opacity 180ms ease, transform 180ms ease; }
.toast.open { opacity: 1; transform: none; }
.toast-ok { background: #14532d; }
.toast-err { background: #7a1c14; }
.toast-warn { background: #5c3d00; }

/* ---------- Spinner ---------- */
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 700ms linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Prototype controls panel ---------- */
.proto-panel { position: fixed; top: var(--topbar-h); right: 0; bottom: 0; width: 340px; max-width: 100%; z-index: 60; background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); transform: translateX(100%); transition: transform 180ms ease; display: flex; flex-direction: column; }
.proto-panel.open { transform: none; }
.proto-panel-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.proto-panel-body { padding: 14px 16px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 18px; }
.proto-section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); margin-bottom: 8px; }
.proto-account { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.proto-account:last-child { border-bottom: 0; }
.proto-account .muted { font-size: 12px; }

/* ---------- Footer ---------- */
.app-footer { max-width: var(--content-max); margin: 0 auto; padding: 0 20px 24px; color: var(--text-3); font-size: 12px; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar .nav-toggle { display: inline-flex; }
  .nav { display: none; position: absolute; top: var(--topbar-h); left: 0; right: 0; flex-direction: column; align-items: stretch; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px; margin: 0; gap: 2px; }
  .nav.open { display: flex; }
  .user-chip { display: none; }
}
@media (max-width: 640px) {
  .page { padding: 16px 14px 40px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; }
  .topbar { padding: 0 12px; gap: 8px; }
  .drawer, .drawer-wide { width: 100%; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 8px; }
}
