:root {
  --paper: #fdf7f0;
  --ink: #211d17;
  --ink-muted: rgba(33, 29, 23, 0.6);
  --accent: #b44d2b;
  --accent-soft: rgba(180, 77, 43, 0.25);
  --panel-line: rgba(33, 29, 23, 0.18);
  --dialog-bg: #fff9f2;
  --danger: #b33a2a;
  --menu-width: clamp(190px, 19vw, 240px);
  --inspector-width: clamp(240px, 24vw, 340px);
  --global-footer-height: 34px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Inter', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  font-size: 17px;
  line-height: 1.55;
}

body.error {
  display: flex;
  align-items: center;
  justify-content: center;
}

body.login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.error-panel {
  max-width: 480px;
  padding: 2rem;
  border: 1px solid var(--panel-line);
  background: var(--dialog-bg);
}

.error-panel a {
  color: var(--accent);
}

#grid-app {
  position: relative;
  min-height: 100vh;
  padding: 0;
  gap: 0;
}

body[data-page-type='plain'] #recenter-btn,
body[data-page-type='book'] #recenter-btn {
  display: none !important;
}

body[data-page-type='plain'] #menu-inspector {
  display: none !important;
}

/* Plain/book pages: let the document scroll naturally (no inner-div scroll container) */
body[data-page-type='plain'],
body[data-page-type='book'] {
  overflow-y: auto;
}

#page-menu {
  position: fixed;
  left: 0;
  top: 0;
  height: 100dvh;
  width: var(--menu-width);
  z-index: 20;
  border-right: 1px solid var(--panel-line);
  padding: clamp(0.85rem, 2vw, 1.2rem);
  background: var(--dialog-bg);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-height: 0;
  overflow-y: hidden;
}

#menu-inspector {
  margin-top: auto;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  color: inherit;
  overflow: hidden;
}

.inspector-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 100%;
  padding: 0.45rem 0.65rem;
  border: none;
  background: none;
  font: inherit;
  cursor: pointer;
  color: inherit;
}

.inspector-toggle:hover {
  color: var(--ink);
}

.inspector-toggle-label {
  display: none;
  flex: 1;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.72rem;
}

#menu-inspector.is-collapsed .inspector-toggle-label {
  display: block;
}

.inspector-toggle-icon {
  font-size: 0.85rem;
  line-height: 1;
  transition: transform 0.15s ease;
}

#menu-inspector.is-collapsed .inspector-toggle-icon {
  transform: rotate(-90deg);
}

.inspector-body {
  padding: 0 0.65rem 0.65rem;
  display: grid;
  gap: 0.55rem;
}

#menu-inspector.is-collapsed .inspector-body {
  display: none;
}

.inspector-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: inherit;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.inspector-check[hidden] {
  display: none;
}

.inspector-check input[type="checkbox"] {
  margin: 0;
  accent-color: var(--ink);
  cursor: pointer;
}

/* Game of Life tooltip */
.gol-label-wrap {
  position: relative;
  padding: 0.4rem 0.3rem;
  margin: -0.4rem -0.3rem;
}
.gol-tooltip {
  display: none;
  position: fixed;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #ccc);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  font-size: 0.7rem;
  white-space: nowrap;
  text-transform: none;
  letter-spacing: normal;
  color: var(--ink-muted);
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
  z-index: 9999;
  pointer-events: auto;
}
.gol-tooltip a {
  color: var(--ink);
  text-decoration: underline;
}

/* Game of Life transport bar */
.gol-transport {
  position: absolute;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 22;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.7rem;
  background: var(--dialog-bg);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
}
.gol-transport[hidden] {
  display: none;
}

.gol-transport-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--ink);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.12s ease;
}

.gol-transport-btn:hover:not(:disabled) {
  background: rgba(33, 29, 23, 0.08);
}

.gol-transport-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.gol-transport-btn--play {
  width: 32px;
  height: 32px;
  font-size: 1rem;
}

.gol-transport-gen {
  font-size: 0.72rem;
  color: var(--ink-muted);
  letter-spacing: 0.06em;
  margin-left: 0.2rem;
  min-width: 3.5em;
}

body.gol-active .grid-cell--gol-born {
  background: rgba(33, 29, 23, 0.12) !important;
  border-color: rgba(33, 29, 23, 0.25) !important;
  cursor: default !important;
}

/* Mobile GOL trigger button */
.gol-mobile-btn {
  display: none;
  position: absolute;
  bottom: 1.2rem;
  right: 1.2rem;
  z-index: 22;
  width: 44px;
  height: 44px;
  border: 1px solid var(--panel-line);
  border-radius: 50%;
  background: var(--dialog-bg);
  color: var(--ink-muted);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.gol-mobile-btn.is-active {
  background: var(--ink);
  color: var(--surface, #fff);
  border-color: var(--ink);
}

@media (max-width: 960px) {
  .gol-mobile-btn:not([hidden]) {
    display: flex;
  }
  /* Hide the GOL checkbox in the inspector — the mobile icon handles it */
  #gol-toggle-label {
    display: none !important;
  }
  .gol-transport {
    bottom: 4.2rem;
    padding: 0.5rem 0.8rem;
    gap: 0.55rem;
  }
  .gol-transport-btn {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }
  .gol-transport-btn--play {
    width: 40px;
    height: 40px;
    font-size: 1.15rem;
  }
  .gol-transport-gen {
    font-size: 0.78rem;
  }
}

.site-title-link {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: inherit;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.45rem 0.55rem;
  white-space: nowrap;
  overflow: hidden;
}

.site-title-link.has-favicon {
  font-size: clamp(0.62rem, 3.8vw, 0.92rem);
}

.site-favicon {
  width: 1.3rem;
  height: 1.3rem;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 2px;
}

.page-menu-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.page-menu-item {
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  padding: 0.45rem 0.55rem;
  text-align: left;
  font: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  transition: opacity 0.15s ease;
}

.page-menu-item.is-dragging {
  opacity: 0.35;
}

.page-menu-item.drag-over-above {
  border-top-color: rgba(33, 29, 23, 0.5);
}

.page-menu-item.drag-over-below {
  border-bottom-color: rgba(33, 29, 23, 0.5);
}

.page-menu-item.is-active {
  border-color: rgba(33, 29, 23, 0.42);
  background: transparent;
  position: relative;
  padding-left: 1.45rem;
}

.page-menu-item.is-active::before {
  content: '☞';
  position: absolute;
  left: 0.45rem;
  top: 50%;
  transform: translateY(-50%);
  color: inherit;
  font-size: 0.86rem;
  line-height: 1;
}

.page-menu-main {
  display: inline;
  color: inherit;
  opacity: 0.7;
  font-size: 0.88rem;
  font-weight: 500;
  line-height: 1;
}

.menu-social {
  display: flex;
  gap: 0.6rem;
  margin-top: 0;
}

.menu-social + #menu-inspector {
  margin-top: -0.6rem;
}

.menu-social__link {
  color: inherit;
  opacity: 0.5;
  transition: opacity 0.2s;
}

.menu-social__link:hover {
  opacity: 1;
}

.global-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 24;
  height: var(--global-footer-height);
  border-top: 1px solid var(--panel-line);
  background: var(--dialog-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.8rem;
  font-size: 0.74rem;
  color: var(--ink-muted);
  transform: translateY(120%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

body.footer-revealed .global-footer {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.global-footer p {
  margin: 0;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.global-footer a {
  color: var(--ink);
  text-decoration: none;
}

.global-footer a:hover {
  text-decoration: underline;
}

#grid-viewport {
  position: relative;
  border: none;
  background: var(--paper);
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  width: 100%;
  min-height: 100vh;
  height: 100vh;
  min-width: 0;
}

/* On static (non-grid) pages: release fixed-height grid constraints so the document
   scrolls naturally.  Touch-action and cursor are restored to defaults so mobile
   native scroll and pointer behaviour work correctly. */
#grid-viewport.is-static-page {
  height: auto;
  min-height: 100vh;
  overflow: visible;
  touch-action: auto;
  cursor: auto;
}

#grid-page-view,
#plain-page-view,
#book-page-view {
  width: 100%;
  height: 100%;
}

/* On static pages the inner views grow with their content instead of filling 100vh */
#grid-viewport.is-static-page #plain-page-view,
#grid-viewport.is-static-page #book-page-view {
  height: auto;
}

#grid-page-view {
  position: relative;
}

#grid-page-view[hidden],
#plain-page-view[hidden],
#book-page-view[hidden] {
  display: none !important;
}

.plain-page-view,
.book-page-view {
  padding: 0;
  overflow-y: visible;  /* body scrolls — no inner scroll container needed */
  background: inherit;
  border: 0;
  padding-left: calc(var(--menu-width) + 0.9rem);
  padding-right: 1rem;
}

.plain-page-view {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  overflow-x: hidden;
  min-width: 0;
  scroll-behavior: smooth;
  animation: plain-page-fade-in 0.25s ease-out;
  padding-bottom: 2rem;
}

@keyframes plain-page-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* plain-page-view layout */
.plain-page-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 1rem 0;
}

.plain-page-header h2 {
  flex: 1;
  margin: 0;
  padding: 0;
}

.plain-page-view h2,
.book-page-view h2 {
  margin: 0;
  padding: 0.85rem 1rem 0;
}

#plain-page-content {
  white-space: normal;
}

/* The content area itself – no white frame, inherits page background */
.plain-page-content {
  margin: 0 1rem 1rem;
  padding: 0.5rem 0;
  white-space: normal;
  min-height: clamp(180px, 40vh, 480px);
  overflow-x: auto;
  min-width: 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Public (non-admin) content typography */
.plain-page-content p,
.plain-page-content li {
  font-size: 1rem;
  line-height: 1.65;
}

.plain-page-content a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--panel-line);
  text-underline-offset: 2px;
  transition: text-decoration-color 0.15s ease;
}

.plain-page-content a:hover {
  text-decoration-color: var(--ink);
}

.plain-page-content img {
  max-width: 100%;
  height: auto;
  display: inline-block;
  vertical-align: middle;
  margin: 0.75rem 0;
  cursor: zoom-in;
}

/* Responsive embeds: iframes, videos, objects */
.plain-page-content iframe,
.plain-page-content video,
.plain-page-content embed,
.plain-page-content object {
  max-width: 100%;
  height: auto;
}

.plain-page-content pre {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.plain-page-content blockquote {
  max-width: 100%;
  margin-left: 0;
  margin-right: 0;
  padding: 0.4rem 1rem;
  border-left: 3px solid var(--panel-line);
}

.plain-page-content hr {
  border: none;
  border-top: 1px solid var(--panel-line);
  margin: 1rem 0;
}

.plain-page-content h1,
.plain-page-content h2,
.plain-page-content h3,
.plain-page-content h4 {
  word-wrap: break-word;
  overflow-wrap: break-word;
  margin-top: 1.6em;
  margin-bottom: 0.5em;
  line-height: 1.3;
}

.plain-page-content h1 { font-size: 1.65rem; }
.plain-page-content h2 { font-size: 1.35rem; }
.plain-page-content h3 { font-size: 1.15rem; }
.plain-page-content h4 { font-size: 1rem; font-weight: 600; }

/* Plain page tables – sensible base layout */
.plain-page-content table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.plain-page-content table td,
.plain-page-content table th {
  vertical-align: top;
  padding: 0.4rem 0.6rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

/* ── Responsive: stack multi-column tables on small screens ── */
@media (max-width: 640px) {
  .plain-page-content table,
  .plain-page-content tbody,
  .plain-page-content tr {
    display: block;
    width: 100%;
  }

  .plain-page-content td,
  .plain-page-content th {
    display: block;
    width: 100% !important;
    padding: 0.25rem 0;
    border: none !important;
  }

  /* View padding already handles horizontal spacing on mobile */
  .plain-page-content {
    margin: 0 0 1rem;
  }
}

.book-page-view p {
  margin: 0.6rem 1rem 1rem;
}

#grid-viewport.is-panning {
  cursor: grabbing;
}

#grid-viewport.is-static-page {
  cursor: default;
}

#grid-viewport.is-dragging-tile {
  cursor: move;
}

#grid-plane {
  position: absolute;
  inset: 0;
  transform-origin: center;
  will-change: transform;
  /* Start hidden so the browser never paints the uncentered initial frame;
     JS reveals it after the first centering pass. */
  visibility: hidden;
}

.viewport-controls {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  z-index: 2;
}
.viewport-controls[hidden] {
  display: none;
}

.jump-edge-button {
  position: absolute;
  z-index: 21;
  width: 2.2rem;
  height: 2.2rem;
  border: 1px solid var(--panel-line);
  border-radius: 50%;
  background: rgba(253, 247, 240, 0.92);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s ease, background 0.2s ease, transform 0.15s ease;
}

.jump-edge-button[hidden] {
  display: none;
}

.jump-edge-button:hover {
  opacity: 1;
  background: rgba(253, 247, 240, 1);
  transform: scale(1.12);
}

.jump-edge-button.is-active {
  opacity: 1;
  border-color: rgba(33, 29, 23, 0.5);
  background: rgba(253, 247, 240, 1);
}

.jump-edge-top {
  top: 1rem;
  left: calc(var(--menu-width) + (100% - var(--menu-width)) / 2);
  transform: translateX(-50%);
}
.jump-edge-top:hover {
  transform: translateX(-50%) scale(1.12);
}

.jump-edge-bottom {
  bottom: 1rem;
  left: calc(var(--menu-width) + (100% - var(--menu-width)) / 2);
  transform: translateX(-50%);
}
.jump-edge-bottom:hover {
  transform: translateX(-50%) scale(1.12);
}

.jump-edge-left {
  left: calc(var(--menu-width) - 1.1rem);
  top: 50%;
  transform: translateY(-50%);
}
.jump-edge-left:hover {
  transform: translateY(-50%) scale(1.12);
}

.jump-edge-right {
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
}
.jump-edge-right:hover {
  transform: translateY(-50%) scale(1.12);
}

.zoom-button {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--panel-line);
  background: rgba(253, 247, 240, 0.9);
  color: var(--ink);
  font: inherit;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.sidebar-toggle,
.sidebar-close,
.sidebar-backdrop {
  display: none;
}

.grid-cell {
  position: absolute;
  width: 236px;
  height: 236px;
  border: 1px solid rgba(33, 29, 23, 0.1);
  background: rgba(255, 255, 255, 0.3);
  color: inherit;
  padding: 0;
  display: block;
  transform: translate(-50%, -50%);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
  overflow: hidden;
  content-visibility: hidden;
  contain-intrinsic-size: 236px 236px;
}

.grid-cell__image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.grid-cell__overlay {
  position: absolute;
  inset: auto 0 0 0;
  padding: 0.7rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  background: linear-gradient(to top, rgba(16, 14, 11, 0.74), rgba(16, 14, 11, 0.35), transparent);
  color: #fdf7f0;
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}

.tag-border-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 1;
}

.grid-cell__coord {
  font-size: 0.72rem;
  color: rgba(253, 247, 240, 0.75);
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  letter-spacing: 0.08em;
}

.grid-cell__topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  pointer-events: none;
  padding: 0.35rem 0.35rem 0;
  box-sizing: border-box;
}

.grid-cell__date {
  display: block;
  width: 100%;
  text-align: center;
  color: rgba(253, 247, 240, 0.94);
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  white-space: nowrap;
  box-sizing: border-box;
  padding: 0.22rem 0.4rem;
  background: rgba(16, 14, 11, 0.36);
  border: 1px solid rgba(253, 247, 240, 0.14);
  border-radius: 0.2rem;
  font-size: 10px;
}

.grid-cell--text .grid-cell__date {
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(33, 29, 23, 0.14);
  color: rgba(33, 29, 23, 0.72);
}

.grid-cell strong,
.grid-cell em {
  font-weight: 500;
  font-size: 0.86rem;
  overflow-wrap: break-word;
  margin: 0;
}

.grid-cell em {
  color: rgba(253, 247, 240, 0.82);
  font-style: normal;
  font-size: 0.77rem;
}

.grid-cell--available {
  color: var(--ink-muted);
  background: rgba(255, 255, 255, 0.16);
  cursor: default;
}

.grid-cell--available:not(:disabled) {
  cursor: pointer;
}

.grid-cell--available .grid-cell__overlay {
  opacity: 0.72;
  background: linear-gradient(to top, rgba(33, 29, 23, 0.46), rgba(33, 29, 23, 0.08));
}

.grid-cell--landing {
  color: var(--accent);
  border-color: rgba(180, 77, 43, 0.2);
}

.grid-cell.is-visible {
  opacity: 1;
  pointer-events: auto;
  content-visibility: visible;
}

.grid-cell:disabled {
  cursor: default;
}

.grid-cell.is-current {
  color: var(--ink);
  border-color: #8fd694;
  border-width: 2px;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 0 2px rgba(143, 214, 148, 0.18);
}

.grid-cell.is-current .grid-cell__overlay,
.grid-cell:hover .grid-cell__overlay {
  opacity: 1;
}

.grid-cell.is-center {
  border-color: #8fd694;
}

.grid-cell.is-center.is-current {
  border-width: 3px;
  box-shadow: 0 0 0 3px rgba(143, 214, 148, 0.28);
}

/* Arrow inside a grid tile */
.grid-cell__arrow {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 0;
}
.grid-cell__arrow svg {
  width: 50%;
  height: 50%;
  fill: rgba(33, 29, 23, 0.55);
  transition: fill 0.2s;
}
.grid-cell:hover .grid-cell__arrow svg {
  fill: rgba(33, 29, 23, 0.75);
}
.grid-cell--arrow-only:not(:disabled) {
  cursor: default;
}
.grid-cell--arrow-only:hover .grid-cell__arrow svg {
  fill: rgba(33, 29, 23, 0.55);
}

.inspector-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0;
}

.inspector-coords {
  font-size: 0.72rem;
  font-family: 'IBM Plex Mono', monospace;
  color: inherit;
  margin: 0;
}

#mobile-banner {
  display: none;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 24px;
  z-index: 3;
  background: var(--dialog-bg);
  border-right: 1px solid var(--panel-line);
  align-items: center;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
}

.mobile-banner-text {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  color: inherit;
  -webkit-user-select: none;
  user-select: none;
}

.site-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}


.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.75rem;
  color: var(--ink-muted);
}


.is-hidden {
  display: none !important;
}

.link-button {
  border: none;
  background: none;
  padding: 0;
  text-align: left;
  font: inherit;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-size: 0.75rem;
  color: var(--ink);
  cursor: pointer;
  display: inline-block;
  text-decoration: none;
}

.link-button.subtle {
  color: inherit;
}

.link-button.danger {
  color: var(--danger);
}

.link-button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.inspector-foot {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: inherit;
}

.inspector-foot--compact {
  gap: 0.25rem;
  font-size: 0.78rem;
}

.inspector-foot--compact p {
  margin: 0;
}

.footnote {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.logout {
  margin: 0;
}

.public-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

.public-note {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.admin-link {
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-size: 0.75rem;
  color: var(--accent);
  text-decoration: none;
}

.login-panel {
  max-width: 420px;
  width: 100%;
  border: 1px solid var(--panel-line);
  background: var(--dialog-bg);
  padding: clamp(1.5rem, 4vw, 2.5rem);
}

.login-panel h1 {
  margin-top: 0;
}

.login-error {
  color: var(--danger);
  font-size: 0.9rem;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
}

label.field[hidden] {
  display: none !important;
}

label.field input,
label.field select,
label.field textarea {
  width: 100%;
  border: 1px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.65);
  padding: 0.65rem 0.85rem;
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
}

.grid-cell--text {
  background: rgba(255, 255, 255, 0.84);
}

.grid-cell--text .grid-cell__overlay {
  display: none;
}

.grid-cell__text-wrap {
  position: absolute;
  inset: 0;
  padding: 2rem 0.75rem 0.72rem;
  display: flex;
  flex-direction: column;
  gap: 0.48rem;
}

.grid-cell__text-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: rgba(33, 29, 23, 0.95);
  line-height: 1.2;
}

.grid-cell__text-body {
  position: static;
  font-size: 0.9rem;
  line-height: 1.35;
  color: rgba(33, 29, 23, 0.9);
  text-align: left;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 7;
  -webkit-box-orient: vertical;
}

.grid-cell__text-more {
  display: block;
  margin-top: auto;
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.25em;
  line-height: 1;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  background: linear-gradient(to top, rgba(33, 29, 23, 0.35) 0%, rgba(33, 29, 23, 0) 100%);
  cursor: pointer;
  padding: 0.5rem 0 0.3rem;
  margin-left: -0.75rem;
  margin-right: -0.75rem;
  margin-bottom: -0.72rem;
  transition: color 0.2s ease;
}

.grid-cell:hover .grid-cell__text-more {
  color: rgba(255, 255, 255, 1);
}

#image-preview-dialog,
#text-preview-dialog {
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  padding: clamp(1.25rem, 3vw, 2rem);
  background: var(--dialog-bg);
  color: var(--ink);
  width: min(520px, 95vw);
}

#image-preview-dialog {
  width: min(980px, 95vw);
  padding: 0;
}

#image-preview-dialog::backdrop {
  background: rgba(33, 29, 23, 0.5);
}

.image-preview-window {
  position: relative;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(320px, 1.4fr);
  grid-template-rows: 1fr;
  gap: 0;
  height: min(84vh, 720px);
  overflow: hidden;
}

.image-preview-text {
  padding: clamp(1rem, 2.4vw, 1.6rem);
  border-right: 1px solid var(--panel-line);
  overflow: auto;
  min-height: 0;
  min-width: 0;
  align-self: stretch;
}

.image-preview-text h3 {
  margin: 0.2rem 0 0.8rem;
}

#image-preview-content {
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  color: var(--ink-muted);
}

.image-preview-media {
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: rgba(33, 29, 23, 0.04);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 0.5rem;
}

#image-preview-image {
  width: 100%;
  height: 100%;
  max-height: min(80vh, 700px);
  object-fit: contain;
  cursor: zoom-in;
}

.image-preview-close {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
  z-index: 2;
}

#text-preview-dialog {
  width: min(720px, 92vw);
  padding: 0;
}

#text-preview-dialog::backdrop {
  background: rgba(33, 29, 23, 0.5);
}

/* ── Lightbox (matches ViewerJS layout) ── */
#mobile-image-dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: rgba(0, 0, 0, 0.96);
  overscroll-behavior: contain;
  overflow: hidden;
}

#mobile-image-dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
}

.mobile-image-window {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  overscroll-behavior: contain;
  transition: transform 0.22s cubic-bezier(0.22, 0.61, 0.36, 1), opacity 0.22s ease;
  will-change: transform, opacity;
}

#mobile-image-full {
  max-width: 90%;
  max-height: calc(100% - 100px);
  width: auto;
  height: auto;
  object-fit: contain;
  transform-origin: center center;
  margin-bottom: 50px;
  will-change: transform;
}

/* Close button — ViewerJS style: circle tucked into top-right corner */
.mobile-image-close {
  position: absolute;
  top: -50px;
  right: -50px;
  width: 100px;
  height: 100px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  padding: 0;
  /* push the × glyph into the visible quadrant */
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding-left: 18px;
  padding-bottom: 14px;
  transition: background-color 0.15s;
}
.mobile-image-close:hover {
  background: rgba(0, 0, 0, 0.8);
}

/* Footer: title + toolbar pinned to bottom, above browser chrome */
.mobile-image-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  text-align: center;
  z-index: 2;
  pointer-events: none;
}

.mobile-image-title {
  margin: 0 5%;
  padding: 0;
  color: #ccc;
  font-size: 12px;
  line-height: 1.4;
  opacity: 0.8;
  overflow-wrap: break-word;
  word-break: break-word;
  text-align: center;
}

.mobile-image-toolbar {
  display: inline-flex;
  gap: 3px;
  margin: 0 auto 5px;
  padding: 6px 3px;
  pointer-events: auto;
}

.mobile-image-toolbar button {
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.mobile-image-toolbar button:hover {
  background: rgba(255, 255, 255, 0.35);
}

.text-preview-window {
  position: relative;
  padding: clamp(1.2rem, 3vw, 2rem);
  max-height: min(74vh, 620px);
  overflow-y: auto;
}

.text-preview-window h3 {
  margin: 0.2rem 0 0.9rem;
}

#text-preview-content {
  white-space: pre-wrap;
}

.text-preview-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
}

/* Custom viewer close button (injected, replaces ViewerJS built-in) */
.custom-viewer-close {
  position: fixed;
  top: 0.75rem;
  right: 0.75rem;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  border: none;
  color: #fff;
  font-size: 1.5rem;
  line-height: 2.6rem;
  text-align: center;
  cursor: pointer;
  z-index: 9999;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.custom-viewer-close:active {
  background: rgba(0, 0, 0, 0.75);
}
@supports (padding-top: env(safe-area-inset-top)) {
  .custom-viewer-close {
    top: calc(0.75rem + env(safe-area-inset-top));
  }
}

@media (max-width: 960px) {
  #image-preview-dialog {
    width: 96vw;
  }

  .image-preview-window {
    display: flex;
    flex-direction: column;
    max-height: 88vh;
    overflow-y: auto;
  }

  .image-preview-window {
    height: auto;
  }

  .image-preview-media {
    position: static;
    flex: 0 0 auto;
    height: auto;
    min-height: 160px;
    overflow: hidden;
    order: -1;
  }

  #image-preview-image {
    height: auto;
    max-height: 44vh;
    width: 100%;
    object-fit: contain;
  }

  .image-preview-text {
    border-right: none;
    border-top: 1px solid var(--panel-line);
    border-bottom: none;
    flex: 0 0 auto;
    overflow: visible;
  }

  #text-preview-dialog {
    width: 96vw;
  }

  .text-preview-window {
    max-height: 82vh;
    /* right padding clears the absolute close button (2rem + 0.75rem gap = 2.75rem) */
    padding: 1rem 3.2rem 1rem 1rem;
  }
}

#toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.65rem 1.25rem;
  border: 1px solid var(--panel-line);
  background: var(--dialog-bg);
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#toast.is-visible {
  opacity: 1;
}

#toast.is-error {
  border-color: var(--danger);
  color: var(--danger);
}
body.gol-active #toast {
  bottom: 4rem;
  left: 50%;
  transform: translateX(-50%);
}
@media (max-width: 960px) {
  body.gol-active #toast {
    bottom: 8rem;
  }
}

@media (max-width: 960px) {
  #grid-app {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas:
      'viewport'
      'inspector';
    min-height: 100vh;
    padding: 0;
    gap: 0;
  }

  body[data-mode='public'] #grid-app {
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: 'viewport';
  }

  #grid-viewport {
    grid-area: viewport;
    min-height: 100dvh;
    height: 100dvh;
  }

  /* Shift grid center right by half the 24px mobile banner width */
  #grid-plane {
    transform-origin: calc(50% + 12px) center;
  }

  .plain-page-view,
  .book-page-view {
    /* Clear the 24px mobile banner on the left; modest breathing room on right */
    padding-left: calc(24px + 0.75rem);
    padding-right: 0.75rem;
  }

  body[data-page-type='plain'] #plain-page-view {
    padding-top: 0;
  }
  body[data-page-type='book'] #book-page-view {
    /* Sidebar toggle occupies top: 1rem, height: 2.2rem → bottom at 3.2rem.
       Title sits just beneath it with a small gap. */
    padding-top: 3.5rem;
  }

  .plain-page-header {
    /* Remove vertical and horizontal padding — view padding handles spacing */
    padding: 0;
    /* Leave room for sidebar toggle (right: 1rem, width: 2.2rem) */
    padding-right: 3.5rem;
    flex-wrap: wrap;
  }

  /* Hide Save / Delete buttons on mobile — editing not practical on small screens */
  .plain-page-header button {
    display: none !important;
  }

  /* Hide the slide-out panel toggle on mobile — panel stacks below */
  .panel-slide-btn {
    display: none !important;
  }

  .plain-page-content {
    /* Remove horizontal margin — view padding already provides it */
    margin: 0 0 1rem;
  }

  #page-menu {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(86vw, 340px);
    max-width: 340px;
    padding: 1.2rem 1rem;
    background: var(--dialog-bg);
    border-right: 1px solid var(--panel-line);
    border-left: none;
    z-index: 20;
    transform: translateX(-104%);
    transition: transform 0.28s ease;
    overflow-y: auto;
  }

  body.sidebar-open #page-menu {
    transform: translateX(0);
  }

  /* Social + footer stick to bottom of sidebar on mobile */
  .menu-social {
    margin-top: auto;
    margin-bottom: 0;
  }

  .global-footer {
    position: static;
    transform: none;
    opacity: 1;
    pointer-events: auto;
    transition: none;
    margin-top: 0.4rem;
    border-top: none;
    padding: 0;
    font-size: 0.7rem;
    color: inherit;
    background: transparent;
    height: auto;
  }

  .global-footer p {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    text-align: left;
    font-size: clamp(0.5rem, 3.2vw, 0.7rem);
  }

  .global-footer a {
    color: inherit;
  }

  #mobile-banner {
    display: flex;
  }

  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 1rem;
    left: calc(24px + 0.55rem);
    width: 2.2rem;
    height: 2.2rem;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    background: #f0f0f0 !important;
    color: var(--ink);
    font: inherit;
    font-size: 1.1rem;
    z-index: 4;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  }

  body[data-page-type='plain'] .sidebar-toggle {
    left: auto;
    right: 1rem;
  }

  .sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    margin-left: auto;
    border: 1px solid var(--panel-line);
    background: rgba(255, 255, 255, 0.6);
    color: var(--ink);
    font: inherit;
    font-size: 1.05rem;
    cursor: pointer;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    border: 0;
    background: rgba(33, 29, 23, 0.22);
    z-index: 15;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  body.sidebar-open .sidebar-backdrop {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  .jump-edge-left {
    left: calc(24px + 0.6rem);
  }

  .jump-edge-top,
  .jump-edge-bottom {
    left: 50%;
  }

  /* ── Mobile touch-target and layout improvements ── */

  .grid-cell {
    width: 210px;
    height: 210px;
  }

  .grid-cell__date {
    font-size: 8.5px;
  }

  .grid-cell.is-visible .grid-cell__overlay {
    opacity: 0.75;
  }

  .zoom-button {
    width: 2.6rem;
    height: 2.6rem;
  }

  .sidebar-toggle {
    width: 2.6rem;
    height: 2.6rem;
  }

  .jump-edge-button {
    width: 2.6rem;
    height: 2.6rem;
  }

  body.sidebar-open .jump-edge-button {
    display: none;
  }

  .jump-edge-bottom {
    bottom: calc(6.5rem + env(safe-area-inset-bottom, 0px));
  }

  .book-mobile__close {
    width: 2.6rem;
    height: 2.6rem;
  }

  .text-preview-close,
  .image-preview-close {
    width: 2.6rem;
    height: 2.6rem;
    font-size: 1.1rem;
  }

  #toast {
    max-width: calc(100vw - 3rem);
    font-size: 0.85rem;
  }

}

@media (max-width: 600px) {
  .grid-cell {
    width: 182px;
    height: 182px;
  }

  .grid-cell__date {
    font-size: 7px;
    padding: 0.15rem 0.25rem;
  }

  .viewport-controls {
    top: 0.85rem;
    right: 0.85rem;
  }

  /* Hide pagination arrows on phones */
  .jump-edge-button {
    display: none !important;
  }
}

/* ================================================================
   Sketchbook tile badge
   ================================================================ */

.grid-cell__sketchbook-badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 2;
  letter-spacing: 0.03em;
}

/* ================================================================
   Book viewer (desktop two-page spread)
   ================================================================ */

#book-viewer-dialog {
  padding: 0;
  border: none;
  background: transparent;
  max-width: 100vw;
  max-height: 100vh;
  overflow: hidden;
}

#book-viewer-dialog::backdrop {
  background: rgba(20, 18, 14, 0.88);
}

.book-viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem;
  max-height: 100vh;
  box-sizing: border-box;
  position: relative;
}

.book-viewer__close {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.6rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.book-viewer__close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.book-viewer__title {
  color: #fff;
  font-size: 1.1rem;
  font-weight: 500;
  margin: 0 0 1rem;
  text-align: center;
  opacity: 0.85;
}

.book-viewer__spread {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 0;
  max-width: 90vw;
  max-height: 78vh;
  position: relative;
}

.book-viewer__page {
  flex: 0 0 auto;
  width: min(42vw, 540px);
  max-height: 78vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f5f0;
  position: relative;
  overflow: hidden;
}

.book-viewer__page--left {
  border-radius: 4px 0 0 4px;
  box-shadow: -2px 2px 12px rgba(0, 0, 0, 0.2);
}

.book-viewer__page--right {
  border-radius: 0 4px 4px 0;
  box-shadow: 2px 2px 12px rgba(0, 0, 0, 0.2);
}

.book-viewer__page--empty {
  background: #eae5dc;
}

.book-viewer__img {
  max-width: 100%;
  max-height: 78vh;
  object-fit: contain;
  display: block;
  cursor: zoom-in;
  transition: transform 0.15s ease;
}

.book-viewer__img:hover {
  transform: scale(1.01);
}

.book-viewer__nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  border: none;
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  font-size: 2.2rem;
  width: 44px;
  height: 64px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.book-viewer__nav:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.55);
}

.book-viewer__nav:disabled {
  opacity: 0.2;
  cursor: default;
}

.book-viewer__nav--prev {
  left: 1rem;
}

.book-viewer__nav--next {
  right: 1rem;
}

.book-viewer__indicator {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.85rem;
  margin-top: 0.75rem;
  text-align: center;
}

/* ================================================================
   Book viewer (mobile vertical scroll)
   ================================================================ */

#book-mobile-dialog {
  padding: 0;
  border: none;
  background: transparent;
  max-width: 100vw;
  max-height: 100dvh;
  width: 100vw;
  height: 100dvh;
}

#book-mobile-dialog::backdrop {
  background: rgba(20, 18, 14, 0.92);
}

.book-mobile {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100vw;
  box-sizing: border-box;
  /* push content below the status bar / notch */
  padding-top: env(safe-area-inset-top, 0px);
}

.book-mobile__close {
  position: fixed;
  top: calc(0.75rem + env(safe-area-inset-top, 0px));
  right: 0.75rem;
  z-index: 10;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 1.4rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-mobile__title {
  color: #fff;
  font-size: 1rem;
  font-weight: 500;
  margin: 0;
  /* right side must clear the fixed close button (36px + 0.75rem gap ≈ 3rem) */
  padding: 0.75rem 3.5rem 0.75rem 1rem;
  text-align: center;
  opacity: 0.85;
  flex-shrink: 0;
  overflow-wrap: break-word;
  word-break: break-word;
  /* ensure minimum title row height matches close button target area */
  min-height: calc(36px + 1.5rem);
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-mobile__scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 0.5rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

.book-mobile__img {
  width: 100%;
  max-width: 600px;
  height: auto;
  display: block;
  border-radius: 4px;
  cursor: zoom-in;
}

/* ================================================================
   Landing page overlay
   ================================================================ */

.landing-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
}

.landing-overlay[hidden] {
  display: none;
}

.landing-stage {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  max-width: 96vw;
  max-height: 92vh;
}

.landing-title {
  margin: 0;
  writing-mode: vertical-lr;
  transform: rotate(180deg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
  font-weight: 400;
  text-transform: lowercase;
  color: var(--ink, #211d17);
  white-space: nowrap;
  flex-shrink: 0;
}

.landing-pixel-grid {
  display: grid;
  width: min(82vw, 82vh);
  aspect-ratio: 1;
  gap: 2px;
  flex-shrink: 1;
  min-width: 0;
}

.landing-pixel {
  perspective: 800px;
  overflow: hidden;
}

.landing-pixel__inner {
  width: 100%;
  height: 100%;
  position: relative;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  transition: transform 0.65s cubic-bezier(0.4, 0, 0.2, 1);
  transition-delay: var(--flip-delay, 0ms);
}

.landing-pixel.is-flipping .landing-pixel__inner {
  transform: rotateX(180deg);
}

.landing-pixel__front,
.landing-pixel__back {
  position: absolute;
  inset: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.landing-pixel__back {
  transform: rotateX(180deg);
}

.landing-close {
  position: absolute;
  bottom: 0.6rem;
  right: 0.6rem;
  border: none;
  background: rgba(0, 0, 0, 0.06);
  padding: 0.45rem 0.5rem;
  border-radius: 5px;
  cursor: pointer;
  z-index: 2;
  color: #444;
  transition: background 0.2s;
  line-height: 0;
}

.landing-close:hover {
  background: rgba(0, 0, 0, 0.12);
}

/* Arrow pad: mini navigation arrows */
.arrow-pad {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: auto auto;
  gap: 2px;
  width: 5.6rem;
}

.arrow-pad__btn {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid #d0d0d0;
  background: #f0f0f0;
  color: #666;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
  border-radius: 3px;
  padding: 0;
}

.arrow-pad__btn:hover {
  background: #e4e4e4;
  color: #333;
}

.arrow-pad__btn:active,
.arrow-pad__btn.is-pressed {
  background: #d0d0d0;
  color: #111;
}

.arrow-pad__up    { grid-column: 2; grid-row: 1; }
.arrow-pad__left  { grid-column: 1; grid-row: 2; }
.arrow-pad__down  { grid-column: 2; grid-row: 2; }
.arrow-pad__right { grid-column: 3; grid-row: 2; }

.arrow-pad__space {
  grid-column: 1 / -1;
  grid-row: 3;
  margin-top: 3px;
  height: 1.4rem;
  border: 1px solid #d0d0d0;
  background: #f0f0f0;
  border-radius: 3px;
  font: inherit;
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  color: #999;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
  -webkit-user-select: none;
  user-select: none;
  padding: 0;
}

.arrow-pad__space:hover {
  background: #e4e4e4;
  color: #666;
}

.arrow-pad__space:active,
.arrow-pad__space.is-pressed {
  background: #d0d0d0;
  color: #111;
}

.arrow-pad[hidden] { display: none; }

/* Color explosion flash on empty tile click */
.color-explosion {
  position: fixed;
  inset: 0;
  z-index: 9999;
  opacity: 0.85;
  pointer-events: none;
  transition: opacity 0.45s ease-out;
}

.color-explosion.is-fading {
  opacity: 0;
}

.color-name-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 2;
  text-align: center;
  padding: 0.5rem;
  background: rgba(255, 255, 255, 0.75);
  font-style: italic;
  font-weight: 500;
  line-height: 1.1;
  overflow: hidden;
}

.color-name-label .color-name-prefix {
  font-size: var(--cn-prefix-size, 1.4rem);
}

.color-name-label .color-name-value {
  font-size: var(--cn-value-size, 2rem);
  font-weight: 700;
}

.color-name-label.is-visible {
  opacity: 1;
}

.color-name-label.is-fading {
  opacity: 0;
  transition: opacity 0.4s ease-out;
}

@media (max-width: 960px) {
  .arrow-pad { display: none; }
  .landing-stage {
    /* Left padding smaller to compensate for vertical title's
       built-in line-height whitespace around the letters */
    width: 100%;
    max-width: 100%;
    padding: 0 4vw 0 1.5vw;
    box-sizing: border-box;
  }
  .landing-pixel-grid {
    /* Fill remaining space after the title */
    width: auto;
    flex: 1;
    min-width: 0;
  }
  .landing-close {
    display: none;
  }
}

/* Ghost cells created during arrow navigation */
.grid-cell.is-ghost {
  background: var(--viewer-bg, var(--paper)) !important;
  background: color-mix(in srgb, var(--viewer-bg, var(--paper)), white 4%) !important;
  border-style: dashed;
  border-color: rgba(0, 0, 0, 0.14);
}

/* Center tile: blue glow when navigating with arrows */
.grid-cell.is-center.is-arrow-focus {
  border-color: #5b9cf5;
  border-style: solid;
  box-shadow: 0 0 0 3px rgba(91, 156, 245, 0.35), 0 0 12px rgba(91, 156, 245, 0.2);
}

/* ================================================================
   Recent tiles popup
   ================================================================ */

.recent-tiles-btn {
  font-size: 0;       /* hide fallback text */
  display: flex;
  align-items: center;
  justify-content: center;
}
.recent-tiles-btn[hidden] {
  display: none;
}
.recent-tiles-btn svg {
  display: block;
}

.recent-tiles-popup {
  position: absolute;
  top: 1rem;
  right: calc(1rem + 2rem + 0.55rem);   /* right of viewport-controls */
  z-index: 25;
  width: 280px;
  max-height: 380px;
  background: var(--dialog-bg, rgba(253, 247, 240, 0.97));
  border: 1px solid var(--panel-line);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(33, 29, 23, 0.14);
  display: flex;
  flex-direction: column;
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  overflow: hidden;
}

.recent-tiles-popup[hidden] {
  display: none;
}

.recent-tiles-popup__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--panel-line);
}

.recent-tiles-popup__title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink);
}

.recent-tiles-popup__close {
  width: 1.6rem;
  height: 1.6rem;
  border: none;
  background: none;
  color: var(--ink-muted);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  transition: background 0.15s;
}
.recent-tiles-popup__close:hover {
  background: rgba(33, 29, 23, 0.08);
}

.recent-tiles-popup__list {
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1;
  min-height: 0;
}

.recent-tile-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.8rem;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s;
  border-bottom: 1px solid rgba(33, 29, 23, 0.05);
}
.recent-tile-item:last-child {
  border-bottom: none;
}
.recent-tile-item:hover {
  background: rgba(33, 29, 23, 0.05);
}

.recent-tile-item__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.recent-tile-item__date {
  flex-shrink: 0;
  font-size: 0.7rem;
  color: var(--ink-muted);
  white-space: nowrap;
}

.recent-tiles-popup__more {
  border: none;
  background: none;
  padding: 0.55rem 0.75rem;
  font: inherit;
  font-size: 0.78rem;
  color: var(--accent, #b44d2b);
  cursor: pointer;
  text-align: center;
  width: 100%;
  border-top: 1px solid var(--panel-line);
  transition: background 0.12s;
}
.recent-tiles-popup__more:hover {
  background: rgba(33, 29, 23, 0.04);
}
.recent-tiles-popup__more[hidden] {
  display: none;
}

.recent-tiles-popup__empty {
  padding: 1.2rem 0.75rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

@media (max-width: 960px) {
  .recent-tiles-popup {
    /* On mobile: anchor bottom-right, above GOL button area */
    position: fixed;
    top: auto;
    right: 0.75rem;
    bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
    left: 0.75rem;
    width: auto;
    max-height: 50vh;
    max-height: 50dvh;
  }
}

/* Preview mode: back-to-admin button */
.preview-back-btn {
  position: fixed;
  bottom: 7rem;
  right: 1rem;
  z-index: 200;
  background: #f0f0f0;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  padding: 0.45rem 1rem;
  font: inherit;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: #444;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s;
}

.preview-back-btn:hover {
  background: #e0e0e0;
}

.preview-back-btn[hidden] {
  display: none;
}
