:root {
  --paper:  #F4F1EA;
  --paper2: #EAE6DC;
  --ink:    #111111;
  --ink-2:  #777777;
}
* { margin: 0; padding: 0; box-sizing: border-box; font: inherit; }
html, body { height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
  cursor: crosshair;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: "Baumans", sans-serif;
}
body.review         { cursor: grab; }
body.review.panning { cursor: grabbing; }

/* Canvas owns all gestures — the game handles pinch/pan itself, so tell the
   browser not to scroll, zoom, or fire a tap delay on it. */
svg#sheet { position: fixed; inset: 0; display: block; touch-action: none; }

button { touch-action: manipulation; }

/* ---- SVG element styling ---- */
.grid-min { stroke: rgba(0,0,0,.04);  stroke-width: 1; }
.grid-maj { stroke: rgba(0,0,0,.08);  stroke-width: 1; }
.frame    { fill: none; stroke: rgba(0,0,0,.14); stroke-width: 1; }
.baseline { stroke: rgba(0,0,0,.08);  stroke-width: 1; stroke-dasharray: 1 8; }

.ln    { fill: none; stroke: var(--ink); stroke-width: 3;   stroke-linecap: round; }
.ring  { fill: none; stroke: var(--ink); stroke-width: 2; }
.dot   { fill: var(--ink); }

.dim   { fill: none; stroke: var(--ink-2); stroke-width: 1; }
.ext   { fill: none; stroke: var(--ink-2); stroke-width: 1; opacity: .6; }

.ghost     { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 7; opacity: .28; }
.ghost-dot { fill: var(--ink); opacity: .35; }
.string { stroke: var(--ink); stroke-width: 1; opacity: .4; }

.txt      { font-family: "Baumans", sans-serif; fill: var(--ink);   font-size: 16px; letter-spacing: .5px; }
.txt-d    { font-family: "Baumans", sans-serif; fill: var(--ink-2); font-size: 15px; letter-spacing: .5px; }
.lbl-lean { font-family: "Baumans", sans-serif; fill: var(--ink);   font-size: 19px; letter-spacing: 1px; }

/* ---- HTML overlays ---- */
.overlay { position: fixed; pointer-events: none; }

#title {
  top: calc(22px + env(safe-area-inset-top));
  left: calc(30px + env(safe-area-inset-left));
  font-size: 26px; font-weight: 400; letter-spacing: 8px;
  text-transform: uppercase;
  opacity: .88;
}
#title::after {
  content: ""; display: block;
  width: 46px; height: 1.5px; margin-top: 6px;
  background: var(--ink); opacity: .2;
}

#stats {
  top: calc(24px + env(safe-area-inset-top));
  right: calc(30px + env(safe-area-inset-right));
  display: grid; grid-template-columns: auto auto;
  gap: 2px 16px; text-align: right;
  font-size: 17px;
}
#stats .k { color: var(--ink-2); letter-spacing: 3px; text-transform: uppercase; font-size: 12px; align-self: center; }
#stats .v { color: var(--ink); font-variant-numeric: tabular-nums; }
#stScore   { min-width: 4.5ch; }

/* ---- end-of-level buttons ---- */
#endBtns {
  position: fixed;
  bottom: calc(28px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100vw - 32px);
  gap: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .5s ease;
  z-index: 10;
  -webkit-user-select: none; user-select: none;
}
#endBtns.show { opacity: 1; pointer-events: auto; }
#gameOverLabel {
  display: none;
  font-size: 17px; letter-spacing: 3px; text-transform: uppercase;
  color: #CC2200;
  align-self: center;
  padding: 10px 0;
}
#endBtns.gameover #gameOverLabel { display: block; }
#endBtns.gameover #nextLevelBtn  { display: none; }
#bestLabel {
  display: none;
  font-size: 15px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--ink-2);
  align-self: center;
  padding: 10px 0;
}
#endBtns.gameover #bestLabel { display: block; }
#bestLabel b { color: var(--ink); font-variant-numeric: tabular-nums; }
#endBtns button {
  font-family: "Baumans", sans-serif;
  font-size: 16px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--ink);
  background: transparent;
  border: 1.5px solid var(--ink);
  border-radius: 0;
  padding: 10px 32px;
  cursor: pointer;
  transition: background .15s ease;
}
#endBtns button:hover  { background: rgba(0,0,0,.07); }
#endBtns button:active { transform: translateY(1px); }

/* ---- share button (gameover only) ---- */
#shareBtn { display: none; }
#endBtns.gameover #shareBtn { display: block; }

/* ---- share modal ---- */
#shareModal {
  display: none;
  position: fixed; inset: 0; z-index: 30;
  align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(244, 241, 234, .92);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
#shareModal.show { display: flex; }
.share-card {
  width: 100%; max-width: 480px;
  padding: 24px 24px 20px;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  box-shadow: 5px 5px 0 rgba(0,0,0,.12);
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
#sharePreview {
  width: 100%; height: 260px;
  background: var(--paper);
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
#sharePreview svg { max-width: 100%; max-height: 100%; display: block; }
#shareCaption {
  font-size: 14px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--ink-2); text-align: center;
}
.share-actions { display: flex; gap: 12px; }
.share-actions button {
  font-family: "Baumans", sans-serif;
  font-size: 14px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--ink); background: transparent;
  border: 1.5px solid var(--ink); border-radius: 0;
  padding: 10px 18px; cursor: pointer;
  transition: background .15s ease;
  white-space: nowrap;
}
.share-actions button:hover  { background: rgba(0,0,0,.07); }
.share-actions button:active { transform: translateY(1px); }

/* ---- intro overlay ---- */
#intro {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(244, 241, 234, .90);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  transition: opacity .5s ease;
  cursor: pointer;
}
#intro.hide { opacity: 0; pointer-events: none; }
.intro-card {
  width: 100%; max-width: 384px;
  padding: 32px 34px 28px; text-align: center;
  background: var(--paper);
  border: 1.5px solid var(--ink); border-radius: 0;
  box-shadow: 5px 5px 0 rgba(0,0,0,.12);
  cursor: default;
}
.intro-card h1 {
  font-size: 26px; letter-spacing: 9px; text-transform: uppercase; color: var(--ink);
}
.intro-rule { width: 46px; height: 1.5px; margin: 10px auto 20px; background: var(--ink); opacity: .2; }
.intro-dia { width: 100%; max-width: 230px; height: auto; display: block; margin: 0 auto 20px; }
.intro-card p {
  font-size: 16px; line-height: 1.55; color: var(--ink);
  margin: 0 auto 10px; max-width: 304px;
}
.intro-card p em { font-style: normal; color: var(--ink-2); }
.intro-card button {
  margin-top: 16px;
  font-size: 16px; letter-spacing: 3px; text-transform: uppercase; color: var(--ink);
  background: transparent;
  border: 1.5px solid var(--ink); border-radius: 0;
  padding: 9px 32px; cursor: pointer;
  transition: background .15s ease;
}
.intro-card button:hover  { background: rgba(0,0,0,.07); }
.intro-card button:active { transform: translateY(1px); }

/* ---- intro high-score line ---- */
.intro-best {
  margin: 6px auto 0 !important;
  font-size: 13px; letter-spacing: 3px; text-transform: uppercase;
  color: var(--ink-2);
}
.intro-best b { color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 400; }

/* ---- small screens / phones ---- */
@media (max-width: 480px) {
  #title { top: calc(16px + env(safe-area-inset-top)); left: calc(20px + env(safe-area-inset-left)); font-size: 21px; letter-spacing: 6px; }
  #stats { top: calc(18px + env(safe-area-inset-top)); right: calc(20px + env(safe-area-inset-right)); font-size: 15px; }
  /* Stack the end-of-level controls so each fits comfortably on its own line. */
  #endBtns {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    bottom: calc(18px + env(safe-area-inset-bottom));
    width: min(280px, calc(100vw - 48px));
  }
  #endBtns button { width: 100%; padding: 13px 20px; font-size: 14px; letter-spacing: 2px; }
  #gameOverLabel, #bestLabel { text-align: center; padding: 2px 0; }
  .intro-card { padding: 26px 24px 24px; }
  .intro-card h1 { font-size: 22px; letter-spacing: 6px; }
  .intro-card p { font-size: 15px; }
  .share-actions { flex-wrap: wrap; justify-content: center; }
}
