@font-face {
  font-family: 'Cascadia Code';
  /* Prefer local font at /fonts/; fallback to CDN */
  src: url('/fonts/CascadiaCode-SemiBold.ttf') format('truetype'),
       url('https://cdn.jsdelivr.net/gh/microsoft/cascadia-code@latest/ttf/CascadiaCode-SemiBold.ttf') format('truetype');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --radius: 4px;
  --radius-sm: 3px;
  --gap: 16px;

  --mono: "Cascadia Code", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  /* default: dark theme */
  --bg: #000;
  --panel: #000;
  --text: #fff;
  --muted: #cfcfcf;
  --border: #fff;

  --btn-bg: #000;
  --btn-text: #fff;
  --btn-border: #fff;

  --input-bg: #000;
  --input-text: #fff;
  --input-border: #fff;

  --focus: 2px solid #fff;
}

html[data-theme="light"] {
  --bg: #fff;
  --panel: #fff;
  --text: #000;
  --muted: #222;
  --border: #000;

  --btn-bg: #fff;
  --btn-text: #000;
  --btn-border: #000;

  --input-bg: #fff;
  --input-text: #000;
  --input-border: #000;

  --focus: 2px solid #000;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  /* Prefer Cascadia Code semibold; fallback fonts keep math layout */
  font-family: "Cascadia Code", "KaTeX_Main", "Latin Modern Roman", "Computer Modern Serif", Georgia, serif;
  font-weight: 600;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-weight: 600; }

.spacer { height: 14px; }

.appShell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: var(--gap);
  padding: var(--gap);
}

@media (max-width: 980px) {
  .appShell { grid-template-columns: 1fr; }
}

.sidebar {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  position: sticky;
  top: var(--gap);
  height: calc(100vh - (var(--gap) * 2));
}

.sidebarTop {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.brandRow {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.brandTitle { font-size: 18px; font-weight: 700; }
.brandSub { font-size: 12px; color: var(--muted); }

.avatarRow {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  font-weight: 700;
}

.userName { font-weight: 700; }
.userSub { font-size: 12px; }

.sidebarActions {
  margin-top: 12px;
  display: grid;
}

.nav {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.navItem {
  width: 100%;
  min-height: 44px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;

  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);

  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.navItem.active {
  background: var(--text);
  color: var(--bg);
}

.pill {
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid currentColor;
  border-radius: var(--radius-sm);
}

.main {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.topbar {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbarLeft { display: flex; align-items: center; gap: 10px; }
.apiStatus { font-weight: 700; }
.apiHint { font-size: 12px; }

.dot {
  width: 10px;
  height: 10px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
}
.dot.ok { background: var(--text); }
.dot.bad { background: transparent; }

.section { padding: 14px; }

.grid2 {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 14px;
}
@media (max-width: 980px) { .grid2 { grid-template-columns: 1fr; } }

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.cardHeader {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.cardTitle { font-weight: 700; }
.cardBody { padding: 14px; }

.rowBetween {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.wrap { flex-wrap: wrap; }

.tagRow {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.promptBox {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  min-height: 92px;
  display: grid;
  place-items: center;
}

#prompt {
  font-size: 20px;
  line-height: 1.35;
  text-align: center;
}

.fieldLabel {
  font-size: 12px;
  color: var(--muted);
  display: block;
  margin-bottom: 8px;
}

input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;

  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--input-text);
  font: inherit;
  outline: none;
}

input:focus {
  outline: var(--focus);
  outline-offset: 2px;
}

.btnRow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.btn {
  min-height: 44px;
  padding: 10px 12px;

  border: 1px solid var(--btn-border);
  border-radius: var(--radius);
  background: var(--btn-bg);
  color: var(--btn-text);

  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn:hover {
  background: var(--text);
  color: var(--bg);
}

.btn:focus-visible {
  outline: var(--focus);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btnSmall {
  min-height: 36px;
  padding: 6px 10px;
  font-weight: 700;
}

.btnFull { width: 100%; }

.console {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 220px;

  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.45;

  white-space: pre-wrap;
  overflow: auto;
}

.progressWrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.progressTop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.progressBar {
  height: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: transparent;
}

.progressFill {
  height: 100%;
  width: 0%;
  background: var(--text);
}

.statsPill {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.points { font-weight: 900; font-size: 18px; }

.miniStats {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
@media (max-width: 980px) { .miniStats { grid-template-columns: 1fr; } }

.miniStat {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.big { font-size: 18px; font-weight: 900; }

.tableWrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
}

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { text-align: left; font-weight: 900; }
tr:last-child td { border-bottom: 0; }

.segments {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.seg {
  min-height: 40px;
  padding: 8px 12px;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.seg:last-child { border-right: 0; }

.seg.active {
  background: var(--text);
  color: var(--bg);
}

.seg:focus-visible {
  outline: var(--focus);
  outline-offset: 2px;
}

.profileGrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
@media (max-width: 980px) { .profileGrid { grid-template-columns: 1fr; } }

.profileItem {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.modalBackdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.60);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 999;
}

html[data-theme="light"] .modalBackdrop {
  background: rgba(0,0,0,0.25);
}

.modal {
  width: min(520px, 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.modalHeader {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modalTitle { font-weight: 900; font-size: 16px; }

.modalTabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border);
}

.tab {
  border: 0;
  background: transparent;
  padding: 12px 14px;
  cursor: pointer;
  font: inherit;
  font-weight: 900;
  color: var(--text);
  border-right: 1px solid var(--border);
}
.tab:last-child { border-right: 0; }

.tab.active {
  background: var(--text);
  color: var(--bg);
}

.modalBody { padding: 14px; }

/* Floating report button for mobile */
.btnFloat {
  position: fixed;
  right: 16px;
  bottom: 18px;
  z-index: 1100;
  padding: 12px 14px;
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  display: none; /* shown only on small screens */
}

@media (max-width: 600px) {
  .btnFloat { display: inline-flex; align-items: center; justify-content: center; }
}

/* Mobile-specific tweaks */
@media (max-width: 600px) {
  .appShell { padding: 10px; gap: 10px; }

  .sidebar {
    position: static;
    top: auto;
    height: auto;
    margin-bottom: 8px;
  }

  .sidebarTop { padding: 10px; }

  .brandTitle { font-size: 16px; }
  .brandSub { font-size: 11px; }

  .avatar { width: 36px; height: 36px; }

  #prompt { font-size: 18px; }

  .console { min-height: 140px; font-size: 12px; }

  .progressBar { height: 8px; }

  .btn { padding: 10px 12px; }
  .btnSmall { min-height: 40px; }

  .navItem { min-height: 48px; padding: 10px; }

  .cardBody { padding: 12px; }

  .modal { width: min(480px, 100%); }
}
