:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  --ink: #102033;
  --muted: #6d7c8c;
  --line: #dce3e8;
  --surface: #ffffff;
  --page: #f6f8fa;
  --accent: #149fc7;
  --accent-dark: #087fa4;
  --shadow: 0 5px 15px rgba(20, 39, 57, 0.10), 0 1px 3px rgba(20, 39, 57, 0.07);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, select { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(14px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.topbar {
  min-height: 66px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 10px 14px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 9px; white-space: nowrap; }

.brand-mark {
  width: 13px;
  height: 30px;
  display: inline-block;
  border-radius: 99px;
  background: linear-gradient(180deg, #20b5da 0 50%, #f2b84b 50% 100%);
}

.brand-title { font-size: 21px; font-weight: 780; letter-spacing: -.02em; }
.brand-subtitle { color: var(--muted); font-size: 14px; font-weight: 650; padding-left: 1px; }

.table-control { display: flex; align-items: center; gap: 9px; }
.table-control label { color: var(--muted); font-size: 14px; font-weight: 720; }

.select-wrap { position: relative; }
.select-wrap::after {
  content: "";
  position: absolute;
  right: 15px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid #435366;
  border-bottom: 2px solid #435366;
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

#table-select {
  width: 116px;
  height: 50px;
  appearance: none;
  border: 1px solid #cad4dc;
  border-radius: 13px;
  padding: 0 40px 0 16px;
  color: var(--ink);
  background: var(--surface);
  font-size: 17px;
  font-weight: 750;
  outline: none;
}

#table-select:focus-visible { box-shadow: 0 0 0 4px rgba(20,159,199,.18); border-color: var(--accent); }
.topbar-spacer { flex: 1; }

.order-total { display: flex; align-items: baseline; gap: 5px; color: var(--muted); font-size: 14px; font-weight: 650; }
.order-total strong { min-width: 26px; color: var(--ink); font-size: 24px; text-align: right; font-variant-numeric: tabular-nums; }

.clear-button {
  min-width: 104px;
  height: 50px;
  border: 0;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 4px 10px rgba(20, 159, 199, .22);
  font-size: 17px;
  font-weight: 760;
  cursor: pointer;
}

.clear-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.clear-button:active { transform: translateY(1px); background: var(--accent-dark); }
.clear-button:focus-visible, .number-wheel:focus-visible, .item-hit:focus-visible, .plate-button:focus-visible { outline: 4px solid rgba(20,159,199,.22); outline-offset: 2px; }

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(470px, 1.18fr) 1px minmax(400px, .82fr);
  gap: clamp(20px, 3vw, 46px);
  padding: 16px 10px 2px;
}

.items-panel, .plates-panel { min-height: 0; display: flex; flex-direction: column; }
.panel-heading { height: 47px; flex: 0 0 47px; display: flex; align-items: flex-start; justify-content: space-between; }
.eyebrow { margin: 0 0 2px; color: var(--accent-dark); font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.panel-heading h1, .panel-heading h2 { margin: 0; font-size: 17px; line-height: 1.2; font-weight: 760; }
.drag-hint { margin: 15px 0 0; color: var(--muted); font-size: 12px; font-weight: 600; }
.drag-hint span { display: inline-block; margin-right: 3px; color: var(--accent); font-size: 15px; }
.divider { width: 1px; background: var(--line); border-radius: 1px; }

.item-list, .plate-list { flex: 1; min-height: 0; display: grid; }
.item-list { grid-template-rows: repeat(8, minmax(58px, 1fr)); gap: 6px; }
.plate-list { grid-template-rows: repeat(5, minmax(88px, 1fr)); gap: 8px; }

.order-row { min-height: 0; display: grid; align-items: center; }
.item-row { grid-template-columns: 88px minmax(0, 1fr); gap: 14px; }
.plate-row { grid-template-columns: minmax(0, 1fr) auto; gap: 12px; justify-items: end; }

.item-hit, .plate-button {
  border: 0;
  color: inherit;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.item-hit {
  width: 52%;
  min-width: 220px;
  max-width: 320px;
  height: calc(100% - 6px);
  min-height: 52px;
  border-radius: 15px;
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 0 16px;
  text-align: left;
}

.item-hit:active { background: #e9f5f8; }
.item-index { width: 25px; color: #a0abb6; font-size: 12px; font-weight: 750; font-variant-numeric: tabular-nums; }
.item-name { font-size: clamp(21px, 2vw, 27px); font-weight: 790; letter-spacing: -.025em; }
.item-dot { width: 7px; height: 7px; margin-left: auto; border-radius: 50%; background: #d8e1e7; }

.counter { width: 74px; height: 60px; display: grid; place-items: center; }

.number-wheel {
  position: relative;
  width: 74px;
  height: 60px;
  border: 1px solid #ccd7df;
  border-radius: 15px;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--ink);
  background: linear-gradient(180deg, #f7fafb, #fff 40%, #fff 60%, #edf3f6);
  box-shadow: var(--shadow);
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: color .14s ease, background .14s ease, border-color .14s ease, box-shadow .14s ease;
}

.number-wheel::before, .number-wheel::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  height: 1px;
  background: #d8e1e6;
}
.number-wheel::before { top: 11px; }
.number-wheel::after { bottom: 11px; }
.wheel-value { font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, sans-serif; font-size: 31px; line-height: 1; font-weight: 790; font-variant-numeric: tabular-nums; }
.wheel-grip { position: absolute; right: 4px; width: 2px; height: 15px; border-radius: 2px; background: #b8c6d0; opacity: .75; }
.number-wheel.dragging { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(20,159,199,.15), var(--shadow); }
.number-wheel.has-value {
  color: #ffffff;
  border-color: #087f9f;
  background: linear-gradient(180deg, #18a9cd, #0784a8);
  box-shadow: 0 6px 16px rgba(8, 127, 164, .28), 0 1px 3px rgba(8, 70, 91, .18);
}
.number-wheel.has-value::before, .number-wheel.has-value::after { background: rgba(255,255,255,.34); }
.number-wheel.has-value .wheel-grip { background: rgba(255,255,255,.72); }
.number-wheel.bump .wheel-value { animation: bump .13s ease-out; }

.plate-row .counter { order: 1; }
.plate-button {
  --plate-size: clamp(82px, 12.2vh, 112px);
  --plate-color: #20a5cf;
  order: 2;
  position: relative;
  width: calc(var(--plate-size) + 18px);
  height: calc(var(--plate-size) + 18px);
  border-radius: 50%;
  padding: 0;
  display: grid;
  place-items: center;
}
.plate-button::before {
  content: "";
  position: absolute;
  width: var(--plate-size);
  height: var(--plate-size);
  border-radius: 50%;
  background: var(--plate-color);
  filter: drop-shadow(0 6px 5px rgba(25, 41, 54, .16));
}
.plate-button::after {
  content: "";
  position: absolute;
  width: calc(var(--plate-size) - 26px);
  height: calc(var(--plate-size) - 26px);
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.38);
  box-shadow: inset 0 0 0 7px rgba(255,255,255,.08);
}
.plate-button:active { transform: scale(.96); }
.plate-blue { --plate-color: #20a5cf; }
.plate-gold { --plate-color: #f4b649; }
.plate-red { --plate-color: #ed1230; }
.plate-purple { --plate-color: #a866df; }
.plate-black { --plate-color: #17202a; }

.toast {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translate(-50%, 24px);
  min-width: 280px;
  min-height: 54px;
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 8px 10px 8px 18px;
  color: #fff;
  background: #182533;
  box-shadow: 0 10px 30px rgba(15, 29, 43, .28);
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { min-width: 68px; min-height: 38px; border: 0; border-radius: 10px; color: #7bdef3; background: rgba(255,255,255,.1); font-weight: 750; }

@keyframes bump { 50% { transform: scale(1.12); color: var(--accent-dark); } }

@media (max-height: 720px) and (min-width: 900px) {
  .app-shell { padding-top: 8px; padding-bottom: 8px; }
  .topbar { min-height: 58px; padding-bottom: 8px; }
  #table-select, .clear-button { height: 46px; }
  .workspace { padding-top: 10px; }
  .panel-heading { height: 40px; flex-basis: 40px; }
  .drag-hint { margin-top: 10px; }
  .plate-button { --plate-size: clamp(78px, 11.5vh, 98px); }
}

@media (max-width: 899px), (orientation: portrait) {
  body { overflow: auto; }
  .app-shell { min-height: 100vh; padding: 12px; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 4px 2px 12px; }
  .brand { width: 100%; }
  .brand-subtitle { display: none; }
  .topbar-spacer { display: none; }
  .order-total { margin-left: auto; }
  .workspace { display: block; padding: 16px 2px; }
  .divider { display: none; }
  .items-panel, .plates-panel { min-height: auto; }
  .item-list { display: grid; grid-template: repeat(4, 76px) / repeat(2, 1fr); gap: 8px 12px; }
  .item-row { grid-template-columns: minmax(0, 1fr) 88px; }
  .item-hit { padding: 0 8px; }
  .item-index, .item-dot { display: none; }
  .item-name { font-size: 19px; }
  .plates-panel { margin-top: 26px; }
  .plate-list { display: grid; grid-template: repeat(5, 112px) / 1fr; gap: 8px; }
  .plate-row { grid-template-columns: 1fr auto; }
  .plate-button { --plate-size: 92px; }
}

@media (max-width: 620px) {
  .order-total { display: none; }
  .clear-button { min-width: 90px; }
  .item-list { grid-template: repeat(8, 72px) / 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
