:root {
  --bg: #f5f6f8;
  --panel: #fff;
  --line: #d9dee7;
  --text: #18202a;
  --muted: #667085;
  --accent: #315efb;
  --soft: #eef2ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font:
    15px/1.65 system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

header {
  position: sticky;
  top: 0;
  background: #111827;
  color: #fff;
  padding: 14px 20px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header .link {
  cursor: pointer;
}

header button,
header input[type="file"] + label {
  border: 1px solid #475569;
  background: #1f2937;
  color: #fff;
  border-radius: 7px;
  padding: 7px 11px;
  cursor: pointer;
  font: 13.33px Arial;
}

header button:hover,
header input[type="file"] + label:hover {
  background: #334155;
}

header h1 {
  margin: 0;
  padding: 0;
  color: #fff;
  font-size: 15px;
  font-weight: bolder;
}

header .site-logo {
  height: 30px;
  width: auto;
  margin-right: 8px;
  vertical-align: bottom;
}

.eyebrow {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #aeb6c4;
}

main {
  max-width: 1050px;
  margin: 0 auto;
  padding: 25px 18px 70px;
}

.subject-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.subject-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: 0 6px 20px rgba(20, 28, 40, 0.05);
}
.subject-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e6e9ee;
}
.subject-head h2 {
  margin: 0;
  font-size: 20px;
}
.subject-head span {
  color: var(--muted);
}
.subject-count {
  color: var(--muted);
  font-size: 12px;
}
.class-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.class-button {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 76px;
  padding: 12px 14px;
  border: 1px solid #cfd6e1;
  border-radius: 10px;
  background: #fff;
  text-decoration: none;
  color: inherit;
  transition:
    border-color 0.15s,
    box-shadow 0.15s,
    transform 0.15s;
}
.class-button:hover {
  border-color: #93a5e9;
  box-shadow: 0 4px 12px rgba(49, 94, 251, 0.1);
  transform: translateY(-1px);
}
.class-grade {
  font-weight: 750;
  font-size: 16px;
}
.class-title {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

.card,
article,
.toc {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin: 10px;
  box-shadow: 0 6px 20px rgba(20, 28, 40, 0.05);
}

.toc {
  margin: 18px 0;
}
.toc ul {
  margin: 4px 0;
  padding-left: 22px;
}
.toc a {
  color: #315efb;
}

.toc .indent-1 {
  margin-left: 22px;
}
.toc .indent-2 {
  margin-left: 44px;
}
.toc .indent-3 {
  margin-left: 55px;
}

.chapter-select .indent-1 {
  margin-left: 0px;
}
.chapter-select .indent-2 {
  margin-left: 22px;
}
.chapter-select .indent-3 {
  margin-left: 33px;
}

summary {
  cursor: pointer;
}

a {
  text-decoration: none;
  color: inherit;
}

article h2,
article h3,
article h4 {
  scroll-margin-top: 80px;
}

.scrollable {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.scrollable table {
  width: 100%;
  border-collapse: collapse;
}
.scrollable th,
.scrollable td {
  white-space: normal;
}

.scrollable:has(> mjx-container):not(.math .scrollable) {
  display: inline-block;
  max-width: 100%;
  width: max-content;
  white-space: nowrap;
  vertical-align: middle;
}

table {
  border-collapse: collapse;
  width: 100%;
  margin: 14px 0;
}

th,
td {
  border: 1px solid #cfd5df;
  padding: 8px;
  vertical-align: top;
}

.math {
  background: #f4f6ff;
  padding: 8px;
  border-radius: 7px;
  overflow: visible;
  max-width: 100%;
  margin: 5px;
  print-color-adjust: exact;
}
.math .MathJax,
.math mjx-container {
  max-width: 100%;
  overflow: visible;
}

.definition {
  border-left: 4px solid #7d8796;
  background: #f7f8fa;
  padding: 9px 12px;
  margin: 10px 0;
  print-color-adjust: exact;
}

article button,
article select,
.map-overlay-controls .map-zoom {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  padding: 7px 10px;
}

article button:hover,
article select:hover,
.map-overlay-controls .map-zoom {
  border-color: #93a5e9;
  box-shadow: 0 4px 12px rgba(49, 94, 251, 0.1);
  transform: translateY(-1px);
}

.code-wrapper {
  margin: 16px 0;
  padding: 0;

  background: #fff;

  border: 1px solid #d0d7de;
  border-left: 4px solid #04aa6d;

  border-radius: 8px;
  overflow: hidden;

  position: relative;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;

  height: 44px;
  padding: 0 12px 0 16px;

  background: #f3f3f3;
  border-bottom: 1px solid #d6d6d6;
}

.code-language {
  display: flex;
  align-items: center;
  gap: 8px;

  font-weight: 700;
  color: #666;
}

.code-copy {
  padding: 4px 9px;

  border: 1px solid #ccc;
  border-radius: 5px;

  background: #fff;
  color: #555;

  font-size: 12px;
  cursor: pointer;

  transition:
    background 0.15s,
    border-color 0.15s;
}

.code-copy:hover {
  background: #f8f8f8;
  border-color: #aaa;
}

.code-copy.copied {
  color: #04aa6d;
  border-color: #04aa6d;
}
.code-icon {
  padding: 0 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  transform: scaleX(0.7);
  user-select: none;
}

.code-wrapper pre.code-block {
  margin: 0 !important;
  padding: 16px !important;

  background: #fff !important;

  overflow-x: auto;
}

.code-wrapper pre.code-block code {
  display: block;

  margin: 0;
  padding: 0;

  background: transparent !important;
  border: none !important;

  font-family: Consolas, "Courier New", monospace;
  font-size: 14px;
  line-height: 1.6;

  white-space: pre;
}

.area {
  fill: rgba(0, 0, 0, 0);
  stroke: rgba(0, 0, 0, 0);
  stroke-width: 0;
}

.area.hover-visible.hovered,
.area.visible {
  fill: rgba(255, 0, 0, 0.1);
  stroke: rgba(255, 0, 0, 0.3);
  stroke-width: 2px;
}

.map-point {
  background-color: red;
  border: solid 2px white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);

  position: absolute;

  width: 14px;
  height: 14px;
  border-radius: 50%;
}

.map-point.invisible,
.map-label.invisible,
.map-label.in-quiz {
  display: none;
}

.map-label {
  position: absolute;
  background-color: rgba(17, 24, 39, 0.92);
  color: white;
  border-radius: 4px;
  transform: translate(9px, -100%);
  padding: 3px 6px;
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
  border: 1px solid #d9dee7;
  z-index: 3;
}

.map-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.map-box {
  position: relative;
  transition: width 0.5s ease;
}

.map-box svg image {
  clip-path: inset(0 round 12px);
}

.map-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.map-header h3 {
  margin: 0;
  flex: 0 0 auto;
  white-space: nowrap;
}

.map-scroll {
  user-select: none;
  overflow: scroll;
  aspect-ratio: 1;
}

.map-controls {
  display: flex;
  align-items: center;
  gap: 8px;

  flex: 1 1 auto;
  min-width: 0;

  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;

  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.map-controls > * {
  flex: 0 0 auto;
}

.map-overlay-controls {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 3;
}

.map-overlay-controls .map-zoom {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  text-align: center;
  align-items: center;
  pointer-events: auto;
  cursor: pointer;
  padding: 0;
  user-select: none;
}

.outer-map {
  position: relative;
}

.area:not(.showArea),
.map-point:not(.showArea),
.map-label:not(.showArea) {
  display: none;
}

code.inline-code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.9em;
  background: #f1f1f1;
  padding: 2px 5px;
  border-radius: 4px;
  border: 1px solid #ddd;
  white-space: pre-wrap;
  overflow-wrap: anywhere !important;
}

@media screen and (min-width: 900px) {
  .map-scroll {
    overflow: hidden;
    aspect-ratio: unset;
  }
  .map-overlay-controls {
    display: none;
  }
  .map-box {
    width: 100% !important;
  }
}

@media screen and (max-width: 800px) {
  .chart {
    width: 100% !important;
  }
  .chart-table {
    width: 100% !important;
  }
}

@media screen and (max-width: 520px) {
  .subject-box {
    padding: 14px;
  }
  .class-buttons {
    grid-template-columns: 1fr;
  }
  .class-button {
    min-height: 64px;
  }
  article {
    margin: 0;
    border-radius: 0;
  }
  img {
    width: 100%;
  }
  .scrollable .chart {
    width: 150% !important;
  }
}

@media print {
  body {
    background-color: #ffffff;
  }

  header {
    display: none;
  }

  article {
    background: #ffffff;
    border: none;
    border-radius: 0;
    padding: 0;
    margin: 0;
    box-shadow: none;
  }

  details.toc {
    display: none;
  }

  .scrollable,
  .scrollable math,
  .scrollable .chart,
  .scrollable table,
  .scrollable .vocabulary {
    max-width: 100% !important;
    overflow: hidden !important;
  }

  dialog {
    display: none;
  }

  .hide-print {
    display: none;
  }
}
