:root {
  --ink: #101426;
  --ink-soft: #2A3050;
  --paper: #FFFFFF;
  --paper-line: #D8DAE4;
  --text-soft: #4B5170;
  --yellow: #FFC21A;
  --marker: #FFD84A;
  --font-display: 'Dela Gothic One', 'Arial Black', system-ui, sans-serif;
  --font-body: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

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

html, body { height: 100%; margin: 0; }
body {
  background: #0A0D1A;
  color: #fff;
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button, input { font: inherit; touch-action: manipulation; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }

.app {
  position: relative;
  width: 100%;
  max-width: 30rem;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  overflow: clip;
  background: var(--ink);
  container-type: inline-size;
}

/* camera layer */
.cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: var(--ink); }

.top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5; pointer-events: none;
  padding: calc(env(safe-area-inset-top) + 0.9rem) 1rem 0;
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.6rem;
}
.wordmark { font-family: var(--font-display); font-size: 1.3rem; letter-spacing: 0.01em; }
.status { margin: 0; background: var(--yellow); color: var(--ink); font-weight: 700; padding: 0.35rem 0.8rem; border-radius: 99px; font-size: 0.95rem; }

.finder {
  position: absolute; z-index: 1;
  left: 8%; right: 8%; top: 24%; height: 26%;
  box-shadow: 0 0 0 100vmax rgba(16, 20, 38, 0.6);
  color: var(--yellow);
  pointer-events: none;
}
.finder svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.finder path { fill: none; stroke: currentColor; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.finder__hint { position: absolute; left: 0; right: 0; top: calc(100% + 0.9rem); margin: 0; text-align: center; font-weight: 700; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.7); }

.cam-off {
  position: absolute; inset: 0; z-index: 3;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 1.2rem;
  padding: 0 1.5rem calc(env(safe-area-inset-bottom) + 7.5rem); text-align: center;
}
[data-camera="off"] .finder__hint { visibility: hidden; }
.cam-off__msg { margin: 0; max-width: 20rem; font-size: 1.15rem; }
[data-camera="on"] .cam-off { display: none; }

/* dock: all controls sit in the thumb zone */
.dock {
  position: absolute; z-index: 4;
  left: 0.75rem; right: 0.75rem;
  bottom: calc(env(safe-area-inset-bottom) + 0.75rem);
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0.5rem;
}
.dock__btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.3rem;
  min-height: 3.75rem; padding: 0.5rem; border: 0; border-radius: 1.1rem;
  background: rgba(16, 20, 38, 0.86); color: #fff; font-size: 0.875rem; font-weight: 700;
}
.dock__btn svg { width: 1.5rem; height: 1.5rem; }
.dock__btn[aria-pressed="true"] { background: var(--yellow); color: var(--ink); }
.dock__btn:active { background: var(--ink-soft); }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

svg { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 3.5rem; padding: 0.75rem 1.5rem; border: 0; border-radius: 1rem;
  font-weight: 700; font-size: 1.1rem;
}
.btn--yellow { background: var(--yellow); color: var(--ink); }

/* verdict flood */
.flood {
  --bg: var(--ink); --fg: #fff; --deep: var(--ink-soft);
  position: absolute; inset: 0; z-index: 6;
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--fg);
  visibility: hidden;
  clip-path: circle(0 at 50% 37%);
  transition: clip-path 0.55s cubic-bezier(0.2, 0.7, 0.2, 1), visibility 0s 0.55s;
}
.flood.is-open { visibility: visible; clip-path: circle(150% at 50% 37%); transition: clip-path 0.55s cubic-bezier(0.2, 0.7, 0.2, 1), visibility 0s; }
.flood[data-tone="contains"] { --bg: #E8322B; --fg: #fff; --deep: #A81812; }
.flood[data-tone="free"] { --bg: #0B7F45; --fg: #fff; --deep: #07592F; }
.flood[data-tone="caution"] { --bg: #FFC21A; --fg: #101426; --deep: #D49A00; }
.flood[data-tone="unknown"] { --bg: #3B3F8F; --fg: #fff; --deep: #272B6B; }

.flood__top { padding: calc(env(safe-area-inset-top) + 1.4rem) 1.25rem 0; flex: none; }
.word {
  margin: 0; font-family: var(--font-display); font-weight: 400;
  font-size: 5rem;
  font-size: min(calc(86cqw / (var(--letters, 3) * 0.95)), 40cqw);
  line-height: 0.92; letter-spacing: -0.01em;
}
.reason__title { margin: 1rem 0 0.2rem; font-size: 1.45rem; font-weight: 700; line-height: 1.2; }
.reason__text { margin: 0; font-size: 1.05rem; max-width: 26rem; }

.slip {
  position: relative; flex: 1; min-height: 0; overflow-y: auto;
  margin: 1.6rem 0.9rem 0; padding: 1.1rem 1.1rem 1.4rem;
  background: var(--paper); color: var(--ink);
  transform: rotate(-1.1deg); transform-origin: 20% 0;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18);
}
.slip::before {
  content: ""; position: absolute; left: 0; right: 0; top: -10px; height: 10px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='10'%3E%3Cpath d='M0 10 10 0l10 10Z' fill='%23fff'/%3E%3C/svg%3E") repeat-x;
}
.slip__head { display: flex; gap: 0.8rem; align-items: center; padding-bottom: 0.8rem; border-bottom: 2px dashed var(--paper-line); }
.slip__img { width: 3.6rem; height: 3.6rem; object-fit: contain; flex: none; border-radius: 0.4rem; background: #F2F3F7; }
.slip__name { margin: 0; font-weight: 700; font-size: 1.2rem; line-height: 1.2; }
.slip__meta { margin: 0.1rem 0 0; color: var(--text-soft); font-size: 0.95rem; }
.slip h3 { margin: 1rem 0 0.3rem; font-size: 1rem; }
.ingredients { margin: 0; font-size: 1.05rem; line-height: 1.6; overflow-wrap: anywhere; }
mark { background: var(--marker); color: var(--ink); font-weight: 700; padding: 0.05em 0.2em; border-radius: 0.2em; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.own { margin-top: 1rem; padding-top: 0.9rem; border-top: 2px dashed var(--paper-line); }
.slip__head + .own { border-top: 0; margin-top: 0.4rem; padding-top: 0; }
.own p { margin: 0 0 0.6rem; }
.own__row { display: flex; gap: 0.6rem; }
.own__row .btn { flex: 1; min-height: 3.25rem; background: var(--ink); color: #fff; }
.own .link { background: none; border: 0; padding: 0.5rem 0; color: var(--ink); text-decoration: underline; font-weight: 700; }
.photo-actions { margin-top: 1rem; padding-top: 0.9rem; border-top: 2px dashed var(--paper-line); }
.slip__head + .photo-actions { border-top: 0; margin-top: 0.4rem; padding-top: 0; }
.photo-actions p { margin: 0 0 0.6rem; }
.btn--photo { width: 100%; min-height: 3.25rem; background: var(--yellow); color: var(--ink); }
.photo-actions + .own { border-top: 0; padding-top: 0; }
.fine { margin: 1.1rem 0 0; font-size: 0.9rem; color: var(--text-soft); }
.fine a { color: inherit; }

.flood__actions { flex: none; padding: 0.9rem 0.9rem calc(env(safe-area-inset-bottom) + 0.9rem); }
.btn--flood { width: 100%; background: var(--fg); color: var(--bg); min-height: 3.75rem; font-size: 1.2rem; }
.flood[data-tone="caution"] .btn--flood { background: var(--ink); color: var(--yellow); }

/* panels */
.panel {
  position: absolute; z-index: 8; left: 0; right: 0; bottom: 0; max-height: 82%;
  display: flex; flex-direction: column;
  background: var(--ink); color: #fff;
  border-radius: 1.4rem 1.4rem 0 0; border-top: 3px solid var(--yellow);
  transform: translateY(105%); visibility: hidden;
  transition: transform 0.3s ease-out, visibility 0s 0.3s;
}
.panel.is-open { transform: none; visibility: visible; transition: transform 0.3s ease-out, visibility 0s; }
.panel__head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.1rem 0.4rem; }
.panel__head h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 1.35rem; }
.panel__close { width: 3rem; height: 3rem; border: 0; border-radius: 50%; background: var(--ink-soft); color: #fff; display: grid; place-items: center; }
.panel__close svg { width: 1.4rem; height: 1.4rem; }
.panel__body { overflow-y: auto; padding: 0.5rem 1.1rem calc(env(safe-area-inset-bottom) + 1.2rem); }

.manual label { display: block; margin-bottom: 0.5rem; }
.manual__row { display: flex; gap: 0.6rem; }
.manual input {
  flex: 1; min-width: 0; min-height: 3.5rem; padding: 0 1rem;
  font-size: 1.25rem; letter-spacing: 0.06em;
  border: 2px solid var(--ink-soft); border-radius: 1rem; background: #fff; color: var(--ink);
}
.manual__error { min-height: 1.4rem; margin: 0.5rem 0 0; color: #FFB4AF; font-weight: 700; }

.history { list-style: none; margin: 0; padding: 0; }
.history li + li { border-top: 1px solid var(--ink-soft); }
.history__item { width: 100%; display: flex; align-items: center; gap: 0.8rem; min-height: 3.75rem; padding: 0.5rem 0; border: 0; background: none; color: inherit; text-align: left; }
.tag { flex: none; min-width: 4.2rem; text-align: center; padding: 0.3rem 0.6rem; border-radius: 0.6rem; font-weight: 700; font-size: 0.95rem; }
.tag[data-tone="contains"] { background: #E8322B; color: #fff; }
.tag[data-tone="free"] { background: #0B7F45; color: #fff; }
.tag[data-tone="caution"] { background: #FFC21A; color: #101426; }
.tag[data-tone="unknown"] { background: #3B3F8F; color: #fff; }
.history__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { margin: 0.5rem 0; color: #C9CCE0; }
.linkbtn { margin-top: 1rem; background: none; border: 0; padding: 0.6rem 0; color: #C9CCE0; text-decoration: underline; }

@media (prefers-reduced-motion: reduce) {
  .flood, .flood.is-open, .panel, .panel.is-open { transition: none; }
}
