/* Modern CSS for Invent Your Own Computer Games with Python, 4th Edition */

/* ============================================
   CSS Reset & Base Styles
   ============================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   Typography & Body Styles
   ============================================ */

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
               'Ubuntu', 'Cantarell', 'Helvetica Neue', sans-serif;
  font-size: 1.125rem;
  line-height: 1.75;
  color: #2c3e50;
  background-color: #ffffff;
  padding: 2rem 1.5rem;
}

@media (min-width: 768px) {
  body {
    padding: 3rem 2rem;
  }
}

/* Main chapter container, kept to a comfortable measure. */
.calibre {
  max-width: 55rem;
  margin: 0 auto;
}

/* ============================================
   Headings
   ============================================ */

h1, h2, h3, h4, h5, h6 {
  font-family: 'Georgia', 'Times New Roman', serif;
  color: #1a202c;
  margin-top: 2rem;
  margin-bottom: 1rem;
  line-height: 1.3;
  font-weight: 600;
}

h1 {
  font-size: 2.5rem;
  margin-top: 0;
  padding-bottom: 1rem;
  border-bottom: 3px solid #3498db;
  color: #2c5282;
}

/* Chapter opener: big numeral above the title. */
h1 .chapternum {
  display: block;
  font-size: 3.5rem;
  line-height: 1;
  color: #3498db;
}

h1 .chaptertitle {
  display: block;
}

h2 {
  font-size: 2rem;
  margin-top: 3rem;
  padding-top: 1rem;
  color: #2d3748;
  border-top: 1px solid #e2e8f0;
}

h3 {
  font-size: 1.5rem;
  color: #4a5568;
}

h4 {
  font-size: 1.25rem;
  color: #4a5568;
}

/* ============================================
   Paragraphs & Text
   ============================================ */

p {
  margin-bottom: 1.5rem;
}

/* Calibre's page-break markers carry no content. */
span[data-pagebreak] {
  display: none;
}

/* ============================================
   Code Blocks & Inline Code
   ============================================ */

code {
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  background-color: #f7fafc;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.95em;
  color: #d73a49;
  border: 1px solid #e2e8f0;
}

pre {
  background-color: #ffffff;
  color: #2c3e50;
  padding: 1.5rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  font-size: 0.95rem;
  line-height: 1.5;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  border: 1px solid #e2e8f0;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

pre code {
  background-color: transparent;
  color: inherit;
  padding: 0;
  border: none;
  font-size: inherit;
}

/* Text the reader types is bold inside listings and shell transcripts. */
pre strong {
  color: #1a202c;
  font-weight: 700;
}

/* ============================================
   Tables
   ============================================ */

table {
  width: 100%;
  border-collapse: collapse;
  margin: 2rem 0;
  background-color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  border-radius: 0.5rem;
  overflow: hidden;
}

thead {
  background-color: #f8f9fa;
  color: #2c3e50;
}

th {
  padding: 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.95rem;
}

td {
  padding: 1rem;
  border-bottom: 1px solid #e2e8f0;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background-color: #f7fafc;
  transition: background-color 0.2s ease;
}

tbody tr:nth-child(even) {
  background-color: #f8fafc;
}

.tablecap {
  font-size: 0.95rem;
  color: #718096;
  margin-top: -1rem;
}

/* ============================================
   Lists
   ============================================ */

ul, ol {
  margin: 1.5rem 0;
  padding-left: 2rem;
}

li {
  margin-bottom: 0.5rem;
  line-height: 1.8;
}

li::marker {
  color: #3498db;
}

li ul, li ol {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

/* Hanging-indent definitions (the Bagels clue legend, glossary terms). */
.hang, .term, .termlist {
  padding-left: 2rem;
  text-indent: -2rem;
  margin-bottom: 0.75rem;
}

/* ============================================
   Links
   ============================================ */

a {
  color: #3498db;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: all 0.3s ease;
  font-weight: 500;
}

a:hover {
  color: #2980b9;
  border-bottom-color: #2980b9;
}

a:visited {
  color: #8e44ad;
}

/* ============================================
   Sidebars, Notes & Callouts
   ============================================ */

.sidebar {
  background-color: #f0f9ff;
  border-left: 4px solid #3498db;
  padding: 1.25rem 1.5rem;
  margin: 2rem 0;
  border-radius: 0.25rem;
}

.sidebar-title {
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 0.75rem;
  color: #2c5282;
}

.sidebar ul, .sidebar p:last-child {
  margin-bottom: 0;
}

.note, .note-txt {
  background-color: #fef3c7;
  border-left: 4px solid #f59e0b;
  padding: 1rem 1.5rem;
  margin: 2rem 0;
  border-radius: 0.25rem;
}

.note-txt {
  margin-bottom: 1.5rem;
}

.sidenote {
  font-size: 0.95rem;
  color: #4a5568;
  border-left: 3px solid #cbd5e1;
  padding-left: 1rem;
}

/* ============================================
   Images & Figures
   ============================================ */

img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 2rem auto;
}

figure {
  margin: 2rem 0;
  text-align: center;
}

figure img {
  margin: 0 auto;
}

figcaption {
  margin-top: 0.75rem;
  font-size: 0.95rem;
  color: #718096;
}

/* ============================================
   "Other books" promo box
   ============================================ */

.otherbooks {
  background-color: #eeeddd;
  font-family: inherit;
  font-size: 0.95rem;
  padding: 1rem;
  margin: 0 auto 2rem auto;
  max-width: 55rem;
  border-radius: 0.5rem;
  text-align: center;
}

.otherbooks img.cover {
  display: inline-block;
  height: 150px;
  width: auto;
  margin: 0.25rem;
  border: 1px solid #000;
  vertical-align: bottom;
}

/* ============================================
   Chapter navigation (Prev | Next)
   ============================================ */

body > a {
  display: inline-block;
  margin-bottom: 1rem;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 768px) {
  body {
    font-size: 1rem;
  }

  h1 {
    font-size: 2rem;
  }

  h1 .chapternum {
    font-size: 2.5rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  h3 {
    font-size: 1.25rem;
  }

  pre {
    padding: 1rem;
    font-size: 0.8125rem;
  }

  table {
    font-size: 0.875rem;
  }

  th, td {
    padding: 0.75rem 0.5rem;
  }

  .otherbooks img.cover {
    height: 110px;
  }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
  body {
    color: #000;
    background: #fff;
    font-size: 12pt;
    line-height: 1.5;
  }

  .otherbooks {
    display: none;
  }

  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid;
    color: #000;
  }

  pre, figure, table {
    page-break-inside: avoid;
  }

  a {
    color: #000;
    text-decoration: underline;
  }

  a[href^="http"]:after {
    content: " (" attr(href) ")";
  }

  pre {
    border: 1px solid #999;
    background: #f5f5f5;
    box-shadow: none;
  }
}

/* ============================================
   Accessibility
   ============================================ */

*:focus-visible {
  outline: 3px solid #3498db;
  outline-offset: 2px;
}

/* ============================================
   Dark Mode
   ============================================ */

@media (prefers-color-scheme: dark) {
  body {
    background-color: #1a202c;
    color: #e2e8f0;
  }

  h1, h2, h3, h4, h5, h6 {
    color: #f7fafc;
  }

  h1 {
    color: #90cdf4;
  }

  code {
    background-color: #2d3748;
    color: #fbbf24;
    border-color: #4a5568;
  }

  pre {
    background-color: #0f172a;
    color: #e2e8f0;
    border-color: #334155;
  }

  pre strong {
    color: #ffffff;
  }

  table {
    background-color: #2d3748;
  }

  thead {
    background-color: #374151;
    color: #e2e8f0;
  }

  tbody tr:hover {
    background-color: #374151;
  }

  tbody tr:nth-child(even) {
    background-color: #1f2937;
  }

  td {
    border-color: #4a5568;
  }

  a {
    color: #60a5fa;
  }

  a:hover {
    color: #93bbfc;
    border-bottom-color: #93bbfc;
  }

  a:visited {
    color: #a78bfa;
  }

  .sidebar {
    background-color: #1e293b;
    border-left-color: #3b82f6;
  }

  .sidebar-title {
    color: #90cdf4;
  }

  .note, .note-txt {
    background-color: #451a03;
    border-left-color: #f59e0b;
  }

  .sidenote {
    color: #cbd5e1;
    border-left-color: #4a5568;
  }

  figcaption, .tablecap {
    color: #a0aec0;
  }

  .otherbooks {
    background-color: #2d3748;
  }

  .otherbooks img.cover {
    border-color: #4a5568;
  }
}
