/* Trick Index Cards: old ruled index cards kept in a wooden box on a walnut desk */
:root {
  --typewriter: "American Typewriter", "Courier Prime", "Courier New", Courier, monospace;
  --printed: Georgia, "Times New Roman", serif;
  --index-paper: #fbf5e2;
  --index-ink: #2a2620;
  --index-rule: #a9c8e4;
  --index-margin: #d9535c;
  --index-line: 28px;
}

.card-button.red .card-button-index { color: var(--card-red); }

.page.desk-page { max-width: none; padding: 0; }
.desk-page .flash { margin: 0; }

.desk {
  min-height: calc(100dvh - 57px);
  padding: 24px 16px 64px;
  color: #f3e6cc;
  background:
    repeating-linear-gradient(91deg, rgb(255 255 255 / 0.025) 0 2px, transparent 2px 11px),
    repeating-linear-gradient(89deg, rgb(0 0 0 / 0.08) 0 1px, transparent 1px 17px),
    radial-gradient(ellipse at 50% 30%, #5a3a24, #3b2416 70%, #2a190f);
}
.desk .page-head { max-width: 640px; margin: 0 auto 8px; }
.desk h1 { font-family: var(--printed); letter-spacing: 0.02em; }
.desk .button.secondary { background: var(--index-paper); border-color: var(--index-paper); color: var(--index-ink); }
.desk-link {
  color: #f2d27a;
  background: none; border: 0; padding: 0;
  font: inherit; text-decoration: underline; text-underline-offset: 3px;
  cursor: pointer;
}
.desk-link.danger { color: #f5a59c; }
.desk form.button_to { margin: 0; }

.desk .new-card:focus-visible { outline-color: #f2d27a; }

/* An index card: printed labels, a red rule under the heading and blue rules below */
.index-card {
  display: block;
  position: relative;
  padding: 10px 18px 14px;
  border-radius: 3px;
  color: var(--index-ink);
  text-decoration: none;
  font: 1rem / var(--index-line) var(--typewriter);
  background:
    radial-gradient(ellipse 90% 80% at 50% 45%, transparent 55%, rgb(150 110 50 / 0.16)),
    var(--index-paper);
  box-shadow: 0 1px 1px rgb(0 0 0 / 0.25), 0 6px 16px rgb(0 0 0 / 0.35);
}
.index-card-head {
  display: flex; align-items: baseline; gap: 10px;
  min-height: 40px;
  padding-bottom: 4px;
  border-bottom: 3px double var(--index-margin);
}
.index-card-head h1 { margin: 0; font: 700 1.35rem / 1.2 var(--typewriter); }
.index-card-label {
  font: 700 0.72rem / 1 var(--printed);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #8a6f4d;
}
.index-card-lines {
  display: block;
  margin: 0;
  padding: 0;
  min-height: calc(var(--index-line) * 3);
  background: repeating-linear-gradient(transparent 0 calc(var(--index-line) - 1px), var(--index-rule) calc(var(--index-line) - 1px) var(--index-line));
  overflow-wrap: anywhere;
}
.index-card-lines p { margin: 0; }
.index-card-lines p + p { margin-top: var(--index-line); }
.index-card .errors { margin: 4px 0; font-family: var(--printed); }
.index-card-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

/* Typing straight onto the card */
.index-card input[type=text], .index-card textarea {
  width: 100%;
  border: 0; border-radius: 0;
  padding: 0;
  background-color: transparent;
  color: var(--index-ink);
  font: 1rem / var(--index-line) var(--typewriter);
  resize: vertical;
}
.index-card textarea { background-attachment: local; }
.index-card input[type=text] { font-size: 1.2rem; font-weight: 700; }
.index-card :is(input, textarea):focus-visible { outline: 2px dashed #8a6f4d; outline-offset: 2px; }
.index-card ::placeholder { color: #a5977f; opacity: 1; }
.trick-form .index-card-lines { min-height: 0; background: none; }
.trick-form .index-card-lines .index-card-label { display: block; margin-top: 12px; }
.trick-form textarea { background: repeating-linear-gradient(transparent 0 calc(var(--index-line) - 1px), var(--index-rule) calc(var(--index-line) - 1px) var(--index-line)); }

/* A trick laid out on the desk: its title card, then one card per step */
.card-pile { max-width: 640px; margin: 16px auto 0; display: flex; flex-direction: column; gap: 18px; }
.step-cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 18px; }
.card-pile .index-card { transform: rotate(-0.5deg); }
.step-cards .index-card:nth-child(even) { transform: rotate(0.6deg); }
.step-cards .index-card:nth-child(3n) { transform: rotate(-0.2deg); }
.card-pile .index-card { scroll-margin-top: 24px; }
.card-pile :is(.blank-card, .trick-form, .index-card:has(form)) { transform: none; }
.index-card .button.secondary { border-color: #d8ccb2; }
.step-number { font: 700 1.3rem / 1 var(--typewriter); color: var(--index-margin); }
.step-tools { margin-left: auto; display: flex; gap: 4px; }
.step-tool {
  min-width: 30px; height: 30px;
  padding: 0 8px;
  border: 1px solid #d8ccb2; border-radius: 6px;
  background: rgb(255 255 255 / 0.5);
  color: #6d5a40;
  font: 600 0.85rem / 28px var(--printed);
  text-align: center; text-decoration: none;
  cursor: pointer;
}
.step-tool:disabled { opacity: 0.35; cursor: default; }
.blank-card { background-color: #fffaea; }

/* The card box */
.trick-box {
  --box-card-w: min(440px, calc(100vw - 72px));
  --box-card-h: calc(var(--box-card-w) * 0.6);
  --peek: 48px;
  --front-h: calc(var(--box-card-h) * 0.62);
  position: relative;
  width: calc(var(--box-card-w) + 40px);
  margin: calc(var(--box-card-h) * 0.4) auto 0;
  perspective: 1400px;
  perspective-origin: 50% -40%;
}

/* The lid stands open behind the cards, hinged at the top of the box */
.trick-box-lid {
  position: absolute; left: 0; right: 0;
  bottom: calc(var(--front-h) - 6px);
  height: calc(var(--box-card-h) * 0.85 + (var(--n) - 1) * var(--peek));
  border-radius: 8px 8px 2px 2px;
  transform-origin: 50% 100%;
  transform: rotateX(22deg);
  background:
    linear-gradient(to top, rgb(0 0 0 / 0.45), transparent 60%),
    repeating-linear-gradient(90deg, rgb(255 255 255 / 0.04) 0 2px, transparent 2px 9px),
    linear-gradient(#8a5a33, #6d4426);
  box-shadow: inset 0 0 0 6px #a06a3c, inset 0 0 0 7px rgb(0 0 0 / 0.3), 0 4px 10px rgb(0 0 0 / 0.4);
}

.trick-box-cards {
  position: relative; z-index: 1;
  list-style: none;
  margin: 0; padding: 0 20px;
  clip-path: inset(-100vh -20px 0 -20px);
}
.trick-box-cards li + li { margin-top: calc(var(--peek) - var(--box-card-h)); }
.box-card {
  height: var(--box-card-h);
  padding-top: 8px;
  overflow: hidden;
  transition: transform 0.2s ease;
}
.box-card:hover, .box-card:focus-visible { transform: translateY(-14px); }
.box-card:focus-visible { outline: 3px solid #f2d27a; outline-offset: 2px; }
.box-card-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  height: calc(var(--peek) - 8px);
  border-bottom: 3px double var(--index-margin);
}
.box-card-name { font-weight: 700; font-size: 1.1rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.box-card-count { flex: none; font: 700 0.72rem / 1 var(--printed); letter-spacing: 0.12em; text-transform: uppercase; color: #8a6f4d; }
.box-card-lines {
  display: block;
  height: 100%;
  background: repeating-linear-gradient(transparent 0 calc(var(--index-line) - 1px), var(--index-rule) calc(var(--index-line) - 1px) var(--index-line));
}

.trick-box-front {
  position: relative; z-index: 2;
  display: grid; place-items: center;
  height: var(--front-h);
  margin-top: calc(var(--box-card-h) * -0.5);
  border-radius: 4px 4px 10px 10px;
  background:
    repeating-linear-gradient(92deg, rgb(255 255 255 / 0.05) 0 2px, transparent 2px 10px),
    repeating-linear-gradient(88deg, rgb(60 25 5 / 0.12) 0 1px, transparent 1px 14px),
    linear-gradient(#c58a50, #a8703e 60%, #8f5c31);
  box-shadow: inset 0 3px 0 rgb(255 225 180 / 0.35), inset 0 -6px 10px rgb(0 0 0 / 0.25), 0 14px 24px rgb(0 0 0 / 0.5);
}
.trick-box-latch {
  position: absolute; top: -4px; left: 50%;
  width: 34px; height: 18px; margin-left: -17px;
  border-radius: 3px 3px 8px 8px;
  background: linear-gradient(#f4d98a, #b88a2c);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.5);
}
.trick-box-plate {
  padding: 6px 22px;
  border-radius: 4px;
  background: linear-gradient(#f2d98f, #c9a24a 55%, #a9832e);
  box-shadow: inset 0 0 0 1px rgb(255 245 210 / 0.6), 0 1px 2px rgb(0 0 0 / 0.5);
  font: 700 1rem / 1.2 var(--printed);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #5a3d0c;
  text-shadow: 0 1px 0 rgb(255 240 200 / 0.6);
}

/* Opening the box (once per visit): the lid swings up, then the cards rise out back to front */
@media (prefers-reduced-motion: no-preference) {
  .trick-box-lid { animation: lid-open 0.7s cubic-bezier(0.3, 0.7, 0.4, 1.1) 0.15s both; }
  .trick-box-cards li { animation: card-rise 0.55s cubic-bezier(0.2, 0.8, 0.3, 1.05) both; animation-delay: calc(0.55s + min(var(--i), 12) * 0.06s); }
}
@keyframes lid-open {
  from { transform: rotateX(84deg); }
}
@keyframes card-rise {
  from { transform: translateY(calc(var(--box-card-h) * 0.55 + (var(--n) - 1 - var(--i)) * var(--peek) + 12px)); }
}

@media (prefers-reduced-motion: reduce) {
  .box-card { transition: none; }
}
