/* Inkwell — the writing desk: tray, pens, inks, sheet, blotter */
.desk-grid { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: clamp(14px, 2vw, 26px); align-items: start; }

/* ---------- tray ---------- */
.tray-details {
  position: relative; border-radius: var(--r);
  background: var(--grain), var(--noise), linear-gradient(170deg, var(--leather), var(--leather-2));
  box-shadow: 0 1px 0 rgba(255, 255, 255, .06) inset, 0 14px 34px rgba(0, 0, 0, .4);
  outline: 1.5px dashed var(--stitch); outline-offset: -8px;
  padding: 12px 16px 16px;
}
.desk-grid > .tray-details { position: sticky; top: 86px; max-height: calc(100vh - 100px); overflow: auto; scrollbar-width: thin; }
.tray-summary {
  list-style: none; cursor: pointer; min-height: 44px; display: flex; align-items: center; justify-content: space-between;
  font-family: var(--display); font-style: italic; font-size: 1.2rem; color: var(--brass-hi); padding: 4px 6px;
}
.tray-summary::-webkit-details-marker { display: none; }
.tray-summary::after { content: "▾"; font-style: normal; transition: transform .3s var(--ease); color: var(--brass); }
.tray-details:not([open]) .tray-summary::after { transform: rotate(-90deg); }
.tray { display: grid; gap: 14px; padding: 4px 4px 0; }
.tray-sec { display: grid; gap: 8px; }
.tray-h { margin: 0; font-size: .72rem; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.pen-rack {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 10px;
  border-radius: 12px;
  background: radial-gradient(120% 140% at 50% 0%, rgba(255, 255, 255, .06), transparent 60%), var(--noise), var(--felt);
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, .6), inset 0 -1px 0 rgba(255, 255, 255, .06), 0 1px 0 rgba(255, 255, 255, .05);
}
.pen-btn {
  position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 6px;
  min-height: 56px; padding: 6px 8px 5px; border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--text); text-align: left;
  transition: transform .35s var(--spring), background .25s, border-color .25s, box-shadow .35s var(--ease);
}
.pen-btn .pen-svg { grid-column: 1 / -1; width: 100%; height: 26px; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .5)); transition: transform .45s var(--spring), filter .35s; }
.pen-btn .pen-name { font-size: .76rem; color: var(--muted); }
.pen-btn kbd { font-size: .62rem; opacity: .75; }
.pen-btn:hover { background: rgba(255, 255, 255, .05); }
.pen-btn:hover .pen-svg { transform: translateX(-3px) rotate(-2deg); }
.pen-btn.on { background: linear-gradient(180deg, rgba(246, 226, 164, .16), rgba(246, 226, 164, .04)); border-color: rgba(246, 226, 164, .4); transform: translateY(-3px); box-shadow: 0 10px 18px rgba(0, 0, 0, .35); }
.pen-btn.on .pen-svg { transform: translate(-4px, -3px) rotate(-4deg); filter: drop-shadow(0 9px 6px rgba(0, 0, 0, .55)); }
.pen-btn.on .pen-name { color: var(--brass-hi); }
.pen-btn:active .pen-svg { transform: translate(-6px, 0) rotate(-6deg) scale(.98); }

.ink-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-end; }
.ink-btn {
  width: 44px; height: 54px; padding: 3px 4px 2px; border: 0; border-radius: 10px; background: transparent;
  transition: transform .35s var(--spring), background .2s;
}
.ink-btn svg { width: 100%; height: 100%; filter: drop-shadow(0 4px 3px rgba(0, 0, 0, .45)); }
.ink-btn:hover { transform: translateY(-3px) rotate(-4deg); }
.ink-btn:hover .ink-lvl, .ink-btn.on .ink-lvl { animation: inkSlosh 1.4s ease-in-out infinite; transform-origin: 16px 30px; }
.ink-btn.on { background: rgba(246, 226, 164, .14); transform: translateY(-5px); box-shadow: 0 0 0 2px var(--brass) inset; }
@keyframes inkSlosh { 0%, 100% { transform: skewY(0); } 30% { transform: skewY(-6deg); } 70% { transform: skewY(5deg); } }
.ink-custom-wrap { width: 44px; height: 44px; border-radius: 50%; overflow: hidden; display: inline-grid; place-items: center; box-shadow: 0 0 0 2px var(--brass), 0 3px 8px rgba(0, 0, 0, .4); background: conic-gradient(#c23b22, #b8892b, #12705a, #1f4fb3, #5a2a6e, #c23b22); cursor: pointer; margin-bottom: 5px; }
.ink-custom { width: 60px; height: 60px; border: 0; padding: 0; opacity: 0; cursor: pointer; }
.sliders { gap: 6px; }
.tool-hint { margin: 2px 2px 0; font-size: .84rem; font-style: italic; color: var(--muted); min-height: 2.6em; border-left: 3px solid var(--ink, var(--brass)); padding-left: 10px; transition: border-color .3s; }
.tray-paper { display: grid; gap: 10px; margin-top: 12px; padding: 12px 4px 2px; border-top: 1px solid var(--line); }
.paper-desc { margin: 0; font-size: .84rem; font-style: italic; color: var(--muted); }
.tray.compact .pen-rack { grid-template-columns: repeat(4, 1fr); }
.tray.compact .pen-btn { grid-template-columns: 1fr; min-height: 50px; }
.tray.compact .pen-btn .pen-name, .tray.compact .pen-btn kbd { display: none; }

/* ---------- sheet area ---------- */
.sheet-area { min-width: 0; display: grid; gap: 12px; }
.sheet-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.sheet-toolbar .title-input { flex: 1 1 220px; }
.tb-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; min-width: 230px; padding: 6px; border-radius: 10px;
  background: var(--noise), var(--paper-card); color: var(--paper-ink); box-shadow: 0 18px 36px rgba(0, 0, 0, .45);
  display: grid; animation: cardIn .3s var(--spring);
}
.menu button { min-height: 44px; text-align: left; padding: 0 14px; border: 0; border-radius: 8px; background: transparent; color: var(--paper-ink); }
.menu button:hover, .menu button:focus-visible { background: rgba(0, 0, 0, .07); }
.play-ico { width: 0; height: 0; border-left: 10px solid currentColor; border-top: 6px solid transparent; border-bottom: 6px solid transparent; transition: all .2s; }
.brass-btn.play.on .play-ico { width: 10px; height: 10px; border: 0; background: currentColor; border-radius: 2px; }
.brass-btn.play.on { animation: rec 1.6s ease-in-out infinite; }
@keyframes rec { 50% { box-shadow: inset 0 2px 6px rgba(0, 0, 0, .35), 0 0 0 5px rgba(246, 226, 164, .18); } }

.blotter {
  position: relative; padding: clamp(10px, 2vw, 26px); border-radius: 18px;
  background: radial-gradient(70% 60% at 30% 20%, rgba(255, 255, 255, .06), transparent 70%), var(--noise), var(--felt);
  box-shadow: inset 0 0 0 6px rgba(0, 0, 0, .18), inset 0 6px 24px rgba(0, 0, 0, .55), 0 20px 40px rgba(0, 0, 0, .35);
}
.blotter::before, .blotter::after {
  content: ""; position: absolute; left: 10px; right: 10px; height: 14px; border-radius: 8px; pointer-events: none;
  background: linear-gradient(180deg, var(--brass-hi), var(--brass) 50%, var(--brass-lo));
  box-shadow: 0 2px 4px rgba(0, 0, 0, .4); opacity: .9;
}
.blotter::before { top: -6px; }
.blotter::after { bottom: -6px; }
.sheet-scroller { overflow: auto; max-height: calc(100vh - 150px); border-radius: 6px; overscroll-behavior: contain; scrollbar-width: thin; padding: 4px; }
@supports (height: 100dvh) { .sheet-scroller { max-height: calc(100dvh - 150px); } }
.sheet-scroller:not(.zoomed) { overflow: visible; max-height: none; }

.sheet {
  --ar: .7692; --chrome: 250px; --z: 1;
  --fitw: calc((100vh - var(--chrome)) * var(--ar));
  position: relative; margin: 0 auto; width: calc(min(100%, max(300px, var(--fitw))) * var(--z));
  height: auto; min-height: 120px; border-radius: 3px; background: #f3eee1;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .25), 0 2px 0 -1px #e8e1cf, 0 4px 0 -2px #d9d0bb, 0 22px 40px rgba(0, 0, 0, .5);
  touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  transition: transform .5s var(--ease);
}
@supports (height: 100dvh) { .sheet { --fitw: calc((100dvh - var(--chrome)) * var(--ar)); } }
.sheet:focus-visible { outline: 3px solid var(--brass-hi); outline-offset: 6px; }
.layer { position: absolute; inset: 0; width: 100%; height: 100%; display: block; border-radius: 3px; }
.layer-paper { z-index: 1; } .layer-guide { z-index: 2; } .layer-ink { z-index: 3; } .layer-live { z-index: 4; cursor: crosshair; touch-action: none; }
.marker-live { opacity: .55; mix-blend-mode: multiply; }
body[data-tool="hand"] .layer-live { cursor: grab; }
body[data-tool="hand"] .layer-live:active { cursor: grabbing; }
body[data-tool="eraser"] .layer-live { cursor: cell; }
.stamp-armed .layer-live { cursor: copy; }
.is-playing .layer-live { cursor: progress; }
.sheet.swap { animation: paperSwap .6s var(--ease); }
@keyframes paperSwap { 0% { transform: translateY(0); } 35% { transform: translateY(-10px) rotate(-.6deg); filter: brightness(1.08); } 100% { transform: none; } }

.corner { position: absolute; width: 38px; height: 38px; z-index: 6; pointer-events: none; background: linear-gradient(135deg, var(--brass-hi), var(--brass) 45%, var(--brass-lo)); filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .45)); }
.corner::after { content: ""; position: absolute; width: 6px; height: 6px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff4cc, #6b4e17); }
.corner.tl { left: -5px; top: -5px; clip-path: polygon(0 0, 100% 0, 0 100%); }
.corner.tr { right: -5px; top: -5px; clip-path: polygon(0 0, 100% 0, 100% 100%); }
.corner.bl { left: -5px; bottom: -5px; clip-path: polygon(0 0, 100% 100%, 0 100%); }
.corner.br { right: -5px; bottom: -5px; clip-path: polygon(100% 0, 100% 100%, 0 100%); }
.corner.tl::after { left: 8px; top: 8px; } .corner.tr::after { right: 8px; top: 8px; } .corner.bl::after { left: 8px; bottom: 8px; } .corner.br::after { right: 8px; bottom: 8px; }

.sheet-empty {
  position: absolute; inset: 0; z-index: 5; pointer-events: none; display: grid; place-content: center; gap: 8px; text-align: center; padding: 12%;
  color: rgba(29, 43, 79, .5); transition: opacity .6s var(--ease), transform .6s var(--ease);
}
.sheet-empty span { font-family: var(--display); font-style: italic; font-size: clamp(1.4rem, 1rem + 2vw, 2.6rem); animation: breathe 4s ease-in-out infinite; }
.sheet-empty small { font-size: .9rem; max-width: 30em; margin: 0 auto; }
.sheet-empty.gone { opacity: 0; transform: translateY(-10px); }
@keyframes breathe { 50% { opacity: .55; letter-spacing: .02em; } }

.nib-cursor {
  position: absolute; z-index: 7; width: 34px; height: 34px; margin: -33px 0 0 -2px; pointer-events: none;
  background: linear-gradient(135deg, var(--brass-hi), var(--brass) 50%, var(--brass-lo));
  clip-path: polygon(0 100%, 30% 25%, 55% 0, 100% 45%, 75% 70%);
  filter: drop-shadow(2px 4px 3px rgba(0, 0, 0, .45));
  transition: left .05s linear, top .05s linear;
}

.sheet-status { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; font-size: .86rem; color: var(--muted); }
.gauge { width: 78px; color: var(--muted); }
.gauge svg { width: 78px; height: 45px; display: block; }
.gauge-needle { transition: transform .12s ease-out; }
.gauge-label { font-variant-numeric: tabular-nums; min-width: 14em; }
.count { padding: 3px 10px; border-radius: 20px; border: 1px solid var(--line); }
.hint { margin-left: auto; }

@media (max-width: 1100px) {
  .desk-grid { grid-template-columns: 1fr; }
  .desk-grid > .tray-details { position: relative; top: 0; max-height: none; }
  .tray { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); align-items: start; }
  .tray-sec:first-child { grid-column: 1 / -1; }
  .pen-rack { grid-template-columns: repeat(8, minmax(92px, 1fr)); overflow-x: auto; }
  .tray-paper { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
  .sheet { --chrome: 300px; }
}
@media (max-width: 640px) {
  .pen-rack { grid-template-columns: repeat(8, 86px); }
  .tray.compact .pen-rack { grid-template-columns: repeat(8, 64px); }
  .sheet-toolbar .title-input { flex-basis: 100%; }
  .tb-group .lbl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .hint { display: none; }
  .gauge-label { min-width: 0; }
  .blotter { padding: 8px; border-radius: 12px; }
  .corner { width: 28px; height: 28px; }
  .sheet { --chrome: 230px; }
}
