:root {
  --lime: #8db41f;
  --leaf: #1d340b;
  --leaf-deep: #0f1e05;
  --cream: #f3f8e2;
  --paper: #f6f7f8;
  --dot: #8f9296;
  --light: #c9cacd;
  --dark: #5d5f63;
  --hatch: #a3a5a9;
  --tree: #3a3c40;
  --ink: #34363a;
  --pencil: #4b4d55;
  --muted: #5f6166;
  --cell: 32px;
  --pad-w: min(366px, calc(100vw - 24px));
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--lime);
  color: var(--leaf);
  font-family: 'Space Mono', ui-monospace, monospace;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--leaf); outline-offset: 2px; }

.app {
  max-width: 420px;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.bar {
  width: 100%;
  height: 56px;
  padding: 0 8px 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: none;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand b { font-size: 16px; letter-spacing: .08em; }
.brand span { font-size: 12px; color: #33521a; }
.bar-actions { display: flex; }
.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  line-height: 1;
}

.pencil { font-family: Kalam, cursive; color: var(--pencil); }

/* notebook pad */
.pad { position: relative; width: var(--pad-w); margin-top: 22px; flex: none; }
.rings { position: absolute; left: 0; right: 0; top: -12px; display: flex; justify-content: space-evenly; z-index: 2; }
.rings i { width: 9px; height: 26px; border-radius: 5px 5px 4px 4px; background: #16220c; box-shadow: 1px 1px 0 rgba(0, 0, 0, .25); }
.page {
  background: var(--paper);
  color: var(--ink);
  border-radius: 2px 2px 14px 14px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .1), 0 16px 30px rgba(20, 40, 0, .22);
  padding: 26px 7px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* course */
.course { margin: 0 auto; position: relative; width: calc(var(--cell) * 11); height: calc(var(--cell) * 15); }
.cells { display: grid; grid-template-columns: repeat(11, var(--cell)); grid-auto-rows: var(--cell); }
.cell { position: relative; display: flex; align-items: center; justify-content: center; }
.cell.light { background: var(--light); }
.cell.dark { background: var(--dark); }
.cell.hatch { background: repeating-linear-gradient(135deg, var(--hatch) 0 1.1px, transparent 1.1px calc(var(--cell) * .141421)); }
.dot { width: 4px; height: 4px; border-radius: 50%; background: var(--dot); }
.cell.dark .dot { background: var(--paper); }
.cell svg { width: 75%; height: 75%; color: var(--tree); }
.cup { width: 60%; height: 60%; border-radius: 50%; background: var(--tree); }
.slope { display: flex; width: 62%; height: 62%; color: var(--tree); }
.slope svg { width: 100%; height: 100%; }
.bigfoot {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  border: 0;
  padding: 0;
  background: var(--paper);
  color: var(--tree);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  border-radius: 6px;
}
.bigfoot svg { width: 70%; height: 70%; }
.bigfoot.found { cursor: default; }
.bigfoot.found::after { content: ""; position: absolute; inset: 1px; border: 2px solid var(--pencil); border-radius: 50%; opacity: .8; }

.overlay { position: absolute; inset: 0; pointer-events: none; }
.overlay svg { position: absolute; inset: 0; overflow: visible; }
.stroke-line { fill: none; stroke: var(--pencil); stroke-width: 2.2; stroke-linecap: round; opacity: .85; }
.stroke-line.fresh { stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: draw .45s ease-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

.mark {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
}
.landed::after { content: ""; width: 44%; height: 44%; border-radius: 50%; border: 2px solid var(--pencil); opacity: .8; box-sizing: border-box; }
.cross::before, .cross::after { content: ""; position: absolute; width: 40%; height: 2px; border-radius: 1px; background: #b9bbbf; transform: rotate(45deg); }
.cross::after { transform: rotate(-45deg); }

.ball {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .45s cubic-bezier(.3, .7, .3, 1);
}
.ball::after { content: ""; width: 15px; height: 15px; border-radius: 50%; background: #fff; border: 2.5px solid #2a2b2e; box-sizing: border-box; transition: transform .3s .4s; }
.ball.sunk::after { transform: scale(0); }

.target {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  border: 0;
  padding: 0;
  background: transparent;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
.target::before { content: ""; position: absolute; inset: -6px; }
.target::after { content: ""; width: 82%; height: 82%; border-radius: 50%; border: 2px dashed var(--ink); box-sizing: border-box; transition: transform .15s, background .15s; }
.target:hover::after, .target:focus-visible::after { transform: scale(1.12); background: rgba(52, 54, 58, .12); border-style: solid; }
.target.sink::after { border-color: var(--leaf); border-width: 2.5px; }
.target:focus-visible { outline: none; }

/* page footer */
.foot { display: flex; align-items: center; justify-content: space-between; padding: 0 6px; font-size: 14px; height: 30px; }
.foot-right { display: flex; gap: 14px; align-items: center; }
.foot-right > div, .foot > div { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.foot > .foot-right { gap: 16px; }
.foot .pencil { font-size: 22px; line-height: 30px; height: 30px; display: inline-block; min-width: 1.1em; text-align: center; transform: rotate(-3deg); }

/* tray */
.tray { width: var(--pad-w); flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 14px; padding-top: 16px; }
.die-row { display: flex; align-items: center; gap: 16px; min-height: 92px; }
.die-row.done { min-height: 54px; }
.share-preview {
  margin: 0;
  padding: 12px 14px;
  border: 1.5px dashed rgba(29, 52, 11, .45);
  border-radius: 10px;
  font: 13px/1.6 'Space Mono', monospace;
  color: var(--leaf);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-align: center;
}
.die {
  width: 84px;
  height: 84px;
  flex: none;
  border: 0;
  border-radius: 18px;
  padding: 14px;
  background: var(--leaf);
  box-shadow: 0 5px 0 var(--leaf-deep);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  transform: rotate(-6deg);
  transition: transform .12s, box-shadow .12s;
}
.die i { width: 12px; height: 12px; border-radius: 50%; background: var(--cream); place-self: center; }
.die i.off { background: transparent; }
.die:not(:disabled):hover { transform: rotate(-6deg) translateY(-2px); box-shadow: 0 7px 0 var(--leaf-deep); }
.die:not(:disabled):active { transform: rotate(-6deg) translateY(4px); box-shadow: 0 1px 0 var(--leaf-deep); }
.die:disabled { cursor: default; }
.die.idle { animation: nudge 2.4s ease-in-out infinite; touch-action: none; cursor: grab; }
.die.idle span { grid-column: 1 / -1; grid-row: 1 / -1; place-self: center; color: var(--cream); font-weight: 700; font-size: 14px; letter-spacing: .08em; transform: rotate(6deg); }
.die.putt span { grid-column: 1 / -1; grid-row: 1 / -1; place-self: center; color: var(--cream); font-weight: 700; font-size: 34px; line-height: 1; transform: rotate(6deg); }
body.dragging, body.dragging * { cursor: grabbing !important; }
.die.thrown {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 20;
  pointer-events: none;
  animation: none;
  box-shadow: 0 5px 0 var(--leaf-deep), 0 14px 22px rgba(15, 30, 5, .35);
  will-change: transform;
}
@keyframes nudge { 0%, 80%, 100% { transform: rotate(-6deg); } 86% { transform: rotate(-12deg); } 93% { transform: rotate(0deg); } }

.note { line-height: 1.1; color: var(--leaf); font-family: Kalam, cursive; }
.note .big { font-size: 26px; font-weight: 700; }
.note .small { font-size: 17px; }
.note-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.chips { display: flex; gap: 6px; }
.chip {
  position: relative;
  height: 32px;
  padding: 0 12px;
  border: 1.5px solid var(--leaf);
  border-radius: 999px;
  background: transparent;
  color: var(--leaf);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.chip::before { content: ""; position: absolute; inset: -6px -3px; }
.chip:hover { background: rgba(29, 52, 11, .1); }
.chip:active { background: rgba(29, 52, 11, .2); }
.hint-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; min-height: 18px; }
.hint { margin: 0; font-size: 12px; color: #2a4512; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mulligans { font-size: 12px; color: #2a4512; white-space: nowrap; }
.mulligans .pencil { color: var(--leaf); font-size: 17px; }

.next-btn, .share-btn {
  height: 56px;
  border: 0;
  border-radius: 12px;
  background: var(--leaf);
  color: var(--cream);
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 5px 0 var(--leaf-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
}
.next-btn:active, .share-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--leaf-deep); }

.card9 { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); border: 1.5px solid var(--leaf); border-radius: 10px; overflow: hidden; background: var(--paper); box-shadow: 0 3px 0 rgba(15, 30, 5, .25); color: var(--ink); }
.card9 div { height: 46px; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 4px 0; border-left: 1px solid var(--light); }
.card9 div:first-child { border-left: 0; }
.card9 div.now { background: #e4e5e8; }
.card9 small { font-size: 10px; color: #6b6d72; }
.card9 .pencil { font-size: 18px; line-height: 1; }

/* results */
.results { padding: 34px 13px 8px; display: flex; flex-direction: column; gap: 22px; }
.results h1 { font-size: 30px; margin: 0; }
.results .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.score { display: grid; grid-template-columns: 40px repeat(9, minmax(0, 1fr)) 34px; align-items: center; font-size: 12px; row-gap: 6px; text-align: center; }
.score .h { color: #6b6d72; font-size: 10px; }
.score .lead { text-align: left; font-size: 10px; color: #6b6d72; letter-spacing: .04em; }
.score .s { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; font-size: 17px; }
.score .s.under { border: 1.6px solid var(--pencil); border-radius: 50%; }
.score .s.over { border: 1.6px solid var(--pencil); border-radius: 3px; }
.total-row { display: flex; justify-content: space-between; align-items: center; font-size: 14px; }
.total-ring { font-size: 30px; display: inline-block; border: 2px solid var(--pencil); border-radius: 50%; padding: 0 10px; transform: rotate(-4deg); }
.rule { border-top: 1.5px dashed #b9bbbf; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); text-align: center; gap: 4px; }
.stats b { display: block; font-size: 24px; }
.stats span { font-size: 10px; letter-spacing: .06em; text-transform: uppercase; }
.next { text-align: center; font-size: 12px; color: var(--leaf); }
.next b { display: block; font-size: 22px; letter-spacing: .06em; margin-top: 2px; }

/* dialogs */
.sheet {
  width: min(360px, calc(100vw - 32px));
  border: 0;
  border-radius: 14px;
  padding: 18px 20px 22px;
  background: var(--paper);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.55;
  box-shadow: 0 20px 50px rgba(15, 30, 5, .35);
}
.sheet::backdrop { background: rgba(29, 52, 11, .45); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin: -6px -10px 4px 0; }
.sheet h2 { font-size: 18px; margin: 0; }
.sheet ol { padding-left: 20px; }
.legend { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.legend li { display: flex; align-items: center; gap: 12px; }
.swatch { width: 26px; height: 26px; flex: none; border-radius: 6px; display: flex; align-items: center; justify-content: center; }
.swatch.light { background: var(--light); }
.swatch.dark { background: var(--dark); }
.swatch.hatch { background: repeating-linear-gradient(135deg, var(--hatch) 0 1.1px, transparent 1.1px 4px); }
.swatch i { width: 4px; height: 4px; border-radius: 50%; background: var(--dot); }
.swatch.dark i { background: var(--paper); }
.swatch.tree { color: var(--tree); }
.sheet .stats { margin-top: 12px; }

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  top: 16px;
  transform: translate(-50%, -20px);
  background: var(--leaf);
  color: var(--cream);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 900px) and (min-height: 640px) {
  :root { --pad-w: calc(var(--cell) * 11 + 14px); }
  .app {
    max-width: 1100px;
    display: grid;
    grid-template-columns: auto 340px;
    grid-template-rows: 72px 1fr;
    column-gap: 64px;
    justify-content: center;
    align-items: center;
    padding: 0 32px 32px;
  }
  .bar { grid-column: 1 / -1; height: 72px; padding: 0; }
  .brand b { font-size: 20px; }
  .brand span { font-size: 14px; }
  .pad { margin-top: 0; align-self: center; }
  .tray { width: 340px; flex: none; align-self: center; padding-top: 0; gap: 18px; }
  .die { width: 96px; height: 96px; padding: 16px; border-radius: 20px; }
  .die i { width: 14px; height: 14px; }
  .note .big { font-size: 30px; }
  .note .small { font-size: 19px; }
  .hint { text-align: left; }
}

@media (max-height: 740px) and (max-width: 899px) {
  .pad { margin-top: 18px; }
  .tray { gap: 10px; padding-top: 10px; }
  .die { width: 64px; height: 64px; padding: 10px; border-radius: 14px; }
  .die i { width: 9px; height: 9px; }
  .die.idle span { font-size: 12px; }
  .die.putt span { font-size: 26px; }
  .die-row { min-height: 70px; }
  .die-row.done { min-height: 44px; }
  .note .big { font-size: 22px; }
  .note .small { font-size: 15px; }
  .card9 div { height: 38px; padding: 2px 0; }
  .next-btn, .share-btn { height: 48px; }
  .results { padding-top: 26px; gap: 14px; }
  .results h1 { font-size: 26px; }
  .share-preview { padding: 8px 12px; font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .stroke-line.fresh { stroke-dashoffset: 0; }
}
