@font-face {
  font-family: "ChaengLabel";
  src: url("fonts/label.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

/* Kraft board, manila tags, dark ink, one vermilion stamp color. */
:root {
  --board: #c7a06b;
  --tag: #f4e3bf;
  --tag-edge: #d9bf8c;
  --field: #fffaf0;
  --ink: #2b1d0e;
  --ink-soft: #6b5233;
  --stamp: #b32d16;
  --on-ink: #f4e3bf;
  --shade: rgb(43 29 14 / .55);
  --grain: .18;
  --grain-img: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85 .55' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .16 0 0 0 0 .1 0 0 0 0 .04 0 0 0 1.1 -.2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  color-scheme: light;
}

/* Night version of the same label, for harbor light game at night. */
@media (prefers-color-scheme: dark) {
  :root {
    --board: #1b140d;
    --tag: #2b2116;
    --tag-edge: #3d2f20;
    --field: #1b140d;
    --ink: #f1e2c2;
    --ink-soft: #b9a27e;
    --stamp: #ff6b47;
    --on-ink: #1b140d;
    --shade: rgb(0 0 0 / .6);
    --grain: .08;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--board);
}

/* Paper grain behind everything, so the board reads as kraft and not flat beige. */
html::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: var(--grain);
  background-image: var(--grain-img);
}

body {
  margin: 0 auto;
  max-width: 560px;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    calc(env(safe-area-inset-top) + 8px)
    max(16px, env(safe-area-inset-right))
    calc(env(safe-area-inset-bottom) + 28px)
    max(16px, env(safe-area-inset-left));
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-tap-highlight-color: transparent;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.display {
  font-family: "ChaengLabel", -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-weight: 800;
  font-synthesis: none;
  letter-spacing: 0;
}

button { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

/* Label sticker buttons: square-ish, thick ink edge, filled when on. */
.lbl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color .12s ease, color .12s ease, transform .08s ease;
}
.lbl:active { transform: translateY(1px); }
.lbl[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); }

/* Header */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
}
.title { margin: 0; font-size: 38px; line-height: 1; }

/* Count and ruler stay pinned while scrolling, so the last check at the bottom
   of the list still shows what is left and where the done stamp lands. */
.tally {
  position: sticky;
  top: 0;
  z-index: 5;
  isolation: isolate;
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 8px -16px 12px;
  padding: 8px 16px 10px;
  background: var(--board);
  transition: box-shadow .15s ease;
}
.tally::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: var(--grain);
  background-image: var(--grain-img);
}
/* Shadow only once pinned: it marks the bar as lifted above the list scrolling under it. */
.tally.stuck { box-shadow: 0 10px 12px -10px rgb(0 0 0 / .5); }
.tally-line { flex: none; margin: 0; display: flex; align-items: baseline; gap: 5px; }
.tally-num { font-size: 46px; line-height: .9; font-variant-numeric: tabular-nums; }
.tally-unit { font-size: 17px; font-weight: 800; }
.tally-total { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Progress drawn as a fish ruler: ticks every 5 and 10 percent. */
.ruler {
  position: relative;
  isolation: isolate; /* keeps the fill's z-index inside the ruler, under the done stamp */
  flex: 1;
  min-width: 72px;
  height: 16px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--tag);
  overflow: hidden;
}
.ruler::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(90deg, var(--ink) 0 2px, transparent 2px 10%) left bottom / 100% 60% no-repeat,
    repeating-linear-gradient(90deg, var(--ink) 0 1px, transparent 1px 5%) left bottom / 100% 30% no-repeat;
}
.ruler-fill {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 1;
  width: 0;
  background: var(--ink);
  transition: width .25s ease;
}

/* Lands on top of the full ruler, on its own scrap of manila so the red reads over ink. */
.done-stamp {
  position: absolute;
  z-index: 2;
  top: 50%;
  right: 24px;
  margin: 0;
  padding: 6px 9px 4px;
  border: 5px double var(--stamp);
  border-radius: 6px;
  background: var(--tag);
  color: var(--stamp);
  font-size: 22px;
  line-height: 1;
  translate: 0 -50%;
  transform: rotate(-4deg);
  animation: big-stamp .34s cubic-bezier(.2, .8, .25, 1.25) both;
}

.today { display: flex; align-items: center; gap: 10px; }
.today-label { flex: none; font-size: 15px; font-weight: 800; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 0 12px; font-size: 15px; }

.storage-warn {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-left: 6px solid var(--stamp);
  background: var(--tag);
  font-size: 15px;
  font-weight: 700;
}

/* Sections with a thick label rule under the title */
.sec { margin-top: 28px; }
.sec-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 3px solid var(--ink);
}
.sec-title { margin: 0; font-size: 24px; line-height: 1.1; }
.sec-count { flex: none; font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }

.tags { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }

/* Each item is a manila tag: clipped corners and a punched hole on the left.
   The paper is a pseudo-element so the focus outline is not clipped. */
.tag {
  --cut: 13px;
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 60px;
  padding: 10px 12px 12px 48px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .08s ease;
}
.tag::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--tag);
  box-shadow: inset 0 -3px 0 var(--tag-edge);
  clip-path: polygon(var(--cut) 0, 100% 0, 100% 100%, var(--cut) 100%, 0 calc(100% - var(--cut)), 0 var(--cut));
}
.tag::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 18px;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border-radius: 50%;
  background: var(--board);
  box-shadow: 0 0 0 3px var(--tag-edge);
}
.tag:active { transform: translateY(1px); }
.tag-name { flex: 1; min-width: 0; transition: color .15s ease; }

.when {
  flex: none;
  padding: 3px 6px 2px;
  border: 1.5px solid currentColor;
  border-radius: 3px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.1;
}

/* Empty dashed ring until checked, then the hook stamp lands on it. */
.mark { position: relative; flex: none; width: 42px; height: 42px; }
.mark::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 2px dashed var(--ink-soft);
  border-radius: 50%;
  transition: opacity .12s ease;
}
.stamp {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  color: var(--stamp);
  opacity: 0;
  transform: rotate(-14deg);
}
.tag[aria-checked="true"] .mark::before { opacity: 0; }
.tag[aria-checked="true"] .stamp { opacity: .92; }
.tag[aria-checked="true"] .tag-name { color: var(--ink-soft); }
.tag.just .stamp { animation: stamp-in .26s cubic-bezier(.2, .8, .25, 1.3) both; }
.tag.enter { animation: tag-in .28s ease-out both; }

/* Edit mode */
.fix {
  flex: none;
  font-size: 14px;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.tag.add {
  justify-content: center;
  min-height: 52px;
  padding: 10px 16px;
  border: 2px dashed var(--ink);
  border-radius: 4px;
  font-weight: 800;
}
.tag.add::before, .tag.add::after { display: none; }

.empty {
  margin: 36px 0 0;
  padding: 22px 16px;
  border: 2px dashed var(--ink);
  border-radius: 4px;
  text-align: center;
}
.empty p { margin: 0 0 14px; font-weight: 700; }
.empty p:last-child { margin-bottom: 0; }

.foot { display: grid; justify-items: center; gap: 14px; margin-top: 34px; }
.restart { width: 100%; min-height: 54px; font-size: 18px; }
.build { margin: 0; font-size: 13px; font-weight: 700; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: min(calc(100% - 32px), 528px);
  min-height: 52px;
  padding: 4px 4px 4px 16px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--on-ink);
  font-size: 16px;
  font-weight: 700;
  transform: translateX(-50%);
}
.toast.show { animation: toast-in .2s ease-out both; }
.toast button {
  flex: none;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--on-ink);
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.toast :focus-visible { outline-color: var(--on-ink); outline-offset: -4px; }

/* Editor bottom sheet */
#editor {
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - 24px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  overflow: visible;
}
#editor::backdrop { background: var(--shade); }
.sheet {
  display: grid;
  gap: 16px;
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px);
  border-top: 6px solid var(--ink);
  border-radius: 10px 10px 0 0;
  background: var(--tag);
}
.sheet:focus { outline: none; }
#editor[open] .sheet { animation: sheet-in .24s cubic-bezier(.2, .8, .2, 1) both; }
.sheet h2 { margin: 0; font-size: 26px; line-height: 1.1; }

.field { display: grid; gap: 8px; min-width: 0; margin: 0; padding: 0; border: 0; }
.field-label { padding: 0; font-size: 15px; font-weight: 800; }
legend.field-label { margin-bottom: 8px; }
.field input[type="text"] {
  width: 100%;
  min-height: 50px;
  padding: 0 12px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: 17px;
  font-weight: 700;
}
.field-error { margin: -8px 0 0; color: var(--stamp); font-size: 14px; font-weight: 800; }

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 2px solid var(--ink);
  border-radius: 4px;
  overflow: hidden;
}
.seg label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 4px 6px;
  font-size: 15px;
  font-weight: 800;
  text-align: center;
  cursor: pointer;
}
.seg label + label { border-left: 2px solid var(--ink); }
.seg input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.seg label:has(input:checked) { background: var(--ink); color: var(--on-ink); }
.seg label:has(input:focus-visible) { outline: 3px solid var(--ink); outline-offset: -6px; }
.seg label:has(input:checked:focus-visible) { outline-color: var(--on-ink); }

.sheet-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.sheet-actions .spacer { flex: 1; }
.danger { border-color: var(--stamp); color: var(--stamp); }
.primary { background: var(--ink); color: var(--on-ink); }

@keyframes stamp-in {
  from { opacity: 0; transform: scale(1.7) rotate(-30deg); }
  60% { opacity: .95; }
  to { opacity: .92; transform: scale(1) rotate(-14deg); }
}
@keyframes big-stamp {
  from { opacity: 0; transform: scale(1.8) rotate(-18deg); }
  to { opacity: 1; transform: scale(1) rotate(-4deg); }
}
@keyframes tag-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes sheet-in {
  from { transform: translateY(100%); }
  to { transform: none; }
}
