/* Viinakello: one screen, iOS-native feel. Ring on top, 2 x 2 tiles in the thumb zone. */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --sheet: #f2f2f7;
  --sheet-card: #ffffff;
  --text: #111114;
  --muted: #6e6e73;
  --sep: rgba(60, 60, 67, 0.16);
  --track: rgba(120, 120, 128, 0.16);
  --green: #34c759;
  --amber: #ff9f0a;
  --red: #ff3b30;
  --accent: #0a84ff;
  --beer: linear-gradient(155deg, #ffb340 0%, #f08c00 100%);
  --beer-large: linear-gradient(155deg, #f09a1a 0%, #c46a00 100%);
  --wine: linear-gradient(155deg, #c0365e 0%, #7d1636 100%);
  --spirit: linear-gradient(155deg, #6f8296 0%, #3f4e5e 100%);
  --radius: 26px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  --rounded: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --sheet: #1c1c1e;
    --sheet-card: #2c2c2e;
    --text: #f5f5f7;
    --muted: #98989f;
    --sep: rgba(84, 84, 88, 0.6);
    --track: rgba(120, 120, 128, 0.3);
    --green: #30d158;
    --amber: #ff9f0a;
    --red: #ff453a;
    --accent: #0a84ff;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
html { -webkit-text-size-adjust: 100%; }
body {
  font: 16px/1.35 var(--font);
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.app {
  max-width: 520px; margin: 0 auto;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) max(16px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 96px) max(16px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 10px;
}

/* header */
.top { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.top h1 { font: 700 22px/1 var(--rounded); letter-spacing: -0.01em; margin: 0; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--muted); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }
.icon-btn:active { background: var(--track); }

/* ring */
.gauge { position: relative; width: min(52vw, 196px, 24dvh); aspect-ratio: 1; margin: 0 auto; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 16; }
.ring-track { stroke: var(--track); }
.ring-fill { stroke: var(--green); stroke-linecap: round; transition: stroke-dashoffset 0.6s cubic-bezier(.2,.8,.2,1), stroke 0.3s; }
.gauge[data-level="amber"] .ring-fill { stroke: var(--amber); }
.gauge[data-level="red"] .ring-fill { stroke: var(--red); }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.total { font: 700 clamp(40px, 13vw, 54px)/1 var(--rounded); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.of { font-size: 13px; color: var(--muted); margin-top: 4px; }
.next { margin: -2px 0 0; text-align: center; font-size: 14px; color: var(--muted); min-height: 19px; }
.next b { color: var(--text); font-weight: 600; }

/* 7-day strip */
.week {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
  background: var(--card); border-radius: 18px; padding: 10px 8px 8px;
}
.day { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; border-radius: 10px; padding: 2px 0; }
.day:active { background: var(--track); }
.day .val { font: 600 12px/1 var(--rounded); font-variant-numeric: tabular-nums; color: var(--muted); height: 12px; }
.day .bar-wrap { height: 48px; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.day .bar { width: 16px; border-radius: 8px; background: var(--accent); min-height: 4px; transition: height 0.4s cubic-bezier(.2,.8,.2,1); }
.day.heavy .bar { background: var(--amber); }
.day.dry .bar { width: 6px; height: 6px; min-height: 6px; background: transparent; border: 1.5px solid var(--muted); border-radius: 50%; opacity: 0.6; }
.day .name { font-size: 12px; color: var(--muted); }
.day.today .name { color: var(--text); font-weight: 700; }

/* tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; flex: 1 0 auto; }
.tile {
  position: relative; overflow: hidden;
  min-height: clamp(132px, 19dvh, 190px);
  border-radius: var(--radius); color: #fff; text-align: left;
  padding: 16px 16px 14px;
  display: flex; flex-direction: column; justify-content: space-between;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14);
  transition: transform 0.25s cubic-bezier(.3,1.6,.5,1);
  touch-action: manipulation;
}
.tile[data-kind="beer"] { background: var(--beer); }
.tile[data-kind="beer-large"] { background: var(--beer-large); }
.tile[data-kind="wine"] { background: var(--wine); }
.tile[data-kind="spirit"] { background: var(--spirit); }
.tile.pressed { transform: scale(0.95); transition-duration: 0.08s; }
.tile.pop { animation: pop 0.45s cubic-bezier(.3,1.6,.5,1); }
@keyframes pop { 0% { transform: scale(0.94); } 60% { transform: scale(1.03); } 100% { transform: scale(1); } }
.tile svg.glass { width: 38px; height: 38px; fill: none; stroke: rgba(255,255,255,0.95); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tile .label { display: flex; align-items: flex-end; justify-content: space-between; gap: 6px; }
.tile .name { font: 700 22px/1.05 var(--rounded); }
.tile .size { font: 600 15px/1.2 var(--rounded); opacity: 0.9; }
.tile .units { font: 600 12px/1 var(--font); opacity: 0.8; margin-top: 3px; }
.tile .count {
  position: absolute; top: 14px; right: 14px; min-width: 30px; height: 30px; padding: 0 9px;
  border-radius: 15px; background: rgba(255,255,255,0.25); display: grid; place-items: center;
  font: 700 15px/1 var(--rounded); font-variant-numeric: tabular-nums;
}
.tile .count[hidden] { display: none; }
.tile .flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.tile.pop .flash { animation: flash 0.45s ease-out; }
@keyframes flash { 0% { opacity: 0.35; } 100% { opacity: 0; } }
.hint { margin: -2px 0 4px; text-align: center; font-size: 12px; color: var(--muted); }

/* today list */
.today { background: var(--card); border-radius: 18px; padding: 12px 0 4px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 16px 6px; }
.section-head h2 { margin: 0; font: 700 17px/1.2 var(--rounded); }
.section-head span { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.list { list-style: none; margin: 0; padding: 0; }
.empty { margin: 4px 16px 10px; color: var(--muted); font-size: 15px; }
.row { position: relative; overflow: hidden; }
.row + .row .row-main { border-top: 0.5px solid var(--sep); }
.row-del {
  position: absolute; inset: 0 0 0 auto; width: 100%; background: var(--red); color: #fff;
  display: flex; align-items: center; justify-content: flex-end; padding-right: 22px; font-weight: 600;
}
.row-main {
  position: relative; background: var(--card); display: flex; align-items: center; gap: 12px;
  padding: 11px 16px; min-height: 52px; touch-action: pan-y; width: 100%; text-align: left;
}
.row-main.anim { transition: transform 0.25s ease; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.dot[data-kind="beer"] { background: var(--beer); }
.dot[data-kind="beer-large"] { background: var(--beer-large); }
.dot[data-kind="wine"] { background: var(--wine); }
.dot[data-kind="spirit"] { background: var(--spirit); }
.row-text { flex: 1; min-width: 0; }
.row-text b { font-weight: 600; }
.row-text small { display: block; color: var(--muted); font-size: 13px; }
.row-amt { color: var(--muted); font-variant-numeric: tabular-nums; }
.row-chev { color: var(--muted); opacity: 0.5; font-size: 18px; }
.storage-note { text-align: center; color: var(--red); font-size: 13px; }

/* toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  width: min(92vw, 420px);
  background: rgba(30, 30, 32, 0.94); color: #fff; border-radius: 16px;
  padding: 10px 10px 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3); z-index: 30;
  pointer-events: none; /* only the Undo button takes taps, the list under it stays usable */
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  animation: toast-in 0.3s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes toast-in { from { transform: translate(-50%, 24px); opacity: 0; } }
.toast span { font-size: 15px; }
.toast button { pointer-events: auto; color: #ffd60a; font-weight: 700; padding: 8px 12px; border-radius: 10px; }
.toast button:active { background: rgba(255,255,255,0.12); }
.toast button[hidden] { display: none; }

/* bottom sheet */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 40; animation: fade 0.25s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-width: 560px; margin: 0 auto; max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--sheet); border-radius: 22px 22px 0 0;
  padding: 8px max(16px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 20px) max(16px, env(safe-area-inset-left, 0px));
  animation: sheet-in 0.35s cubic-bezier(.2,.9,.3,1);
  -webkit-user-select: none; user-select: none;
}
@keyframes sheet-in { from { transform: translateY(100%); } }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--track); margin: 0 auto 6px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.sheet-head h2 { margin: 0; font: 700 20px/1.2 var(--rounded); }
.text-btn { color: var(--accent); font-weight: 600; padding: 10px 4px; }
.sheet-body { display: grid; gap: 14px; padding-top: 6px; }
.group { background: var(--sheet-card); border-radius: 14px; overflow: hidden; }
.group-title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 4px 4px -8px; }
.cell { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; min-height: 50px; width: 100%; text-align: left; }
.cell + .cell { border-top: 0.5px solid var(--sep); }
button.cell:active { background: var(--track); }
.cell .sub { color: var(--muted); font-size: 14px; }
.cell.danger { color: var(--red); justify-content: center; font-weight: 600; }
.cell.primary { color: var(--accent); justify-content: center; font-weight: 600; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick button { background: var(--sheet-card); border-radius: 14px; min-height: 54px; font-weight: 600; }
.quick button:active { background: var(--track); }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 40px; height: 34px; border-radius: 9px; background: var(--track); font: 600 20px/1 var(--font); }
.stepper output { min-width: 46px; text-align: center; font: 600 17px/1 var(--rounded); font-variant-numeric: tabular-nums; }
input[type="datetime-local"] {
  font: 17px var(--font); color: var(--text); background: transparent; border: 0;
  -webkit-appearance: none; appearance: none; text-align: right; min-height: 44px; max-width: 62%;
  -webkit-user-select: text; user-select: text;
}
.note { color: var(--muted); font-size: 13px; margin: 0 4px; line-height: 1.45; }
.day-total { font: 700 34px/1 var(--rounded); font-variant-numeric: tabular-nums; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

@media (max-height: 700px) {
  .app { gap: 8px; }
  .week { padding: 8px 6px 6px; }
  .day .bar-wrap { height: 38px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.sheet .row-main { background: var(--sheet-card); }
