* {
  box-sizing: border-box;
}

:root {
  /* iOS only reports non-zero safe-area-inset-* once viewport-fit=cover is set on the
     viewport meta tag - see fixIOSViewportBug() in main.js for the related height fix. */
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100vh;
  height: 100lvh; /* large-viewport-height unit - no dynamic browser chrome to track in standalone mode, so this avoids a first-paint race condition 100dvh seems to have in portrait on iOS */
  overflow: hidden;
  background: #000000;
  color: #e8e8f0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* Guards against Android Chrome's "font boosting" auto-inflating text size - see
     the matching rule in portal.css for the page where this actually bites (expansion.html). */
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

#app {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100lvh; /* large-viewport-height unit - no dynamic browser chrome to track in standalone mode, so this avoids a first-paint race condition 100dvh seems to have in portrait on iOS */
}

#triangleCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* suppress iOS's long-press magnifier/callout over the triangle */
}

#triangleCanvas:active {
  cursor: grabbing;
}

#toolbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start; /* keep the title/reset button pinned to the top even when the shading card grows taller/wraps */
  gap: 16px;
  padding: calc(10px + var(--safe-area-top, 0px)) calc(16px + var(--safe-area-right, 0px)) 10px calc(16px + var(--safe-area-left, 0px));
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0));
  pointer-events: none;
  z-index: 10;
}

#toolbar > * {
  pointer-events: auto;
}

#toolbar,
#toolbar * {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* suppress iOS's long-press text-selection magnifier on the home link/title/reset button */
}

#toolbar h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: #f0c93a;
  letter-spacing: 0.5px;
}

.home-link {
  font-size: 13px;
  line-height: 1.2;
  color: #ffffff;
  text-decoration: none;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid #22e8f0;
  background: #171a28;
}

@media (hover: hover) and (pointer: fine) {
  .home-link:hover {
    background: #2a2f47;
    color: #ffffff;
  }
}

.shading-card {
  margin-left: auto;
  background: rgba(18, 20, 32, 0.96);
  border: 1px solid #22e8f0;
  border-radius: 10px;
  padding: 6px 14px 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), 0 0 8px rgba(34, 232, 240, 0.7), 0 0 18px rgba(34, 232, 240, 0.45);
  font-size: 13px;
  color: #ffffff;
}

.shading-card-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shading-card legend {
  padding: 0 8px;
  color: #ffffff;
  font-weight: 600;
}

.shading-card input[type="radio"] {
  accent-color: #22e8f0;
}

.label-short {
  display: none;
}

@media (max-width: 600px) {
  /* Same shading-card controls as wide screens, just abbreviated text to save space. */
  .home-arrow,
  .label-full {
    display: none;
  }

  .label-short {
    display: inline;
  }
}

.shading-card,
.shading-card * {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* suppress iOS's long-press text-selection magnifier */
  touch-action: none; /* stop iOS intercepting pinch gestures over this element as native page zoom */
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.toolbar-group label {
  color: #a9adc1;
}

.shading-modulo-row.hidden {
  display: none;
}

.shading-swatch-row.hidden {
  display: none;
}

.shading-swatch-row input[type="color"] {
  width: 28px;
  height: 22px;
  padding: 0;
  border: 1px solid #3a3d55;
  border-radius: 4px;
  background: #171a28;
  cursor: pointer;
}

#rowInput {
  width: 90px;
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid #3a3d55;
  background: #171a28;
  color: #e8e8f0;
  font-size: 13px;
}

#shadingModulusWide {
  padding: 5px 28px 5px 12px;
  border-radius: 4px;
  border: 1px solid #3a3d55;
  background-color: #171a28;
  color: #e8e8f0;
  font-size: 13px;
  line-height: 1.2;
  font-family: inherit;
  /* iOS renders the native select arrow too dark against this dark background -
     draw our own white chevron instead of relying on the platform's own icon. */
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23ffffff' d='M4 6l4 4 4-4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 12px;
}

.shading-pattern-name {
  color: #f0c93a;
  font-style: italic;
}

.shading-pattern-name.hidden {
  display: none;
}

button {
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid #22e8f0;
  background: #171a28;
  color: #ffffff;
  font-size: 13px;
  line-height: 1.2;
  font-family: inherit;
  cursor: pointer;
}

button:hover {
  background: #2a2f47;
}

#infoCard {
  position: fixed; /* anchored to the real viewport, not #app's box (deliberately sized with 100lvh) - keeps this clear of Safari's currently-visible address bar */
  bottom: calc(16px + var(--safe-area-bottom, 0px));
  right: calc(16px + var(--safe-area-right, 0px));
  width: 420px;
  max-height: calc(100dvh - 32px - var(--safe-area-bottom, 0px)); /* dvh (not lvh) so this tracks Safari's currently-visible address bar and doesn't get clipped underneath it */
  overflow-y: auto;
  background: rgba(18, 20, 32, 0.96);
  border: 1px solid #22e8f0;
  border-radius: 10px;
  padding: 20px 24px;
  font-size: 22px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), 0 0 8px rgba(34, 232, 240, 0.7), 0 0 18px rgba(34, 232, 240, 0.45);
  z-index: 20;
}

#infoCard,
#infoCard * {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* suppress iOS's long-press text-selection magnifier */
  touch-action: pan-y; /* stop iOS intercepting pinch gestures here as native page zoom, but still allow the card's own vertical scroll */
}

@media (max-width: 600px) {
  #infoCard {
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    width: min(340px, calc(100vw - 24px));
    font-size: 16px;
    padding: 14px 16px;
  }
}

/* Landscape phones etc: short viewport regardless of width - shrink further so the card never
   gets clipped by the bottom of the screen (independent of the width-based breakpoint above). */
@media (max-height: 480px) {
  #infoCard {
    font-size: 14px;
    padding: 10px 14px;
  }
}

#infoCard.hidden {
  display: none;
}

.info-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: #ffffff;
}

.info-label {
  color: #ffffff;
}

.info-value-box {
  border: 1px solid #22e8f0;
  border-radius: 4px;
  padding: 0 12px 10px;
  margin: 0 0 10px;
  min-width: 0;
}

.info-value-box legend {
  padding: 0 8px;
  color: #ffffff;
}

.info-value {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.82em;
  color: #ffffff;
  text-align: center;
  word-break: break-all;
  background: rgba(18, 20, 32, 0.96);
  border-radius: 4px;
  padding: 8px 10px;
  max-height: 220px;
  overflow-y: auto;
}

.info-note {
  font-size: 0.68em;
  color: #ffffff;
  font-style: italic;
}

.info-sequence {
  font-size: 0.85em;
  color: #ffffff;
  background: rgba(18, 20, 32, 0.96);
  border: 1px solid #22e8f0;
  border-radius: 4px;
  padding: 0 12px 10px;
  margin-bottom: 10px;
  max-width: 100%;
  overflow-x: hidden;
  min-width: 0;
}

.info-sequence legend {
  padding: 0 8px;
  color: #ffffff;
}

.info-sequence-label {
  margin-bottom: 6px;
}

.info-sequence-label.hidden {
  display: none;
}

.info-sequence-detail {
  max-width: 100%;
  overflow-x: hidden;
  overflow-wrap: break-word;
}

.info-sequence-detail.named {
  color: #f0c93a;
  font-weight: 600;
}

.info-sequence.hidden {
  display: none;
}

#contextMenu {
  position: absolute;
  display: flex;
  flex-direction: column;
  min-width: 190px;
  background: rgba(18, 20, 32, 0.98);
  border: 1px solid #3a3d55;
  border-radius: 8px;
  padding: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 30;
}

#contextMenu,
#contextMenu * {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* suppress iOS's long-press text-selection magnifier */
  touch-action: none; /* stop iOS intercepting pinch gestures over this element as native page zoom */
}

#contextMenu.hidden {
  display: none;
}

#contextMenu button {
  background: transparent;
  border: none;
  text-align: left;
  padding: 8px 10px;
  border-radius: 5px;
  font-size: 13px;
  color: #e8e8f0;
}

@media (hover: hover) and (pointer: fine) {
  #contextMenu button:hover {
    background: #2a2f47;
  }
}

#helpModal {
  position: fixed; /* anchored to the real viewport, not #app's box (deliberately sized with 100lvh) - keeps this clear of Safari's currently-visible address bar */
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.65);
  z-index: 40;
}

#helpModal.hidden {
  display: none;
}

#helpModalCard {
  max-width: min(420px, calc(100vw - 48px));
  max-height: calc(100dvh - 48px); /* dvh (not lvh) so this tracks Safari's currently-visible address bar and doesn't get clipped underneath it */
  overflow-y: auto;
  background: rgba(18, 20, 32, 0.98);
  border: 1px solid #22e8f0;
  border-radius: 10px;
  padding: 20px 24px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 8px rgba(34, 232, 240, 0.7), 0 0 18px rgba(34, 232, 240, 0.45);
  color: #e8e8f0;
  font-size: 15px;
  line-height: 1.5;
}

#helpModalCard,
#helpModalCard * {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* suppress iOS's long-press text-selection magnifier */
  touch-action: pan-y; /* stop iOS intercepting pinch gestures here as native page zoom, but still allow the card's own vertical scroll */
}

#helpModalCard h2 {
  margin: 0 0 12px;
  font-size: 18px;
  color: #f0c93a;
}

#helpModalCard p {
  margin: 0 0 12px;
}

#helpModalCard button {
  margin-top: 4px;
}

