/* ThisIsAStartup.com: notebook paper styles */

:root {
  --paper: #FDF6D8;     /* page */
  --desk: #E9DCB8;      /* background behind the page */
  --rule: #E6D9A8;      /* ruled lines */
  --margin: #D9A98A;    /* red-ish margin line */
  --ink: #3A2A1F;       /* main text (espresso) */
  --pen: #6B4A33;       /* handwriting and secondary text (walnut) */
  --butter: #F6E39A;    /* highlighter */
  --line: 32px;         /* ruled line spacing; all vertical rhythm uses this */
  --gutter: 88px;       /* left edge of text, right of the margin line */
  --hand: 'Caveat', 'Bradley Hand', cursive;
  --serif: 'Newsreader', Georgia, serif;
}

* { box-sizing: border-box; }

html { background: var(--desk); }
body { overflow-x: clip; }

body {
  margin: 0;
  font-family: var(--serif);
  font-size: 18px;
  line-height: var(--line);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* ---------- The book: page + index tabs ---------- */

.book {
  position: relative;
  max-width: 760px;
  margin: 40px auto;
}

.sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: calc(100svh - 80px);
  background: var(--paper);
  border-radius: 2px 6px 6px 2px;
  box-shadow: 0 1px 2px rgba(58, 42, 31, .10), 0 10px 30px rgba(58, 42, 31, .10);
  view-transition-name: page;   /* lets only the page flip, not the whole screen */
}

/* Index tabs sticking out of the right edge */
.tabs {
  position: absolute;
  left: 100%;
  top: 128px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tabs a {
  display: block;
  padding: 6px 16px 6px 12px;
  border-radius: 0 6px 6px 0;
  background: var(--butter);
  color: var(--pen);
  font-family: var(--hand);
  font-size: 22px;
  line-height: 28px;
  text-decoration: none;
  box-shadow: 2px 1px 3px rgba(58, 42, 31, .10);
  transition: transform .15s ease;
}
.tabs a:nth-child(2n) { background: #EFC7AE; }
.tabs a:hover { transform: translateX(3px); }
.tabs a[aria-current="page"] { background: var(--paper); box-shadow: none; }

/* ---------- Page header: weekday circle + date + day count ---------- */

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  height: calc(var(--line) * 3);
  padding: 0 32px 10px var(--gutter);
  border-bottom: 2px solid var(--rule);
  font-size: 12px;
  letter-spacing: .12em;
  color: var(--pen);
}

.weekdays { display: flex; gap: 14px; }
.weekdays span { position: relative; width: 12px; text-align: center; }
.weekdays .circle {
  position: absolute;
  left: 50%; top: 50%;
  width: 34px; height: 28px;
  transform: translate(-50%, -52%) rotate(-6deg);
  overflow: visible;
  pointer-events: none;
}
.circle path {
  fill: none;
  stroke: var(--pen);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 0;
}

.fields { display: flex; gap: 20px; align-items: flex-end; }
.field { display: flex; align-items: flex-end; gap: 6px; }
.field .blank {
  min-width: 48px;
  padding: 0 6px;
  border-bottom: 1px solid var(--pen);
  font-family: var(--hand);
  font-size: 24px;
  line-height: 24px;
  letter-spacing: 0;
  text-align: center;
  color: var(--pen);
}
.field .blank.wide { min-width: 120px; }

/* ---------- Ruled writing area ---------- */

.ruled {
  position: relative;
  flex: 1;
  padding: var(--line) 32px 0 var(--gutter);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0 calc(var(--line) - 1px),
    var(--rule) calc(var(--line) - 1px) var(--line)
  );
  background-position: 0 -6px;   /* nudges lines up so text sits on them */
}
.ruled::before {                   /* margin line */
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  left: 64px;
  width: 1px;
  background: var(--margin);
}

.ruled > * { max-width: 34em; }

h1 {
  margin: 0 0 var(--line);
  font-size: 42px;
  font-weight: 500;
  line-height: calc(var(--line) * 2);
  letter-spacing: -.01em;
}

p { margin: 0 0 var(--line); }

.hand {
  font-family: var(--hand);
  font-size: 25px;
  color: var(--pen);
}

mark {
  background: linear-gradient(transparent 50%, var(--butter) 50%);
  color: inherit;
  padding: 0 2px;
}

a { color: var(--pen); text-decoration-thickness: 1px; text-underline-offset: 4px; }

/* ---------- Page footer: printed page number ---------- */

.page-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: calc(var(--line) * 2);
  padding: 0 32px 0 var(--gutter);
  font-size: 13px;
  color: var(--pen);
}
.page-foot .imprint { letter-spacing: .08em; opacity: .7; }
.page-foot .num { font-variant-numeric: oldstyle-nums; font-size: 15px; }

/* Even pages put the number on the left, like a real book */
.sheet[data-even] .page-foot { flex-direction: row-reverse; }

/* ---------- Handwriting ---------- */

.js [data-write]:not(.ready) { visibility: hidden; }

.w {
  display: inline-block;
  padding-right: 3px;
  margin-right: -3px;
  -webkit-mask-image: linear-gradient(90deg, #000 44%, transparent 56%);
          mask-image: linear-gradient(90deg, #000 44%, transparent 56%);
  -webkit-mask-size: 250% 100%;
          mask-size: 250% 100%;
  -webkit-mask-repeat: no-repeat;
          mask-repeat: no-repeat;
  -webkit-mask-position: 100% 0;
          mask-position: 100% 0;
}
.w.go { animation: write linear forwards; }
.w.done { -webkit-mask: none; mask: none; }
@keyframes write { to { -webkit-mask-position: 0 0; mask-position: 0 0; } }

/* ---------- Margin notes ---------- */

.mk {
  position: relative;
  cursor: help;
  border-bottom: 1px dashed var(--pen);
  outline: none;
}
.mk:focus-visible { background: var(--butter); }
.nt {
  position: absolute;
  left: 0;
  font-family: var(--hand);
  font-size: 23px;
  line-height: var(--line);
  color: var(--pen);
  white-space: nowrap;
  transform: rotate(-1.5deg);
  transform-origin: left center;
  pointer-events: none;
}
.nt:not(.ready), .mk:not(.shown) .nt { visibility: hidden; }

/* ---------- Page turn (built by notebook.js) ---------- */

.flip-stage {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 5;
  perspective: 2200px;
  pointer-events: none;
}
.flip-strip {
  position: absolute;
  top: 0;
  height: 100%;
  transform-style: preserve-3d;
  transform-origin: 0 50%;
}
.flip-face, .flip-back {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  right: -1px;                      /* overlap strips slightly so no seams show */
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flip-back {
  transform: rotateY(180deg);
  background-color: #F8EFCC;        /* back side of the paper */
  background-image: repeating-linear-gradient(to bottom, transparent 0 31px, rgba(230, 217, 168, .45) 31px 32px);
}
.flip-shade { position: absolute; inset: 0; background: #3A2A1F; opacity: 0; }
.flip-shadow {
  position: absolute;
  top: 0; left: 0;
  width: 160px;
  height: 100%;
  background: linear-gradient(to right, rgba(58, 42, 31, .35), rgba(58, 42, 31, 0));
  opacity: 0;
}

/* Copies used during a turn: show handwriting as already written, or hidden on a page not yet opened */
.frozen .w.go { animation: none; -webkit-mask: none; mask: none; }
.frozen .circle path { animation: none !important; stroke-dashoffset: 0 !important; }
.preview [data-write], .preview .circle { visibility: hidden; }

/* ---------- Small screens ---------- */

@media (max-width: 900px) {
  .book { margin: 56px 12px 16px; }
  .tabs {
    left: 16px;
    top: auto;
    bottom: 100%;
    flex-direction: row;
  }
  .tabs a { border-radius: 6px 6px 0 0; padding: 4px 14px 2px; box-shadow: none; }
  .tabs a:hover { transform: translateY(-2px); }
}

@media (max-width: 600px) {
  :root { --gutter: 48px; }
  body { font-size: 17px; }
  .ruled { padding-right: 20px; }
  .ruled::before { left: 32px; }
  .page-head {
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-end;
    padding-right: 20px;
  }
  .page-foot { padding-right: 20px; }
  h1 { font-size: 34px; }
}

/* ---------- Motion (skipped for people who turn motion off) ---------- */

@media (prefers-reduced-motion: no-preference) {

  /* Circle draws itself around today's weekday */
  .circle path {
    stroke-dashoffset: 100;
    animation: draw .7s .35s ease-out forwards;
  }
  @keyframes draw { to { stroke-dashoffset: 0; } }

  /* Built-in page flip, used for the browser's back/forward buttons.
     Clicking links uses the bending page turn in notebook.js instead. */
  @view-transition { navigation: auto; }

  ::view-transition-group(page) { animation-duration: .9s; }
  ::view-transition-old(page),
  ::view-transition-new(page) {
    height: 100%;
    object-fit: none;
    object-position: top;
    transform-origin: left center;
  }

  /* Forward: current page turns away to the left, next page is underneath */
  ::view-transition-new(page) { animation: none; z-index: 1; }
  ::view-transition-old(page) {
    z-index: 2;
    animation: turn-away .9s cubic-bezier(.45, .05, .35, 1) both;
  }

  /* Back: the previous page turns back over on top */
  html:active-view-transition-type(back)::view-transition-old(page) { animation: none; z-index: 1; }
  html:active-view-transition-type(back)::view-transition-new(page) {
    z-index: 2;
    animation: turn-back .9s cubic-bezier(.45, .05, .35, 1) both;
  }

  @keyframes turn-away {
    20%  { transform: perspective(2400px) rotateY(-14deg) skewY(-1.5deg); }
    100% { transform: perspective(2400px) rotateY(-105deg) skewY(-3deg); filter: brightness(.8); }
  }
  @keyframes turn-back {
    0%   { transform: perspective(2400px) rotateY(-105deg) skewY(-3deg); filter: brightness(.8); }
    80%  { transform: perspective(2400px) rotateY(-14deg) skewY(-1.5deg); }
  }
}
