:root {
  --bg: #ffffff;
  --bg-elev: #f8fafc;
  --fg: #0f172a;
  --muted: #475569;
  --border: #e2e8f0;
  --shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
  --accent: #2563eb;
  --accent-2: #7c3aed;
  --danger: #dc2626;
  --panel-screen50-height: 50vh;
  --panel-screen60-height: 60vh;
  --panel-screen70-height: 70vh;
  --panel-screen80-height: 80vh;
  --panel-screen90-height: 90vh;
  --sidebar-width: 280px;
  --grid-max-cols: 1;
  --mono: ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: "PT Sans", -apple-system, "Helvetica Neue", "Segoe UI", "Roboto", sans-serif;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  height: 100%;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:visited {
  color: var(--accent);
}

a:hover {
  text-decoration: underline;
}

/* Prevent long URLs from breaking mobile layout */
.article,
.callout {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.article a,
.callout a,
#submission-link {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.panel-header,
.panel-header .title,
.panel-header .meta,
.panel-header .meta > * {
  min-width: 0;
}

.file-link {
  max-width: 100%;
  min-width: 0;
}

.file-link span {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

button,
input,
textarea,
select {
  font-family: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  width: 100%;
  margin: 0;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand-title {
  font-size: 15px;
  font-weight: 760;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elev);
  padding: 2px;
  gap: 2px;
}

.segmented button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  padding: 8px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  background: var(--bg);
  color: var(--fg);
  box-shadow: 0 1px 0 var(--border);
}

.layout {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 12px 16px 20px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  flex: 1 0 auto;
  align-items: start;
}

@media (min-width: 640px) {
  .layout {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }
}

@media (min-width: 1080px) {
  :root {
    --grid-max-cols: 2;
  }
}

@media (min-width: 1500px) {
  :root {
    --grid-max-cols: 3;
  }
}

@media (min-width: 2000px) {
  :root {
    --grid-max-cols: 4;
  }
}

.sidebar {
  position: relative;
  top: auto;
  align-self: start;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.sidebar-section:last-child {
  border-bottom: 0;
}

.nav-button {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg);
  padding: 10px 10px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.nav-button:hover {
  background: var(--bg-elev);
}

.nav-button[aria-current="page"] {
  border-color: rgba(37, 99, 235, 0.35);
  background: rgba(37, 99, 235, 0.08);
}

.nav-meta {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  flex: 0 0 auto;
}

.submeta {
  font-size: 11px;
  color: var(--muted);
  font-weight: 650;
  flex: 0 0 auto;
  white-space: nowrap;
}

.sublist {
  margin: 8px 0 0;
  display: grid;
  gap: 6px;
}

.sublist button {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg);
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sublist button:hover {
  border-color: rgba(37, 99, 235, 0.35);
}

.sublist button[aria-current="true"] {
  border-color: rgba(37, 99, 235, 0.45);
  background: rgba(37, 99, 235, 0.08);
}

.content {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.view {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

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

.view-title h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0.2px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.btn {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg);
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

.btn:hover {
  border-color: rgba(37, 99, 235, 0.45);
}

.select {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

.select:hover {
  border-color: rgba(37, 99, 235, 0.45);
}

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

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  border-radius: 999px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 650;
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, var(--grid-max-cols)), minmax(0, 1fr));
  gap: 16px;
  min-width: 0;
}

.grid > .panel {
  min-height: 0;
}

@media (max-width: 560px) {
  .panel-header {
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .panel-header .meta {
    white-space: normal;
    flex-wrap: wrap;
    flex: 1 1 100%;
    justify-content: flex-start;
  }
}

.panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg);
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-header {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}

.panel-header .title {
  font-size: 12px;
  font-weight: 750;
  color: var(--fg);
}

.panel-header .meta {
  font-size: 12px;
  color: var(--muted);
  display: inline-flex;
  gap: 10px;
  align-items: center;
  white-space: nowrap;
}

.panel-scroll {
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
}

.panel.panel-screen50 {
  height: var(--panel-screen50-height);
  max-height: var(--panel-screen50-height);
  flex: 0 0 auto;
}

.panel.panel-screen60 {
  height: var(--panel-screen60-height);
  max-height: var(--panel-screen60-height);
  flex: 0 0 auto;
}

.panel.panel-screen70 {
  height: var(--panel-screen70-height);
  max-height: var(--panel-screen70-height);
  flex: 0 0 auto;
}

.panel.panel-screen80 {
  height: var(--panel-screen80-height);
  max-height: var(--panel-screen80-height);
  flex: 0 0 auto;
}

.panel.panel-screen90 {
  height: var(--panel-screen90-height);
  max-height: var(--panel-screen90-height);
  flex: 0 0 auto;
}

.file-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-weight: 650;
}

.file-link:hover {
  color: var(--accent-2);
  text-decoration: none;
}

.file-link svg {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
}

.diff-table {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  background: #f6f8fa;
  border-radius: 0;
  min-width: 0;
}

.diff-sbs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-width: 0;
}

.diff-panel-scroll {
  overflow-x: hidden;
}

.diff-side {
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  background: #f6f8fa;
}

.diff-side + .diff-side {
  border-left: 1px solid var(--border);
}

.diff-side-inner {
  width: max-content;
  min-width: 100%;
}

.diff-ln {
  padding: 2px 10px;
  text-align: right;
  color: var(--muted);
  background: var(--bg-elev);
  user-select: none;
  font-size: 11px;
  border-right: 1px solid var(--border);
  position: sticky;
  left: 0;
  z-index: 3;
  width: 5.5em;
  min-width: 5.5em;
  box-shadow: 1px 0 0 var(--border);
}

.diff-line {
  display: grid;
  grid-template-columns: 5.5em max-content;
  width: max-content;
  min-width: 100%;
  border-bottom: 1px solid var(--border);
}

.diff-line:last-child {
  border-bottom: 0;
}

.diff-code {
  padding: 2px 10px;
  white-space: pre;
  background: #f6f8fa;
  font-family: var(--mono);
}

.diff-code.is-added {
  background: rgba(34, 197, 94, 0.14);
}

.diff-code.is-removed {
  background: rgba(239, 68, 68, 0.12);
}

.diff-code.is-empty {
  background: #f1f5f9;
  color: #94a3b8;
}

pre {
  margin: 0;
  padding: 12px;
  font-size: 12px;
  line-height: 1.5;
  border-radius: 0;
  background: #f6f8fa;
  overflow: auto;
}

code,
pre code {
  font-family: var(--mono);
}

.code-wrap {
  display: flex;
  width: max-content;
  min-width: 100%;
  background: #f6f8fa;
}

.code-ln {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--bg-elev);
  color: var(--muted);
  border-right: 1px solid var(--border);
  user-select: none;
  text-align: right;
  min-width: 5.5em;
}

.code-ln pre {
  padding: 12px 10px;
  background: transparent;
  overflow: visible;
}

.code-pre {
  background: transparent;
  overflow: visible;
  flex: 0 0 auto;
}

.article {
  padding: 12px;
}

.article > :first-child {
  margin-top: 0;
}

.article h1,
.article h2,
.article h3 {
  margin: 16px 0 8px;
  line-height: 1.25;
}

.article h1 {
  font-size: 20px;
}

.article h2 {
  font-size: 16px;
}

.article h3 {
  font-size: 14px;
}

.article p {
  margin: 10px 0;
}

.article ul,
.article ol {
  padding-left: 18px;
}

.article li {
  margin: 4px 0;
}

.article blockquote {
  margin: 12px 0;
  padding: 10px 12px;
  border-left: 3px solid rgba(37, 99, 235, 0.35);
  background: var(--bg-elev);
  border-radius: 10px;
}

.article code {
  font-size: 0.95em;
  padding: 0.15em 0.35em;
  border-radius: 6px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
}

.article pre code {
  background: transparent;
  border: 0;
  padding: 0;
}

.callout {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  border-radius: 12px;
  padding: 12px;
  margin: 12px 0;
}

.callout strong {
  display: block;
  margin-bottom: 6px;
}

.error {
  border-color: rgba(220, 38, 38, 0.35);
  background: rgba(220, 38, 38, 0.06);
}

table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--border);
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  vertical-align: top;
}

th {
  background: var(--bg-elev);
  font-weight: 750;
  color: var(--fg);
}

tr:last-child td {
  border-bottom: 0;
}

.footer {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 14px 16px 14px;
  margin-top: auto;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}
