/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --wood-bg:    #5c3d11;
  --wood-grain: rgba(0,0,0,0.08);
  --font:       'Georgia', serif;
  --radius:     10px;
  --shadow:     0 8px 32px rgba(0,0,0,0.45);
}

body {
  font-family: var(--font);
  background: var(--wood-bg);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  color: #fff;
}

.hidden { display: none !important; }

/* ── Login ────────────────────────────────────────────────────────────────── */
#login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background:
    repeating-linear-gradient(
      88deg,
      transparent 0px, transparent 18px,
      var(--wood-grain) 18px, var(--wood-grain) 20px
    ),
    repeating-linear-gradient(
      2deg,
      transparent 0px, transparent 60px,
      rgba(0,0,0,0.04) 60px, rgba(0,0,0,0.04) 62px
    ),
    linear-gradient(170deg, #7a4e1a 0%, #5c3d11 40%, #3d2409 100%);
  z-index: 100;
}

.login-box {
  background: rgba(255,255,255,0.06);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 18px;
  padding: 3rem 3.5rem;
  text-align: center;
  width: 340px;
  box-shadow: var(--shadow);
}

.login-pencils {
  font-size: 2rem;
  letter-spacing: 0.25rem;
  margin-bottom: 1.2rem;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
}

.login-pencils span { color: var(--c); }

.login-box h1 {
  font-size: 1.6rem;
  font-weight: 400;
  letter-spacing: 0.05em;
  margin-bottom: 2rem;
  color: rgba(255,255,255,0.9);
}

#login-form {
  display: flex; flex-direction: column; gap: 0.8rem;
}

#login-form input[type="password"] {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-family: var(--font);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

#login-form input[type="password"]:focus {
  border-color: rgba(255,255,255,0.5);
}

#login-form button[type="submit"] {
  padding: 0.75rem;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.18);
  color: #fff;
  font-family: var(--font);
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
  letter-spacing: 0.05em;
}

#login-form button[type="submit"]:hover {
  background: rgba(255,255,255,0.28);
}

/* ── View toggle ──────────────────────────────────────────────────────────── */
#view-toggle {
  position: fixed;
  top: 1rem;
  right: 4rem;           /* leaves room for logout btn */
  display: flex;
  gap: 2px;
  background: rgba(0,0,0,0.3);
  border-radius: 20px;
  padding: 3px;
  z-index: 50;
}

.vt {
  border: none;
  border-radius: 16px;
  padding: 4px 12px;
  background: transparent;
  color: rgba(255,255,255,0.45);
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}

.vt.active {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

/* ── Gallery ──────────────────────────────────────────────────────────────── */
#gallery-screen {
  position: fixed; inset: 0;
}

#viewport, #side-viewport {
  transition: opacity 0.18s ease;
}

#viewport {
  width: 100vw;
  height: 100vh;
  overflow-y: scroll;
  overflow-x: hidden;
  cursor: crosshair;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4.5rem 1rem 6rem;
  background:
    repeating-linear-gradient(
      88deg,
      transparent 0px, transparent 22px,
      var(--wood-grain) 22px, var(--wood-grain) 24px
    ),
    repeating-linear-gradient(
      2deg,
      transparent 0px, transparent 80px,
      rgba(0,0,0,0.03) 80px, rgba(0,0,0,0.03) 82px
    ),
    linear-gradient(175deg, #7a4e1a 0%, #5c3d11 50%, #3d2409 100%);
  scrollbar-width: none;
}
#viewport::-webkit-scrollbar { display: none; }

/* ── Pencil box frame ─────────────────────────────────────────────────────── */
#box-frame {
  position: relative;
  padding: 2rem 1.5rem 3rem;
  background:
    repeating-linear-gradient(
      88deg,
      transparent 0px, transparent 22px,
      rgba(0,0,0,0.06) 22px, rgba(0,0,0,0.06) 24px
    ),
    linear-gradient(175deg, #180e04 0%, #0e0804 55%, #161205 100%);
  border-radius: 8px 8px 4px 4px;
  border: 1px solid rgba(255,255,255,0.05);
  border-top: 1px solid rgba(255,255,255,0.12);
  border-bottom: 2px solid rgba(0,0,0,0.6);
  box-shadow:
    inset 0 6px 28px rgba(0,0,0,0.7),
    inset 0 -2px 8px rgba(0,0,0,0.35),
    inset 0 1px 0 rgba(255,255,255,0.04),
    0 2px 0 rgba(255,255,255,0.06),
    0 6px 24px rgba(0,0,0,0.5);
}

#canvas {
  position: relative;
  /* width and height set by JS */
}

/* ── Hex pencil cells ─────────────────────────────────────────────────────── */
.hex {
  position: absolute;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
  transform-origin: center center;
}

/* Pointy-top hexagon clip — dark bg becomes a thin shadow-edge ring */
.hex-shape {
  width: 100%;
  height: 100%;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  position: relative;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.38);
}

/* Outer paint layer — very thin ring (≈1mm), inset so dark edge shows;
   gradient simulates the six illuminated faces of the hexagonal body */
.hex-outer {
  position: absolute;
  inset: 2%;
  background: linear-gradient(
    135deg,
    var(--cd)    0%,
    var(--cd)    8%,
    var(--color) 28%,
    var(--color) 48%,
    var(--cl)    56%,
    var(--color) 72%,
    var(--cd)    90%,
    var(--cd)    100%
  );
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}

/* Wood cross-section — large, warm grain, angle varies per pencil via --wg */
.hex-wood {
  position: absolute;
  inset: 10%;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  background:
    repeating-linear-gradient(
      var(--wg, 8deg),
      transparent        0px,
      transparent        2.5px,
      rgba(100,58,8,.09) 2.5px,
      rgba(100,58,8,.09) 3.5px
    ),
    radial-gradient(
      ellipse at 42% 36%,
      #f5e2a8 0%,
      #e6c87a 28%,
      #d4a84a 58%,
      #bc8c30 100%
    );
}

/* Image thumbnail — same inset as wood, overlays it */
.hex-thumb {
  position: absolute;
  inset: 10%;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  background-size: cover;
  background-position: center;
}

/* Text indicator — transparent so wood grain shows behind */
.hex-text-icon {
  position: absolute;
  inset: 10%;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  background: transparent;
  color: rgba(255, 255, 255, 0.82);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
  font-family: serif;
}

/* Graphite core — hexagonal, pencil-coloured, slightly glossy */
.hex-core {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 28%;
  height: 25%;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  background: radial-gradient(circle at 36% 32%, var(--cl) 0%, var(--color) 55%, var(--cd) 100%);
  pointer-events: none;
}

/* Hover: filled pencil */
.hex.filled { cursor: grab; }

.hex.filled:hover {
  transform: scale(1.08) translateY(-2px);
  filter: brightness(1.15);
  z-index: 10;
}

/* Dragging state */
.hex.dragging {
  opacity: 0.3;
  cursor: grabbing;
  transition: none;
}

/* Ghost when used as drop-target over a filled pencil (swap) */
.hex.ghost.drop-swap .hex-outer {
  background: rgba(255, 200, 80, 0.28);
}

/* Ghost: empty cell hover indicator */
.hex.ghost {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}

.hex.ghost .hex-shape {
  background: transparent;
}

.hex.ghost .hex-outer {
  inset: 0;
  background: rgba(255,255,255,0.10);
}

.hex.ghost .hex-wood,
.hex.ghost .hex-core { display: none; }

/* ── Floating UI ──────────────────────────────────────────────────────────── */
#logout-btn {
  position: fixed;
  top: 1rem; right: 1.2rem;
  background: rgba(0,0,0,0.3);
  color: rgba(255,255,255,0.7);
  border: none;
  border-radius: 50%;
  width: 36px; height: 36px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  z-index: 50;
}

#logout-btn:hover {
  background: rgba(0,0,0,0.5);
  color: #fff;
}

#hint {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.35);
  color: rgba(255,255,255,0.6);
  padding: 0.4rem 1rem;
  border-radius: 20px;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  pointer-events: none;
  z-index: 50;
  animation: fadeout 4s ease 3s forwards;
}

@keyframes fadeout { to { opacity: 0; } }

/* ── Modals ───────────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
}

.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
}

.modal-panel {
  position: relative;
  background: #1a1008;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.2rem 2.5rem;
  max-width: 600px;
  width: 92vw;
  max-height: 90vh;
  overflow-y: auto;
  animation: pop-in 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop-in {
  from { transform: scale(0.88); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 1rem; right: 1rem;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.5);
  font-size: 1.1rem;
  cursor: pointer;
  transition: color 0.2s;
  line-height: 1;
}

.modal-close:hover { color: #fff; }

/* View modal */
#view-body { margin-bottom: 1rem; }

#view-body img {
  max-width: 100%;
  max-height: 60vh;
  border-radius: 6px;
  display: block;
  margin: 0 auto;
}

#view-body .text-content {
  white-space: pre-wrap;
  font-size: 1.18rem;
  line-height: 1.9;
  letter-spacing: 0.015em;
  color: rgba(255, 244, 220, 0.93);
  padding: 1.4rem 0.2rem 0.8rem;
  font-style: italic;
}

#view-meta {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.4);
  margin-bottom: 1.2rem;
}

#view-meta .view-title {
  font-size: 1.1rem;
  color: rgba(255,255,255,0.82);
  margin-bottom: 0.25rem;
  font-style: italic;
}

/* Create modal */
.create-panel h2 {
  font-size: 1.3rem;
  font-weight: 400;
  margin-bottom: 1.4rem;
  color: rgba(255,255,255,0.9);
}

.field-label {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.45);
  margin-bottom: 0.45rem;
  margin-top: 1.1rem;
}

.optional { font-size: 0.7rem; text-transform: none; opacity: 0.6; }

/* Color palette */
.color-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.color-swatch {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}

.color-swatch:hover { transform: scale(1.18); }
.color-swatch.active { border-color: #fff; transform: scale(1.15); }

#color-custom {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
  cursor: pointer;
  padding: 0;
  background: transparent;
  vertical-align: top;
}

#create-title, #create-author {
  width: 100%;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  color: #fff;
  font-family: var(--font);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

#create-title:focus, #create-author:focus { border-color: rgba(255,255,255,0.4); }

/* Type tabs */
.type-tabs {
  display: flex;
  gap: 4px;
  margin: 0.9rem 0 0.6rem;
  background: rgba(0,0,0,0.25);
  border-radius: 8px;
  padding: 3px;
}

.type-tab {
  flex: 1;
  padding: 0.4rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: rgba(255,255,255,0.5);
  font-family: var(--font);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.type-tab.active {
  background: rgba(255,255,255,0.12);
  color: #fff;
}

/* Upload area */
.upload-area {
  display: block;
  border: 2px dashed rgba(255,255,255,0.18);
  border-radius: 8px;
  padding: 2rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  min-height: 140px;
  position: relative;
}

.upload-area:hover {
  border-color: rgba(255,255,255,0.38);
  background: rgba(255,255,255,0.04);
}

.upload-area input[type="file"] {
  position: absolute; inset: 0;
  opacity: 0;
  cursor: pointer;
}

#upload-hint {
  color: rgba(255,255,255,0.4);
  font-size: 0.9rem;
  pointer-events: none;
}

#upload-preview {
  max-width: 100%;
  max-height: 180px;
  border-radius: 6px;
  object-fit: contain;
  pointer-events: none;
}

/* Text area */
#create-text {
  width: 100%;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  padding: 0.8rem;
  color: #fff;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
  min-height: 120px;
}

#create-text:focus { border-color: rgba(255,255,255,0.4); }

/* Caption textarea (image mode) */
#create-caption {
  width: 100%;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  padding: 0.7rem 0.8rem;
  color: #fff;
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
  min-height: 80px;
}
#create-caption:focus { border-color: rgba(255,255,255,0.4); }

/* Date drawn input */
#create-drawn-at {
  width: 100%;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  color: #fff;
  font-family: var(--font);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
  color-scheme: dark;
}
#create-drawn-at:focus { border-color: rgba(255,255,255,0.4); }

/* View modal: caption block */
#view-caption {
  white-space: pre-wrap;
  font-size: 0.88rem;
  line-height: 1.65;
  color: rgba(255,255,255,0.65);
  font-style: italic;
  margin-top: 0.6rem;
  padding: 0.6rem 0.8rem;
  border-left: 2px solid rgba(255,255,255,0.15);
}

/* View modal: drawn-at date */
.view-drawn-at {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.55);
}

/* Buttons */
.btn-primary {
  margin-top: 1.4rem;
  width: 100%;
  padding: 0.75rem;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.16);
  color: #fff;
  font-family: var(--font);
  font-size: 1rem;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: background 0.2s;
}

.btn-primary:hover { background: rgba(255,255,255,0.26); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  color: rgba(255,255,255,0.55);
  padding: 0.4rem 0.9rem;
  font-family: var(--font);
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.btn-secondary:hover {
  border-color: rgba(255,255,255,0.5);
  color: #fff;
}

.btn-danger {
  background: transparent;
  border: 1px solid rgba(220, 80, 80, 0.4);
  border-radius: 6px;
  color: rgba(220, 80, 80, 0.7);
  padding: 0.4rem 0.9rem;
  font-family: var(--font);
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.btn-danger:hover {
  border-color: rgba(220, 80, 80, 0.8);
  color: #dc5050;
}

.error {
  color: #f87171;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

/* Drag-over state */
.upload-area.drag-over {
  border-color: rgba(255,255,255,0.6);
  background: rgba(255,255,255,0.08);
}

/* ── Hex hover tooltip — mini side pencil ────────────────────────────────── */
#hex-tooltip {
  position: fixed;
  z-index: 150;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  opacity: 0;
  transition: opacity 0.12s ease;
  filter: drop-shadow(0 6px 16px rgba(0,0,0,0.6));
}

/* ── Side view (landscape) ────────────────────────────────────────────────── */
#side-viewport {
  position: absolute;
  inset: 0;
  overflow-x: scroll;
  overflow-y: hidden;
  cursor: crosshair;
  background: linear-gradient(180deg, #111 0%, #181818 65%, #111 100%);
  scrollbar-width: none;
}
#side-viewport::-webkit-scrollbar { display: none; }

#side-canvas {
  position: relative;
  height: 100%;
  /* width set by JS */
}

/* Fixed floor line */
#side-floor {
  position: fixed;
  bottom: 54px;
  left: 0; right: 0;
  height: 1px;
  background: linear-gradient(to right,
    transparent 0%,
    rgba(255,255,255,0.07) 8%,
    rgba(255,255,255,0.07) 92%,
    transparent 100%
  );
  pointer-events: none;
  z-index: 2;
}

/* ── Individual side pencil ───────────────────────────────────────────────── */
.sp {
  position: absolute;
  bottom: 55px;          /* sits on the floor line */
  display: flex;
  flex-direction: column;
  align-items: stretch;
  transform-origin: bottom center;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.sp.filled:hover {
  transform: translateY(-6px) rotate(var(--rot));
  filter: brightness(1.15);
  z-index: 10;
}

/* Small body stub at the flat end, after the gold ring */
.sp-cap {
  height: 22px;
  flex-shrink: 0;
  border-radius: 0 0 2px 2px;
  background: linear-gradient(to right,
    var(--cd) 0%, var(--cd) 8%,
    var(--color) 8%, var(--color) 33%,
    var(--cl) 33%, var(--cl) 67%,
    var(--color) 67%, var(--color) 92%,
    var(--cd) 92%, var(--cd) 100%
  );
}

/* Thin gold ring */
.sp-ferrule {
  height: 4px;
  flex-shrink: 0;
  background: linear-gradient(to right,
    #5a4206 0%, #a87c10 15%, #d4a824 33%, #f0cc44 50%, #d4a824 67%, #a87c10 85%, #5a4206 100%
  );
}

/* Painted body — 3 visible hex faces: dark edge | side | highlight | side | dark edge */
.sp-body {
  flex: 1;
  background: linear-gradient(to right,
    var(--cd)    0%,
    var(--cd)    8%,
    var(--color) 8%,
    var(--color) 33%,
    var(--cl)    33%,
    var(--cl)    67%,
    var(--color) 67%,
    var(--color) 92%,
    var(--cd)    92%,
    var(--cd)    100%
  );
  position: relative;
  z-index: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 8px;
}

/* Title printed along the body */
.sp-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--label-color, #e8c040);
  text-shadow: none;
  white-space: nowrap;
  overflow: hidden;
  max-height: 80%;
  pointer-events: none;
  font-family: 'Georgia', serif;
}

/* Author initial on the flat end cap */
.sp-cap {
  display: flex;
  align-items: center;
  justify-content: center;
}

.sp-initial {
  font-family: 'Georgia', serif;
  font-size: 10px;
  font-style: italic;
  color: var(--label-color, #e8c040);
  letter-spacing: 0.05em;
  pointer-events: none;
  line-height: 1;
}

/* Wood sharpening cone */
.sp-wood {
  height: 48px;
  background: linear-gradient(to right,
    #8a5428 0%, #b87840 10%, #d8a860 25%, #f0cc82 42%,
    #fae0a0 50%, #f0cc82 58%, #d8a860 75%, #b87840 90%, #8a5428 100%
  );
  clip-path: polygon(43% 0, 57% 0, 100% 100%, 0 100%);
  flex-shrink: 0;
}

/* Pencil tip — matches pencil colour, points up */
.sp-point {
  align-self: center;
  width: 0; height: 0;
  border-left:   2px solid transparent;
  border-right:  2px solid transparent;
  border-bottom: 10px solid var(--color);
  flex-shrink: 0;
  filter: brightness(0.6);
}

/* Drop shadow under each pencil */
.sp::after {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 10%;
  right: 10%;
  height: 12px;
  background: radial-gradient(ellipse at center top, rgba(0,0,0,0.5) 0%, transparent 70%);
  pointer-events: none;
}

/* Empty slot: faint ghost pencil */
.sp.empty {
  opacity: 0.1;
  transition: opacity 0.18s ease;
}

.sp.empty:hover {
  opacity: 0.28;
}

/* ── Side view — portrait overrides ──────────────────────────────────────── */
/* When screen is taller than wide: pencils lie horizontal, stack top→bottom  */

#side-viewport.portrait {
  overflow-y: scroll;
  overflow-x: hidden;
}

#side-viewport.portrait #side-canvas {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 24px 28px 80px;
  width: 100%;
  height: auto;
}

#side-viewport.portrait #side-floor { display: none; }

/* Override the absolute landscape positioning */
#side-viewport.portrait .sp {
  position: relative;
  left: auto;
  bottom: auto;
  flex-direction: row-reverse; /* DOM: point→wood→body→ferrule→cap; visual: cap(left)→…→point(right) */
  width: var(--sp-w);
  height: 28px;                /* PENCIL_W — now the short dimension */
  transform-origin: left center;
}

#side-viewport.portrait .sp.filled:hover {
  transform: translateX(6px) rotate(calc(var(--rot) * 0.4));
  filter: brightness(1.15);
}

#side-viewport.portrait .sp-cap {
  width: 22px; height: 100%; flex-shrink: 0;
  border-radius: 2px 0 0 2px;
  background: linear-gradient(to bottom,
    var(--cd) 0%, var(--cd) 8%,
    var(--color) 8%, var(--color) 33%,
    var(--cl) 33%, var(--cl) 67%,
    var(--color) 67%, var(--color) 92%,
    var(--cd) 92%, var(--cd) 100%
  );
}

#side-viewport.portrait .sp-ferrule {
  width: 4px; height: 100%; flex-shrink: 0;
  background: linear-gradient(to bottom,
    #5a4206 0%, #a87c10 15%, #d4a824 33%, #f0cc44 50%, #d4a824 67%, #a87c10 85%, #5a4206 100%
  );
}

#side-viewport.portrait .sp-body {
  height: 100%; flex: 1;
  background: linear-gradient(to bottom,
    var(--cd)    0%,
    var(--cd)    8%,
    var(--color) 8%,
    var(--color) 33%,
    var(--cl)    33%,
    var(--cl)    67%,
    var(--color) 67%,
    var(--color) 92%,
    var(--cd)    92%,
    var(--cd)    100%
  );
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  padding-left: 10px;
  padding-bottom: 0;
  overflow: hidden;
  margin-top: 0;
}

#side-viewport.portrait .sp-label {
  writing-mode: horizontal-tb;
  transform: none;
  max-width: 85%; max-height: unset;
  padding-left: 0;
}

#side-viewport.portrait .sp-wood {
  width: 48px; height: 100%; flex-shrink: 0;
  clip-path: polygon(0 0, 100% 43%, 100% 57%, 0 100%);
  background: linear-gradient(to bottom,
    #8a5428 0%, #b87840 10%, #d8a860 25%, #f0cc82 42%,
    #fae0a0 50%, #f0cc82 58%, #d8a860 75%, #b87840 90%, #8a5428 100%
  );
}

#side-viewport.portrait .sp-point {
  align-self: center; flex-shrink: 0;
  width: 0; height: 0;
  border-top:    2px solid transparent;
  border-bottom: 2px solid transparent;
  border-left:   10px solid var(--color);
  border-right:  none;
  filter: brightness(0.6);
}

#side-viewport.portrait .sp::after { display: none; }

/* ── Modal pencil preview ─────────────────────────────────────────────────── */
.modal-with-pencil {
  display: flex;
  flex-direction: row;
  gap: 1.5rem;
  align-items: flex-start;
}

.modal-pencil-col {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 0.4rem;
}

.modal-content-col {
  flex: 1;
  min-width: 0;
}

/* Shared pencil wrapper inside modals */
.mp-pencil {
  display: flex;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.5));
}

/* Vertical pencil — landscape screens, stands on the left */
.mp-v {
  flex-direction: column;
  align-items: stretch;
  width: 28px;
  height: min(70vh, 480px);
}

/* Horizontal pencil — portrait screens, lies across the top */
.mp-h {
  flex-direction: row-reverse;
  align-items: stretch;
  height: 28px;
  width: 100%;
}

.mp-h .sp-cap {
  width: 22px; height: 100%; flex-shrink: 0;
  border-radius: 2px 0 0 2px;
  background: linear-gradient(to bottom,
    var(--cd) 0%, var(--cd) 8%,
    var(--color) 8%, var(--color) 33%,
    var(--cl) 33%, var(--cl) 67%,
    var(--color) 67%, var(--color) 92%,
    var(--cd) 92%, var(--cd) 100%
  );
}

.mp-h .sp-ferrule {
  width: 4px; height: 100%; flex-shrink: 0;
  background: linear-gradient(to bottom,
    #5a4206 0%, #a87c10 15%, #d4a824 33%, #f0cc44 50%, #d4a824 67%, #a87c10 85%, #5a4206 100%
  );
}

.mp-h .sp-body {
  height: 100%; flex: 1;
  background: linear-gradient(to bottom,
    var(--cd)    0%,   var(--cd)    8%,
    var(--color) 8%,   var(--color) 33%,
    var(--cl)    33%,  var(--cl)    67%,
    var(--color) 67%,  var(--color) 92%,
    var(--cd)    92%,  var(--cd)    100%
  );
  display: flex; flex-direction: row;
  align-items: center; justify-content: flex-start;
  padding-left: 10px; padding-bottom: 0; overflow: hidden;
}

.mp-h .sp-label {
  writing-mode: horizontal-tb;
  transform: none;
  max-width: 85%; max-height: unset;
}

.mp-h .sp-wood {
  width: 48px; height: 100%; flex-shrink: 0;
  clip-path: polygon(0 0, 100% 43%, 100% 57%, 0 100%);
  background: linear-gradient(to bottom,
    #8a5428 0%, #b87840 10%, #d8a860 25%, #f0cc82 42%,
    #fae0a0 50%, #f0cc82 58%, #d8a860 75%, #b87840 90%, #8a5428 100%
  );
}

.mp-h .sp-point {
  align-self: center; flex-shrink: 0;
  width: 0; height: 0;
  border-top:    2px solid transparent;
  border-bottom: 2px solid transparent;
  border-left:   10px solid var(--color);
  border-right:  none;
  filter: brightness(0.6);
}

@media (orientation: portrait) {
  .modal-with-pencil {
    flex-direction: column;
    align-items: stretch;
  }
  .modal-pencil-col {
    align-self: stretch;
    padding-top: 0;
    margin-bottom: 0.8rem;
  }
}
