/* Layout: one column — top bar, title, how and what to choose, then either the big touch field (Vingers) or the names list with its result (Namen) */
:root {
  --bg: #17110e;
  --surface: #241a15;
  --surface-2: #2f231c;
  --line: #4a3a30;
  --accent: #ff6b2c;
  --accent-text: #ff8a55;
  --accent-deep: #b8461c;
  --on-accent: #17110e;
  --focus: #ffbd4a;
  --text: #f7ede1;
  --muted: #b5a191;
  --bust: #c0392b;
  --on-bust: #ffffff;
  --danger-text: #ff9a8f;
  --glow: rgba(255, 107, 44, .16);
  --scrim: rgba(8, 5, 4, .6);
  --shadow: rgba(0, 0, 0, .5);
  --toast-bg: #f3e7cf;
  --toast-ink: #2b1d14;
  --switch-off: #4a3a30;
  --switch-knob: #f7ede1;
  --finger-ink: #17110e;
  --finger-1: #ff8a4c;
  --finger-2: #61b6ff;
  --finger-3: #93dc7d;
  --finger-4: #ffd54f;
  --finger-5: #c99cff;
  --finger-6: #ff8aac;
  --finger-7: #4fd1c5;
  --finger-8: #ff7a6b;
  --finger-9: #c6e36b;
  --finger-10: #e0b88a;
  --display: 'Bagel Fat One', 'Arial Black', system-ui, sans-serif;
  --body: 'Rethink Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { overflow-x: hidden; }
body {
  margin: 0; min-height: 100vh; overflow-x: hidden; overscroll-behavior: none;
  background: radial-gradient(130% 55% at 50% 105%, var(--glow), transparent 62%), var(--bg);
  color: var(--text); font-family: var(--body); font-size: 16px; line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
button:focus-visible, textarea:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
#app {
  max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 12px;
}
body:not(.finger-mode) #app { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }

/* ---------- buttons and controls ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer; width: 100%; min-height: 52px; padding: 0 18px; border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 800; font-size: 17px;
}
.btn:active { transform: translateY(2px); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn.primary { background: var(--accent); color: var(--on-accent); box-shadow: 0 3px 0 var(--accent-deep); }
.btn.ghost { background: var(--surface); color: var(--text); border: 1.5px solid var(--line); }
.btn.bust { background: var(--bust); color: var(--on-bust); }
.btn.text { background: transparent; color: var(--accent-text); min-height: 44px; }
.btn.big { min-height: 58px; font-family: var(--display); font-weight: 400; font-size: 22px; }
.btn.small { width: auto; min-height: 44px; padding: 0 10px; font-size: 15px; border-radius: 12px; }
.icon-btn { appearance: none; flex: none; width: 46px; height: 46px; border-radius: 14px; cursor: pointer; border: 1.5px solid var(--line); background: var(--surface); color: var(--text); display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; }
.segmented { display: inline-flex; flex: none; gap: 2px; padding: 3px; border-radius: 13px; background: var(--bg); }
.segmented button { appearance: none; border: 0; cursor: pointer; min-height: 44px; padding: 0 12px; border-radius: 10px; background: none; color: var(--muted); font-weight: 700; font-size: 15px; }
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--on-accent); }
.segmented.wide { display: flex; width: 100%; }
.segmented.wide button { flex: 1 1 0; min-width: 0; padding: 0 6px; }
.mode-switch { background: var(--surface); }
.switch { appearance: none; position: relative; flex: none; width: 60px; height: 44px; padding: 0; border: 0; background: none; cursor: pointer; }
.switch::before { content: ''; position: absolute; left: 4px; right: 4px; top: 7px; bottom: 7px; border-radius: 999px; background: var(--switch-off); transition: background-color .2s ease; }
.switch[aria-checked="true"]::before { background: var(--accent); }
.switch-knob { position: absolute; left: 7px; top: 10px; width: 24px; height: 24px; border-radius: 50%; background: var(--switch-knob); box-shadow: 0 2px 4px var(--shadow); transition: translate .2s ease; }
.switch[aria-checked="true"] .switch-knob { translate: 22px 0; }

/* ---------- top ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; }
.top-actions { display: flex; gap: 8px; flex: none; }
.icon-btn[hidden] { display: none; }
.back-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; color: var(--muted); font-weight: 700; text-decoration: none; }
.title { font-family: var(--display); font-weight: 400; font-size: clamp(38px, 11vw, 52px); line-height: 1; }
.controls { display: grid; gap: 10px; min-width: 0; }
.box { background: var(--surface); border-radius: 18px; padding: 14px; display: grid; gap: 12px; min-width: 0; }
.options { padding: 10px; gap: 10px; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.box-title { font-weight: 800; font-size: 17px; padding-left: 4px; }
.hint { color: var(--muted); font-size: 14.5px; }

/* ---------- fingers ---------- */
.stage { flex: 1 1 auto; display: flex; min-height: 300px; }
.touch {
  position: relative; flex: 1; overflow: hidden; border-radius: 26px;
  background: var(--surface); border: 2px dashed var(--line);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.touch[data-phase="counting"], .touch[data-phase="done"] { border-style: solid; border-color: var(--accent); }
.touch-msg {
  position: absolute; z-index: 3; top: 16px; left: 16px; right: 16px; pointer-events: none;
  text-align: center; font-weight: 800; font-size: 18px; color: var(--text); text-wrap: balance;
}
.touch[data-phase="done"] .touch-msg { font-family: var(--display); font-weight: 400; font-size: 26px; line-height: 1.15; }
.touch-hint { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
.touch-hint svg { width: 88px; height: 88px; animation: hint 2.4s ease-in-out infinite; }
.touch:not([data-phase="idle"]) .touch-hint { display: none; }
.touch-count {
  position: absolute; inset: 0; z-index: 1; display: grid; place-items: center; pointer-events: none;
  font-family: var(--display); font-size: 140px; line-height: 1; color: var(--text);
}
.touch-count.tick { animation: count .5s ease-out both; }
.finger { --size: 104px; position: absolute; z-index: 2; left: 0; top: 0; width: 0; height: 0; pointer-events: none; will-change: transform; }
.finger-dot {
  position: absolute; left: calc(var(--size) / -2); top: calc(var(--size) / -2); width: var(--size); height: var(--size);
  border-radius: 50%; display: grid; place-items: center; background: var(--fc); color: var(--finger-ink);
  box-shadow: 0 0 0 7px color-mix(in srgb, var(--fc) 35%, transparent), 0 10px 30px var(--shadow);
  transition: scale .4s cubic-bezier(.2, .9, .3, 1.3), opacity .4s ease, background-color .3s ease;
  animation: land .25s cubic-bezier(.2, .9, .3, 1.4) both;
}
.touch[data-phase="counting"] .finger-dot { animation: pulse .5s ease-in-out infinite; }
.finger.win { z-index: 4; }
.finger.win .finger-dot { scale: 1.45; box-shadow: 0 0 0 10px color-mix(in srgb, var(--fc) 40%, transparent), 0 0 60px var(--fc); }
.finger.lose .finger-dot { scale: .7; opacity: .22; }
.finger-label { font-family: var(--display); font-size: 44px; line-height: 1; }
.finger-tag {
  position: absolute; left: 0; bottom: calc(var(--size) * .75 + 20px); translate: -50% 0; white-space: nowrap;
  padding: 8px 16px; border-radius: 999px; background: var(--toast-bg); color: var(--toast-ink);
  font-weight: 800; font-size: 19px; box-shadow: 0 8px 24px var(--shadow); animation: tag .3s ease-out both;
}
.finger.tag-below .finger-tag { bottom: auto; top: calc(var(--size) * .75 + 20px); }
.finger.tag-left .finger-tag { translate: -30px 0; }
.finger.tag-right .finger-tag { translate: calc(-100% + 30px) 0; }
.finger.leaving { opacity: 0; transition: opacity .9s ease; }

/* ---------- names ---------- */
.names { display: grid; gap: 12px; min-width: 0; }
.names textarea {
  width: 100%; min-width: 0; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-size: 17px; line-height: 1.4; resize: vertical;
}
.names textarea::placeholder { color: var(--muted); }
.result { display: grid; gap: 12px; min-width: 0; scroll-margin-bottom: 96px; }
.result:empty { display: none; }
.result-head { font-family: var(--display); font-weight: 400; font-size: 30px; line-height: 1.1; overflow-wrap: anywhere; }
.result-head:focus { outline: none; }
.name-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.name-chip {
  min-height: 44px; max-width: 100%; padding: 10px 16px; border-radius: 999px; background: var(--surface-2); color: var(--text);
  font-weight: 700; overflow-wrap: anywhere; transition: background-color .08s, color .08s, scale .08s;
}
.name-chip.hot { background: var(--accent); color: var(--on-accent); scale: 1.06; }
.name-chip.win { background: var(--accent); color: var(--on-accent); scale: 1.1; box-shadow: 0 0 0 4px var(--focus); animation: win .5s cubic-bezier(.2, .9, .3, 1.4); }
.order { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.order li { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 6px 14px 6px 6px; border-radius: 16px; background: var(--surface); }
.order-num { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--text); font-family: var(--display); font-size: 20px; }
.order li:first-child .order-num { background: var(--accent); color: var(--on-accent); }
.order-name { min-width: 0; font-weight: 700; overflow-wrap: anywhere; }
.dealt > * { animation: deal .36s cubic-bezier(.2, .9, .3, 1) both; animation-delay: calc(var(--i) * 45ms); }
@media (min-width: 640px) {
  #app { max-width: 760px; }
}

/* ---------- sheets, modal, toast ---------- */
.backdrop { position: fixed; inset: 0; z-index: 20; background: var(--scrim); animation: fade .2s ease; }
.sheet {
  position: fixed; z-index: 21; bottom: 0; left: 50%; translate: -50% 0; width: min(100%, 560px); max-height: 86%; overflow-y: auto;
  border-radius: 22px 22px 0 0; background: var(--surface); display: grid; gap: 14px;
  padding-top: 10px; padding-left: max(18px, env(safe-area-inset-left, 0px)); padding-right: max(18px, env(safe-area-inset-right, 0px));
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -10px 40px var(--shadow); animation: rise .25s cubic-bezier(.2, .9, .3, 1);
}
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); justify-self: center; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h3 { font-family: var(--display); font-weight: 400; font-size: 24px; }
.close-btn { appearance: none; border: 0; width: 44px; height: 44px; border-radius: 12px; background: var(--surface-2); color: var(--text); cursor: pointer; display: grid; place-items: center; }
.close-btn svg { width: 18px; height: 18px; }
.menu-list { display: grid; gap: 6px; }
.menu-item {
  appearance: none; border: 0; cursor: pointer; width: 100%; min-height: 54px; padding: 0 14px; border-radius: 14px;
  background: var(--surface-2); color: var(--text); text-align: left; font-weight: 700; font-size: 16.5px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.menu-item.static { cursor: default; padding-block: 8px; }
.menu-item.home { color: var(--accent-text); }
.menu-item.danger { color: var(--danger-text); }
.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: var(--scrim); animation: fade .2s ease; }
.modal {
  position: fixed; z-index: 41; left: 50%; top: 50%; translate: -50% -50%; width: min(calc(100% - 48px), 360px);
  padding: 20px; border-radius: 20px; background: var(--surface); box-shadow: 0 20px 60px var(--shadow);
  display: grid; gap: 10px; animation: pop .2s ease;
}
.modal h3 { font-family: var(--display); font-weight: 400; font-size: 24px; line-height: 1.1; }
.modal p { color: var(--muted); }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.modal-actions .btn { min-height: 48px; font-size: 16px; padding: 0 10px; }
.toast {
  position: fixed; z-index: 30; left: 50%; translate: -50% 0; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: min(calc(100% - 32px), 528px); display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 16px; background: var(--toast-bg); color: var(--toast-ink);
  box-shadow: 0 12px 30px var(--shadow); font-weight: 600; font-size: 15px; min-height: 52px;
}
.toast span { flex: 1; min-width: 0; }

@keyframes land { from { scale: .4; opacity: 0; } }
@keyframes pulse { 50% { scale: 1.12; } }
@keyframes count { from { scale: 1.5; opacity: 0; } to { scale: 1; opacity: 1; } }
@keyframes tag { from { opacity: 0; scale: .8; } }
@keyframes hint { 50% { translate: 0 -8px; } }
@keyframes win { from { scale: 1; } 50% { scale: 1.25; } }
@keyframes deal { from { opacity: 0; translate: 0 10px; scale: .97; } }
@keyframes rise { from { translate: -50% 30px; opacity: 0; } to { translate: -50% 0; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; scale: .95; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
