:root {
  --bg: #0d1220;
  --ink: #f4f1ea;
  --muted: rgba(244, 241, 234, 0.62);
  --glass: rgba(20, 26, 42, 0.72);
  --line: rgba(255, 255, 255, 0.1);
  --red: #ff3b24;
  --red-deep: #b5200f;
  --amber: #ffb547;
  --mint: #4fe3a1;
  --sky: #5ad1ff;
  --radius: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  color-scheme: dark;
}

[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
}

button,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#stage {
  position: fixed;
  inset: 0;
  touch-action: manipulation;
}

#stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  pointer-events: none;
  z-index: 5;
}

.top > * {
  pointer-events: auto;
}

.who {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  min-width: 0;
}

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--amber), var(--red));
  font-weight: 800;
  color: #1a0f08;
}

.who-text {
  display: grid;
  line-height: 1.1;
  min-width: 0;
}

.who-text small {
  font-size: 11px;
  color: var(--muted);
}

.who-text strong {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 34vw;
}

.actions {
  display: flex;
  gap: 6px;
  flex: none;
}

.icon-btn,
.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 13px;
  font-weight: 600;
  transition: transform 0.15s ease, background 0.2s ease;
}

.icon-btn {
  width: 40px;
  justify-content: center;
  padding: 0;
  font-size: 16px;
}

.pill-btn {
  padding: 0 14px;
  position: relative;
}

.icon-btn:active,
.pill-btn:active {
  transform: scale(0.94);
}

.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 2px var(--bg);
}

.badge.bump {
  animation: bump 0.6s cubic-bezier(0.3, 1.8, 0.5, 1);
}

@keyframes bump {
  0% { transform: scale(0.4); }
  60% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

@media (max-width: 440px) {
  #mine-open span:not(.badge),
  .who-text small {
    display: none;
  }

  .who-text strong {
    max-width: 30vw;
  }
}

.dock {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 520px);
  padding: 14px 14px calc(12px + var(--safe-bottom));
  z-index: 5;
}

.dock::before {
  content: "";
  position: absolute;
  inset: 0 0 0 0;
  border-radius: var(--radius) var(--radius) 0 0;
  background: linear-gradient(180deg, rgba(23, 30, 48, 0.86), rgba(13, 18, 32, 0.96));
  border: 1px solid var(--line);
  border-bottom: 0;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.35);
  z-index: -1;
}

@media (min-width: 560px) {
  .dock {
    bottom: 18px;
    padding-bottom: 14px;
  }

  .dock::before {
    border-radius: var(--radius);
    border-bottom: 1px solid var(--line);
  }
}

.dock-compose,
.dock-held {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.dock.shake {
  animation: shake 0.45s;
}

@keyframes shake {
  20%, 60% { transform: translateX(calc(-50% - 8px)); }
  40%, 80% { transform: translateX(calc(-50% + 8px)); }
}

.field {
  position: relative;
  flex: 1;
  min-width: 0;
}

textarea {
  width: 100%;
  height: 100%;
  min-height: 64px;
  max-height: 132px;
  resize: none;
  padding: 12px 14px 22px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  font-size: 16px;
  line-height: 1.35;
  outline: none;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

textarea::placeholder {
  color: rgba(244, 241, 234, 0.38);
}

textarea:focus {
  border-color: rgba(90, 209, 255, 0.6);
  background: rgba(255, 255, 255, 0.09);
  box-shadow: 0 0 0 4px rgba(90, 209, 255, 0.12);
}

.count {
  position: absolute;
  right: 12px;
  bottom: 6px;
  font-size: 11px;
  color: rgba(244, 241, 234, 0.4);
  pointer-events: none;
}

.take {
  flex: none;
  width: 104px;
  border: 0;
  padding: 0 0 6px;
  border-radius: 18px;
  background: var(--red-deep);
  box-shadow: 0 10px 30px rgba(255, 59, 36, 0.35);
  transition: transform 0.1s ease, padding 0.1s ease, box-shadow 0.2s ease, opacity 0.2s;
}

.take-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 100%;
  min-height: 58px;
  border-radius: 18px;
  background: linear-gradient(180deg, #ff6a4f, var(--red));
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.1s ease;
}

.take-icon {
  font-size: 20px;
}

.take:active:not(:disabled) .take-face,
.take.pressed .take-face {
  transform: translateY(5px);
}

.take:disabled {
  opacity: 0.6;
  cursor: progress;
}

.take-alt {
  width: auto;
  flex: 1;
  background: #0f8a5a;
  box-shadow: 0 10px 30px rgba(79, 227, 161, 0.25);
}

.take-alt .take-face {
  background: linear-gradient(180deg, #6ff0b6, #22b97a);
  color: #08281a;
  text-shadow: none;
  flex-direction: row;
  font-size: 16px;
}

.held-info {
  flex: none;
  display: grid;
  align-content: center;
  padding: 0 6px;
  line-height: 1.1;
}

.held-info small {
  font-size: 11px;
  color: var(--muted);
}

.held-info strong {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--mint);
  font-variant-numeric: tabular-nums;
}

.held-info span {
  font-size: 12px;
  color: var(--muted);
}

.status {
  margin: 10px 2px 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.status b {
  color: var(--amber);
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet[hidden] {
  display: none;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 15, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade 0.25s ease;
}

.sheet-card {
  position: relative;
  width: min(100%, 520px);
  max-height: 78dvh;
  overflow: auto;
  padding: 8px 16px calc(18px + var(--safe-bottom));
  border-radius: var(--radius) var(--radius) 0 0;
  background: #151b2b;
  border: 1px solid var(--line);
  border-bottom: 0;
  animation: rise 0.38s cubic-bezier(0.2, 1.2, 0.4, 1);
}

@media (min-width: 560px) {
  .sheet {
    align-items: center;
  }

  .sheet-card {
    border-radius: var(--radius);
    border-bottom: 1px solid var(--line);
  }
}

@keyframes rise {
  from { transform: translateY(40%); opacity: 0; }
}

@keyframes fade {
  from { opacity: 0; }
}

.sheet-grip {
  width: 40px;
  height: 4px;
  margin: 2px auto 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.18);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

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

.ticket-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  padding: 12px;
  border-radius: 16px;
  background: #f8f5ec;
  color: #23211d;
  position: relative;
  -webkit-mask: radial-gradient(circle 8px at 0 50%, transparent 98%, #000) left / 51% 100% no-repeat,
    radial-gradient(circle 8px at 100% 50%, transparent 98%, #000) right / 51% 100% no-repeat;
  mask: radial-gradient(circle 8px at 0 50%, transparent 98%, #000) left / 51% 100% no-repeat,
    radial-gradient(circle 8px at 100% 50%, transparent 98%, #000) right / 51% 100% no-repeat;
}

.ticket-row.done {
  opacity: 0.55;
}

.ticket-num {
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  padding-right: 12px;
  border-right: 2px dashed rgba(35, 33, 29, 0.25);
  display: grid;
  align-content: center;
}

.ticket-body {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.ticket-body p {
  margin: 0;
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.ticket-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  color: rgba(35, 33, 29, 0.6);
}

.chip {
  display: inline-block;
  white-space: nowrap;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
}

.chip.waiting {
  background: #ffe7b8;
  color: #7a4b00;
}

.chip.serving {
  background: #c9f7e1;
  color: #0b5a38;
  animation: glow 1.4s ease-in-out infinite;
}

.chip.done {
  background: #e4e1d8;
  color: #5c5850;
}

@keyframes glow {
  50% { box-shadow: 0 0 0 4px rgba(79, 227, 161, 0.35); }
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 18px 0 8px;
  margin: 0;
}

.counter-block {
  margin-bottom: 12px;
}

.counter-block small {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.counter-ticket {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  min-height: 52px;
}

.counter-ticket b {
  font-size: 22px;
  color: var(--amber);
  margin-right: 8px;
  font-variant-numeric: tabular-nums;
}

.counter-ticket p {
  margin: 6px 0 0;
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.counter-ticket .who-line {
  font-size: 12px;
  color: var(--muted);
}

#call-next {
  width: 100%;
  margin-top: 6px;
}

#call-next .take-face {
  flex-direction: row;
  font-size: 16px;
}

.toast-zone {
  position: fixed;
  top: calc(64px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(92%, 420px);
  display: grid;
  gap: 8px;
  z-index: 30;
  pointer-events: none;
}

.toast {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(20, 26, 42, 0.94);
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  font-size: 14px;
  animation: drop 0.4s cubic-bezier(0.2, 1.4, 0.4, 1);
  pointer-events: auto;
}

.toast.error {
  border-color: rgba(255, 90, 54, 0.5);
}

.toast.party {
  background: linear-gradient(135deg, #1d7a52, #0f4f8a);
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  padding: 16px;
}

.toast.leaving {
  transition: opacity 0.3s, transform 0.3s;
  opacity: 0;
  transform: translateY(-10px);
}

@keyframes drop {
  from { transform: translateY(-20px) scale(0.96); opacity: 0; }
}

.boot {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: radial-gradient(circle at 50% 40%, #1d2538, var(--bg));
  transition: opacity 0.6s ease, visibility 0.6s;
}

.boot.gone {
  opacity: 0;
  visibility: hidden;
}

.boot p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  max-width: 280px;
}

.boot-ticket {
  width: 110px;
  height: 64px;
  border-radius: 10px;
  background: #f8f5ec;
  color: #23211d;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 28px;
  font-variant-numeric: tabular-nums;
  animation: wobble 1.2s ease-in-out infinite;
}

.boot.error .boot-ticket {
  animation: none;
  background: #ffb4a8;
}

@keyframes wobble {
  0%, 100% { transform: rotate(-6deg) translateY(0); }
  50% { transform: rotate(6deg) translateY(-8px); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
