/* ============================================================
   AADARSH AGARWAL - RESPONSIVE STYLESHEET
   Preserves minimalist academic aesthetic
   ============================================================ */

/* ========================================
   RESET & BASE
   ======================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 320px;
  background-color: #FFFFFA;
  margin: 0;
  padding: 0;
}

img {
  max-width: 100%;
  height: auto;
}

.hero-photo {
  display: block;
  width: min(840px, 100%);
  height: auto;
  margin-top: 32px;
}

/* Global hyperlink color — UChicago maroon. !important is required to
   override the dozens of inline `style="color: #000"` declarations
   scattered across essay templates and nav blocks. The nav-button rule
   below has higher specificity AND its own !important, so it correctly
   keeps its cream label colour on top of this. */
a {
  color: #800000 !important;
}

/* ========================================
   DESKTOP LAYOUT IMPROVEMENTS
   ======================================== */

/* Center content with max-width on desktop */
body > table {
  max-width: 1100px;
  margin: 0 auto;
  padding: 40px;
}

/* Better spacing for main content */
body > table > tbody > tr > td[valign="top"]:first-child {
  padding-right: 60px;
}

/* Sidebar styling */
body > table > tbody > tr > td[valign="top"][style*="width: 200px"] {
  padding-top: 10px;
}

/* ========================================
   TYPOGRAPHY
   ======================================== */

/* Desktop */
@media screen and (min-width: 768px) {
  body { font-size: 18px; }
}

/* Mobile */
@media screen and (max-width: 767px) {
  body {
    font-size: 16px;
    line-height: 1.5;
  }
}

/* ========================================
   HOME PAGE
   ======================================== */

/* Mobile: Transform table to stacked layout */
@media screen and (max-width: 767px) {
  /* Make outer table behave like block elements */
  body > table,
  body > table > tbody,
  body > table > tbody > tr,
  body > table > tbody > tr > td {
    display: block !important;
    width: 100% !important;
  }

  /* Main content cell */
  body > table > tbody > tr > td[valign="top"]:first-child {
    padding: 15px !important;
  }

  /* Sidebar cell - moves below content */
  body > table > tbody > tr > td[valign="top"][style*="width: 200px"] {
    width: 100% !important;
    text-align: left !important;
    padding: 15px !important;
    border-top: 1px solid #eee;
    margin-top: 20px;
  }

  /* Navigation links become horizontal */
  body > table > tbody > tr > td[valign="top"][style*="width: 200px"] p {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px 20px !important;
  }

  /* Hide line breaks in nav */
  body > table > tbody > tr > td[valign="top"][style*="width: 200px"] p br {
    display: none !important;
  }

  /* Profile section - stack image and text */
  #home-section table,
  #home-section table tbody,
  #home-section table tbody tr,
  #home-section table tbody tr td {
    display: block !important;
    width: 100% !important;
  }

  /* Profile image - scale down on mobile */
  #home-section img[src="profile.jpg"] {
    width: 180px !important;
    height: 180px !important;
  }

  .hero-photo {
    width: 100%;
    margin-top: 24px;
  }
}

/* ========================================
   KNOWLEDGE PAGE
   ======================================== */

@media screen and (max-width: 767px) {
  body > h1 {
    font-size: 24px;
    padding: 0 15px;
  }

  body > a[href="index.html"] {
    display: block;
    padding: 0 15px;
  }

  /* Quote paragraphs */
  body > p[style*="font-size: 18px"] {
    padding: 0 15px;
    font-size: 16px !important;
  }

  /* Let text wrap naturally - hide forced breaks */
  body > p[style*="font-size: 18px"] br {
    display: inline;
  }

  body > p[style*="font-size: 18px"] br::before {
    content: " ";
  }
}

/* ========================================
   THOUGHTS PAGES
   ======================================== */

@media screen and (max-width: 767px) {
  div[style*="max-width: 800px"] {
    padding: 15px !important;
    max-width: 100% !important;
  }

  div[style*="max-width: 800px"] h1 {
    font-size: 22px !important;
    line-height: 1.3 !important;
  }

  /* Date line */
  div[style*="max-width: 800px"] p[style*="font-size: 16px"] {
    font-size: 14px !important;
  }

  /* Content area */
  div[style*="line-height: 1.6"] {
    font-size: 16px !important;
    line-height: 1.65 !important;
  }
}

/* ========================================
   NAV BUTTONS — UChicago maroon chiselled buttons
   One hue (UChicago primary maroon #800000), warm-shifted frame, cream
   label. 3px chiselled bevel — six layered inset shadows per button,
   each layer one shade closer to the face. Buttons sit completely
   flush: <br> tags between links are hidden so there's no line-height
   gap, and `a + br + a { margin-top: -1px }` collapses adjacent
   1px frames into a single shared edge.
   ======================================== */

/* Kill the <br> tags entirely — block-level <a> already break to new
   lines; the <br> was injecting an empty inline line ~22px tall. */
body > table > tbody > tr > td[valign="top"][style*="width: 200px"] p br {
  display: none;
}

body > table > tbody > tr > td[valign="top"][style*="width: 200px"] p a {
  display: block;
  width: 130px;
  margin: 0 0 0 auto;
  padding: 4px 12px;
  font-size: 16px;
  text-align: right;
  text-decoration: none !important;
  color: #fffcef !important;
  background: #800000;
  border: 1px solid #1a0000;
  border-radius: 0;
  box-shadow:
    inset 1px 1px 0 #c46060,
    inset 2px 2px 0 #a83838,
    inset 3px 3px 0 #8c1818,
    inset -1px -1px 0 #1a0000,
    inset -2px -2px 0 #4a0000,
    inset -3px -3px 0 #6a0000;
}

/* Collapse the 1px frame where adjacent buttons meet. Selector chains
   through the (now display:none) <br> without HTML edits. */
body > table > tbody > tr > td[valign="top"][style*="width: 200px"] p a + br + a {
  margin-top: -1px;
}

body > table > tbody > tr > td[valign="top"][style*="width: 200px"] p a:hover {
  text-decoration: underline !important;
}

body > table > tbody > tr > td[valign="top"][style*="width: 200px"] p a:active {
  background: #660000;
  box-shadow:
    inset 1px 1px 0 #1a0000,
    inset 2px 2px 0 #4a0000,
    inset 3px 3px 0 #6a0000,
    inset -1px -1px 0 #c46060,
    inset -2px -2px 0 #a83838,
    inset -3px -3px 0 #8c1818;
  /* Outer dimensions constant; label shifts +1px right, +1px down */
  padding: 5px 11px 3px 13px;
}

@media screen and (max-width: 767px) {
  body > table > tbody > tr > td[valign="top"][style*="width: 200px"] p a {
    display: inline-block;
    width: auto;
    margin: 0;
  }
  /* Horizontal flex row on mobile — undo the vertical-stack overlap and
     the right-anchored auto margin. */
  body > table > tbody > tr > td[valign="top"][style*="width: 200px"] p a + br + a {
    margin-top: 0;
  }
}

/* ========================================
   TOUCH DEVICE OPTIMIZATIONS
   ======================================== */

@media (hover: none) and (pointer: coarse) {
  /* Ensure tap targets are large enough */
  a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* Body paragraph links: keep inline, default tap behaviour */
  p a {
    min-height: auto;
    display: inline;
  }

  /* Nav buttons: stay block-like so the bevel renders, but keep tappable */
  body > table > tbody > tr > td[valign="top"][style*="width: 200px"] p a {
    display: inline-block;
    min-height: 44px;
    align-items: unset;
  }
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.mobile-only {
  display: none;
}

.desktop-only {
  display: block;
}

@media screen and (max-width: 767px) {
  .mobile-only {
    display: block;
  }

  .desktop-only {
    display: none;
  }
}

/* ========================================
   CHIP GALLERY
   ======================================== */

.chip-gallery-page body,
body.chip-gallery-page {
  color: #181816;
}

.chip-gallery {
  max-width: 100%;
}

.chip-gallery .site-title {
  font-weight: bold;
  font-size: 22px;
  margin: 0 0 6px;
}

.gallery-header {
  border-bottom: 1px solid #d8d2c4;
  padding-bottom: 18px;
  margin-bottom: 18px;
}

.gallery-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.gallery-title-row h1 {
  font-size: 24px;
  line-height: 1.15;
  margin: 0 0 6px;
  letter-spacing: 0;
}

.gallery-status {
  margin: 0;
  color: #5f5a50;
  font-size: 15px;
  max-width: 680px;
}

.mode-switch {
  display: inline-flex;
  border: 1px solid #251715;
  background: #fffaf0;
  flex: 0 0 auto;
}

.mode-button,
.gallery-reset,
.chip-actions button,
.chip-link-button,
.detail-close {
  min-height: 34px;
  border: 1px solid #251715;
  background: #fffaf0;
  color: #251715 !important;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none !important;
}

.mode-button {
  border-width: 0;
  padding: 6px 12px;
}

.mode-button + .mode-button {
  border-left: 1px solid #251715;
}

.mode-button.active {
  background: #800000;
  color: #fffcef !important;
}

.gallery-controls {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) repeat(6, minmax(118px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  margin: 0 0 14px;
}

.control-field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.control-field span {
  font-size: 12px;
  color: #5f5a50;
}

.control-field input,
.control-field select {
  width: 100%;
  min-height: 36px;
  border: 1px solid #b9b09f;
  background: #fffef8;
  color: #181816;
  border-radius: 0;
  padding: 6px 8px;
  font: inherit;
  font-size: 14px;
}

.gallery-reset {
  padding: 6px 12px;
  background: #f4efe4;
}

.gallery-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  margin: 12px 0 16px;
  color: #5f5a50;
  font-size: 15px;
}

.gallery-summary strong {
  color: #181816;
}

.chip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.chip-card {
  display: grid;
  grid-template-rows: 150px 1fr;
  border: 1px solid #cfc6b5;
  border-radius: 6px;
  background: #fffef8;
  overflow: hidden;
  min-width: 0;
}

.chip-image-slot {
  position: relative;
  min-height: 150px;
  background: #ece7db;
  overflow: hidden;
}

.chip-image-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chip-image-slot-empty {
  display: flex;
  align-items: end;
  padding: 10px;
  background:
    linear-gradient(90deg, rgba(128, 0, 0, 0.22) 1px, transparent 1px),
    linear-gradient(0deg, rgba(15, 118, 110, 0.2) 1px, transparent 1px),
    linear-gradient(135deg, #f6f0e3, #d9e4dd);
  background-size: 22px 22px, 22px 22px, auto;
}

.chip-image-slot-empty span {
  display: inline-block;
  max-width: 100%;
  padding: 3px 6px;
  background: rgba(255, 254, 248, 0.92);
  border: 1px solid #b9b09f;
  color: #514c43;
  font-size: 12px;
}

.chip-card-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  min-width: 0;
}

.chip-card-meta {
  color: #686258;
  font-size: 13px;
  line-height: 1.3;
}

.chip-card h2 {
  font-size: 17px;
  line-height: 1.25;
  margin: 0;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.gallery-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.gallery-tag {
  border: 1px solid #c7bca9;
  background: #f7f2e8;
  color: #2f2d29;
  border-radius: 3px;
  padding: 2px 6px;
  font-size: 12px;
  line-height: 1.35;
}

.chip-idea {
  margin: 0;
  color: #383530;
  font-size: 14px;
  line-height: 1.45;
}

.chip-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
  padding-top: 4px;
}

.chip-actions button,
.chip-link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 9px;
  line-height: 1.2;
}

.gallery-empty {
  border: 1px solid #cfc6b5;
  background: #fffef8;
  border-radius: 6px;
  padding: 18px;
  max-width: 720px;
}

.gallery-empty h2 {
  font-size: 18px;
  margin: 0 0 8px;
}

.gallery-empty p {
  margin: 0;
  color: #514c43;
  line-height: 1.5;
}

.gallery-detail {
  width: min(820px, calc(100% - 30px));
  max-height: min(720px, calc(100vh - 30px));
  border: 1px solid #251715;
  border-radius: 6px;
  background: #fffef8;
  color: #181816;
  padding: 22px;
}

.gallery-detail::backdrop {
  background: rgba(24, 24, 22, 0.45);
}

.detail-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  padding: 0;
  font-size: 20px;
}

.gallery-detail h2 {
  font-size: 22px;
  line-height: 1.25;
  margin: 0 44px 6px 0;
}

.gallery-detail h3 {
  font-size: 16px;
  margin: 18px 0 8px;
}

.detail-image-slot {
  height: 220px;
  min-height: 220px;
  margin: 12px 0 16px;
  border: 1px solid #cfc6b5;
  border-radius: 6px;
}

.detail-meta {
  color: #686258;
  margin: 0 0 14px;
}

.detail-facts {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 6px 12px;
  border-top: 1px solid #ded6c7;
  border-bottom: 1px solid #ded6c7;
  padding: 12px 0;
  margin: 14px 0;
}

.detail-facts dt {
  color: #686258;
}

.detail-facts dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.detail-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.evidence-list {
  padding-left: 20px;
  margin: 0;
  color: #383530;
}

.evidence-list li {
  margin-bottom: 6px;
}

.chip-detail-page {
  color: #181816;
}

.paper-detail {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.paper-detail a {
  color: #0f5f83;
}

.paper-detail-header {
  border-bottom: 1px solid #cfc6b5;
  padding-bottom: 16px;
  margin-bottom: 18px;
}

.paper-detail-header h1 {
  max-width: 820px;
  font-size: 34px;
  line-height: 1.1;
  letter-spacing: 0;
  margin: 8px 0 12px;
}

.paper-detail-figure {
  margin: 0 0 24px;
  border: 1px solid #cfc6b5;
  background: #fffef8;
}

.paper-detail-figure img {
  display: block;
  width: 100%;
  max-height: 560px;
  object-fit: contain;
  background: #fff;
}

.paper-detail-figure figcaption {
  border-top: 1px solid #ded6c7;
  color: #383530;
  font-size: 14px;
  line-height: 1.45;
  padding: 12px 14px;
}

.paper-detail-section {
  margin: 22px 0;
}

.paper-detail-section h2 {
  font-size: 18px;
  line-height: 1.25;
  margin: 0 0 8px;
}

.paper-detail-section p {
  max-width: 820px;
  line-height: 1.55;
  margin: 0 0 10px;
}

@media screen and (max-width: 1100px) {
  .gallery-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .control-field-search {
    grid-column: 1 / -1;
  }
}

@media screen and (max-width: 767px) {
  .gallery-title-row {
    display: grid;
  }

  .mode-switch {
    width: 100%;
  }

  .mode-button {
    flex: 1 1 50%;
  }

  .gallery-controls {
    grid-template-columns: 1fr;
  }

  .chip-grid {
    grid-template-columns: 1fr;
  }

  .detail-facts {
    grid-template-columns: 1fr;
  }

  .gallery-detail {
    padding: 18px;
  }

  .paper-detail {
    width: min(100% - 22px, 980px);
    padding-top: 18px;
  }

  .paper-detail-header h1 {
    font-size: 25px;
  }
}
