:root {
  --paper: #fbfaf4;
  --rule: #bcd3ea;
  --margin: #f0a5a5;
  --pencil: #3b3b3f;
  --faint: #7a7a80;
  --red: #c62e2e;
  --sketch: 255px 15px 225px 15px / 15px 225px 15px 255px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background-color: var(--paper);
  background-image:
    linear-gradient(90deg, transparent 46px, var(--margin) 46px, var(--margin) 47.5px, transparent 47.5px),
    repeating-linear-gradient(var(--paper) 0 31px, var(--rule) 31px 32px);
  color: var(--pencil);
  font-family: "Klee One", "Hiragino Maru Gothic ProN", "Yu Gothic", serif;
  -webkit-tap-highlight-color: transparent;
}
@media (max-width: 600px) {
  body { background-image:
    linear-gradient(90deg, transparent 14px, var(--margin) 14px, var(--margin) 15.5px, transparent 15.5px),
    repeating-linear-gradient(var(--paper) 0 31px, var(--rule) 31px 32px); }
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

header { max-width: 980px; margin: 0 auto; padding: 18px 16px 6px 64px; }
@media (max-width: 600px) { header { padding-left: 26px; } }
h1 { margin: 0; font-size: 34px; font-weight: 600; letter-spacing: .04em; line-height: 1.3; }
header svg { display: block; margin: -2px 0 2px -4px; }
header p { margin: 0; font-size: 15px; color: var(--faint); }
/* the game menu (top left): for now just a list of Ei's games */
header { position: relative; }
.titlebar { display: flex; align-items: center; gap: 10px; margin-left: -46px; }
@media (max-width: 600px) { .titlebar { margin-left: -6px; } }
.games-btn { flex: none; width: 36px; height: 36px; display: grid; place-items: center; background: #fffef8;
  border: 1.8px solid var(--pencil); border-radius: 10px 4px 12px 6px / 4px 10px 6px 12px; }
.games-btn svg { margin: 0; }
.games-btn[aria-expanded="true"] { border-color: var(--red); }
.games-menu { position: absolute; z-index: 20; top: 64px; left: 18px; width: 280px; padding: 12px 12px 8px; background: #fffef8;
  border: 1.6px solid var(--pencil); border-radius: 4px 10px 6px 12px / 10px 4px 12px 6px; box-shadow: 3px 4px 0 rgba(59,59,63,.12); }
@media (max-width: 600px) { .games-menu { left: 20px; } }
.games-menu[hidden] { display: none; }
.games-menu b { display: block; font-size: 14px; color: var(--faint); font-weight: 400; margin-bottom: 4px; }
.games-menu a, .games-menu .here { display: block; padding: 8px 6px; font-size: 18px; color: var(--pencil); text-decoration: none; border-top: 1px dashed #c9c6b8; }
.games-menu a:hover { color: var(--red); }
.games-menu small { display: block; font-size: 12px; color: var(--faint); }
/* the game you are in: circled in red pen, like a picked choice */
.games-menu .here { color: var(--pencil); padding-left: 14px; }
.games-menu .here-name { position: relative; font-weight: 600; }
.games-menu .here-name::after { content: ""; position: absolute; left: -9px; right: -9px; top: -3px; bottom: -3px;
  border: 1.8px solid var(--red); border-radius: 52% 46% 55% 44% / 48% 55% 45% 52%; transform: rotate(-3deg); }
.games-menu .here-tag { margin-left: 14px; font-size: 12px; font-weight: 600; color: var(--red); white-space: nowrap; }
.red { color: var(--red); }

.wrap {
  max-width: 980px; margin: 0 auto; padding: 14px 16px 48px 64px;
  display: grid; grid-template-columns: minmax(0, 520px) minmax(0, 1fr); gap: 40px; align-items: start;
}
@media (max-width: 860px) { .wrap { grid-template-columns: 1fr; gap: 28px; } }
@media (max-width: 600px) { .wrap { padding-left: 26px; } }

.stage {
  position: relative; overflow: hidden; width: 100%; aspect-ratio: 3 / 4.4;
  border: 2px solid var(--pencil); border-radius: 6px 14px 5px 12px / 12px 5px 14px 6px;
  background: var(--paper);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
.hud { position: absolute; top: 10px; font-size: 24px; font-weight: 600; background: var(--paper);
  padding: 0 8px; line-height: 1.4; pointer-events: none; font-variant-numeric: tabular-nums; }
.hud small { font-size: 15px; font-weight: 400; }
#hudDist { left: 10px; }
#hudTimeBox { right: 10px; }
#hudTimeBox.hurry { color: var(--red); }
.sound { position: absolute; right: 10px; bottom: 8px; font-size: 14px; background: var(--paper); padding: 0 6px; }
.sound u { text-decoration-thickness: 1.5px; text-underline-offset: 3px; }

.sheet {
  position: absolute; inset: 0; background: rgba(251, 250, 244, .45);
  padding: 52px 28px 34px; display: flex; flex-direction: column;
}
.sheet[hidden] { display: none; }
.scribble-btn {
  display: block; width: 100%; padding: 10px 0; text-align: center; font-size: 22px; font-weight: 600;
  border: 2.2px solid var(--pencil); border-radius: var(--sketch); background: #fffef8;
}
.scribble-btn:active { transform: translate(1px, 2px) rotate(-.5deg); }
/* start screen choices: course as two cards, time limit as three boxes */
.pick-label { font-size: 13px; color: var(--faint); background: var(--paper); width: fit-content; padding: 0 6px; margin: 10px 0 4px -6px; }
.cards, .seg { display: grid; gap: 8px; }
.cards { grid-template-columns: 1fr 1fr; }
.seg { grid-template-columns: repeat(3, 1fr); }
.cards button, .seg button { background: #fffef8; border: 1.6px solid #b8b8bc; border-radius: var(--sketch); color: var(--faint); text-align: center; }
.cards button { padding: 6px 4px 5px; line-height: 1.35; }
.cards b { display: block; font-size: 17px; font-weight: 600; }
.cards small { font-size: 12px; }
.seg button { padding: 5px 0; font-size: 17px; }
.cards button.on, .seg button.on { border: 2.2px solid var(--red); color: var(--pencil); font-weight: 600; background: #fff; }
.cards button.on small { color: var(--red); font-weight: 400; }
.note-line { font-size: 17px; line-height: 32px; margin: 0; width: fit-content; max-width: 100%;
  background: var(--paper); padding: 0 8px; margin-left: -8px; }
.small-links > * { background: var(--paper); }
.push { flex: 1; }
.small-links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 2px 12px; margin-top: 12px; font-size: 21px; color: var(--faint); }
/* phones: tighten the start sheet a little so the bigger links still fit */
@media (max-width: 600px) {
  #startOv { padding-top: 44px; padding-bottom: 14px; }
  #startOv .small-links { margin-top: 6px; }
  #startOv .pick-label { margin-top: 6px; }
}
.small-links button { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }

/* result and ranking: a full notebook page over the road, scrolls inside the stage */
.page {
  position: absolute; inset: 0; overflow-y: auto; padding: 22px 22px 28px 30px; scrollbar-width: thin;
  touch-action: pan-y;   /* the stage blocks touch gestures for aiming; let this page scroll by finger */
  background-color: var(--paper);
  background-image:
    linear-gradient(90deg, transparent 14px, var(--margin) 14px, var(--margin) 15.5px, transparent 15.5px),
    repeating-linear-gradient(var(--paper) 0 31px, var(--rule) 31px 32px);
  background-attachment: local;
}
.page[hidden] { display: none; }
.page .note-line, .page .small-links > * { background: transparent; }
.faint { color: var(--faint); }
.head { display: flex; justify-content: space-between; align-items: baseline; }
#endOv .score { position: relative; display: inline-block; padding: 0 6px; font-size: 58px; font-weight: 600; line-height: 1.1; margin: 4px 0 0 4px; }
#endOv .score small { font-size: 24px; }
#endOv .score svg { position: absolute; left: -20px; top: -8px; width: calc(100% + 40px); height: calc(100% + 16px); overflow: visible; }
#endOv .grade { width: fit-content; margin: -4px 0 4px auto; font-size: 20px; font-weight: 600; color: var(--red); transform: rotate(-6deg); }
#endOv .redline { color: var(--red); font-size: 15px; margin: 2px 0 0; transform: rotate(-1.5deg); transform-origin: left; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 10px 0 0; text-align: center; }
.stats div { line-height: 1.3; padding: 4px 0; }
.stats small { display: block; font-size: 12px; color: var(--faint); }
.stats b { font-size: 20px; }
.stats div + div { border-left: 1.5px dashed #c9c6b8; }
.registered { margin: 10px 0 0; font-size: 17px; line-height: 1.6; }
.registered[hidden] { display: none; }
.registered .big { font-size: 26px; font-weight: 600; color: var(--red); }

/* share: a note pinned with tape */
.share { position: relative; margin: 22px 0 0; padding: 14px 12px 12px; background: #fffef8;
  border: 1.6px solid var(--pencil); border-radius: 4px 10px 6px 12px / 10px 4px 12px 6px; transform: rotate(-.6deg); }
.share::before { content: ""; position: absolute; left: 50%; top: -11px; width: 78px; height: 20px; margin-left: -39px;
  background: rgba(242, 194, 48, .5); transform: rotate(2deg); }
.share b { font-size: 17px; }
/* equal inner padding on every share button: same base padding, leftover width split evenly (flex-grow) */
.share-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.share-row a { color: inherit; text-decoration: none; text-align: center; }
.share-row button, .share-row a { flex: 1 1 auto; white-space: nowrap; font-size: 13px; letter-spacing: -.02em; font-weight: 600; padding: 8px 10px;
  border: 1.6px solid var(--pencil); border-radius: var(--sketch); background: var(--paper); }
.share-row .line { color: #06893f; border-color: #06893f; }
.share-row .copy { flex-basis: 100%; }
.retry { margin-top: 18px; }

/* name entry: always open, in a box like the share note */
.namebox { margin: 18px 0 0; padding: 12px 12px 10px; background: #fffef8;
  border: 1.6px solid var(--pencil); border-radius: 10px 4px 12px 6px / 4px 10px 6px 12px; transform: rotate(.4deg); }
.namebox b { display: block; font-size: 17px; line-height: 1.6; }
.namelabel { display: block; font-size: 13px; color: var(--faint); line-height: 1.6; }
.nameline { display: flex; gap: 8px; align-items: flex-end; }
.nameline input { flex: 1; min-width: 0; border: 0; border-bottom: 2px solid var(--pencil); background: transparent; font: inherit; font-size: 20px; padding: 2px 4px; outline: none; border-radius: 0; }
.nameline input::placeholder { color: #b5b3ab; }
.nameline button { flex: none; padding: 6px 12px; font-size: 15px; font-weight: 600; border: 1.8px solid var(--red); color: var(--red); border-radius: var(--sketch); background: #fffef8; }
.nameline button:disabled { opacity: .5; }
.regmsg { margin: 6px 0 0; font-size: 14px; color: var(--red); min-height: 1em; }

.rk-title { font-size: 22px; font-weight: 600; margin: 0; display: inline-block;
  background: linear-gradient(transparent 62%, rgba(242, 194, 48, .55) 62%, rgba(242, 194, 48, .55) 92%, transparent 92%); }
ol.board { list-style: none; margin: 10px 0 14px; padding: 0; min-height: 64px; }
ol.board li { display: flex; align-items: baseline; gap: 10px; line-height: 32px; font-size: 16px; }
ol.board .n { width: 2em; text-align: right; color: var(--faint); font-variant-numeric: tabular-nums; }
ol.board li:nth-child(-n+3) .n { color: var(--red); font-weight: 600; }
ol.board .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
ol.board .d { font-weight: 600; font-variant-numeric: tabular-nums; }
ol.board li.me { background: linear-gradient(transparent 55%, rgba(198, 46, 46, .16) 55%, rgba(198, 46, 46, .16) 92%, transparent 92%); }
ol.board li.me .who::after { content: " ← あなた"; color: var(--red); font-size: 13px; }
ol.board li.msg { color: var(--faint); justify-content: center; }

aside h2 { font-size: 22px; font-weight: 600; margin: 0 0 4px; display: inline-block;
  background: linear-gradient(transparent 62%, rgba(242, 194, 48, .55) 62%, rgba(242, 194, 48, .55) 92%, transparent 92%); padding: 0 2px; }
aside ol, aside ul { margin: 0 0 28px; padding-left: 24px; font-size: 16px; line-height: 32px; }
aside li::marker { color: var(--faint); }
aside .rank { list-style: none; padding-left: 0; }
aside .rank li { display: flex; gap: 14px; }
aside .rank .n { width: 1.4em; color: var(--faint); }
aside .rank .d { width: 5em; font-weight: 600; }
aside .rank .m { color: var(--faint); font-size: 14px; }
aside .rank li.fresh .d { color: var(--red); }
aside .rank .empty { color: var(--faint); }
.mode-tag { font-size: 15px; color: var(--faint); font-weight: 400; }
