:root {
  color-scheme: light;
  --page: #eef2f7;
  --card: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #dbe2ea;
  --accent: #ef4444;
  --accent-dark: #c62828;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --danger: #b42318;
  --shadow: 0 16px 40px rgba(23, 32, 51, 0.10);
  --radius-lg: 24px;
  --radius-md: 16px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--page);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family:
    "Microsoft JhengHei UI",
    "PingFang TC",
    "Noto Sans TC",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.10), transparent 32rem),
    radial-gradient(circle at top right, rgba(239, 68, 68, 0.10), transparent 30rem),
    var(--page);
}

button,
input {
  font: inherit;
}

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

button:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.30);
  outline-offset: 3px;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding:
    max(18px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.18em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: clamp(2rem, 6vw, 3.1rem);
  line-height: 1.1;
}

h2 {
  margin-bottom: 4px;
  font-size: 1.25rem;
}

.subtitle,
.section-heading p,
footer,
.list-toolbar,
.tips {
  color: var(--muted);
}

.subtitle {
  margin-bottom: 0;
}

.main-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(310px, 0.85fr);
  gap: 18px;
  align-items: start;
}

.card {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(219, 226, 234, 0.92);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.wheel-card,
.management-card {
  padding: clamp(16px, 3vw, 26px);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.section-heading p {
  margin-bottom: 0;
  font-size: 0.92rem;
}

.badge {
  flex: 0 0 auto;
  padding: 7px 11px;
  border-radius: 999px;
  background: #fff1f2;
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 800;
}

.wheel-wrap {
  position: relative;
  width: min(100%, 620px);
  aspect-ratio: 1;
  margin: 8px auto 2px;
  display: grid;
  place-items: center;
}

#wheelCanvas {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 14px 18px rgba(23, 32, 51, 0.15));
}

.pointer {
  position: absolute;
  z-index: 4;
  top: 0.5%;
  left: 50%;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
  border-top: 44px solid var(--accent);
  filter: drop-shadow(0 4px 4px rgba(120, 20, 20, 0.28));
}

.wheel-hub {
  position: absolute;
  z-index: 3;
  width: 23%;
  aspect-ratio: 1;
  border: 5px solid #344054;
  border-radius: 50%;
  display: grid;
  place-content: center;
  text-align: center;
  background: white;
  box-shadow: 0 8px 20px rgba(23, 32, 51, 0.16);
  pointer-events: none;
}

.wheel-hub span {
  font-size: clamp(0.65rem, 2vw, 1rem);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.wheel-hub strong {
  color: var(--accent);
  font-size: clamp(0.9rem, 3.4vw, 1.5rem);
}

.result-panel {
  margin: 2px auto 14px;
  text-align: center;
}

.result-label {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.result-text {
  margin-bottom: 0;
  min-height: 2.2rem;
  color: var(--accent-dark);
  font-size: clamp(1.35rem, 4vw, 2rem);
  font-weight: 900;
}

.primary-button,
.secondary-button,
.ghost-button,
.text-button {
  border: 0;
  cursor: pointer;
  transition:
    transform 120ms ease,
    background 120ms ease,
    opacity 120ms ease;
}

.primary-button:active,
.secondary-button:active,
.ghost-button:active {
  transform: scale(0.98);
}

.primary-button {
  display: block;
  min-width: 180px;
  margin: 0 auto;
  padding: 14px 24px;
  border-radius: 14px;
  color: white;
  background: linear-gradient(135deg, var(--accent), #f97316);
  font-size: 1.1rem;
  font-weight: 900;
  box-shadow: 0 10px 20px rgba(239, 68, 68, 0.24);
}

.primary-button:hover {
  background: linear-gradient(135deg, #dc2626, #ea580c);
}

.secondary-button {
  padding: 11px 15px;
  border-radius: 12px;
  color: white;
  background: var(--blue);
  font-weight: 800;
}

.secondary-button:hover {
  background: var(--blue-dark);
}

.ghost-button {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: white;
  font-weight: 800;
}

.ghost-button:hover {
  background: #f8fafc;
}

.text-button {
  padding: 4px;
  color: var(--blue);
  background: transparent;
  font-weight: 800;
}

.text-button.danger {
  color: var(--danger);
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.add-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin: 16px 0 10px;
}

.add-form input {
  min-width: 0;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: #fbfcfe;
}

.list-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.88rem;
}

.restaurant-list {
  max-height: 390px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfcfe;
}

.restaurant-item {
  display: grid;
  grid-template-columns: auto 34px 1fr;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  padding: 8px 12px;
  border-bottom: 1px solid #e8edf3;
}

.restaurant-item:last-child {
  border-bottom: 0;
}

.restaurant-item input {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
}

.restaurant-number {
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.restaurant-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 750;
}

.management-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.tips {
  margin-top: 16px;
  font-size: 0.9rem;
}

.tips summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 800;
}

.tips ol {
  margin-bottom: 0;
  padding-left: 1.4rem;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 4px 0;
  font-size: 0.82rem;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translate(-50%, 24px);
  min-width: min(300px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 12px;
  color: white;
  background: rgba(23, 32, 51, 0.94);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: 180ms ease;
  box-shadow: 0 12px 30px rgba(23, 32, 51, 0.24);
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.dialog-backdrop {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(5px);
}

.dialog-card {
  width: min(420px, 100%);
  padding: 28px;
  border-radius: 24px;
  background: white;
  text-align: center;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.30);
}

.dialog-card .primary-button {
  width: 100%;
}

.dialog-emoji {
  margin-bottom: 6px;
  font-size: 3rem;
}

.dialog-result {
  margin: 18px 0 24px;
  color: var(--accent-dark);
  font-size: 1.8rem;
  font-weight: 900;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 860px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .management-card {
    order: 2;
  }

  .restaurant-list {
    max-height: 340px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar .ghost-button {
    font-size: 0.82rem;
  }

  .wheel-card,
  .management-card {
    padding: 14px;
    border-radius: 20px;
  }

  .wheel-wrap {
    width: 100%;
  }

  .pointer {
    border-left-width: 15px;
    border-right-width: 15px;
    border-top-width: 34px;
  }

  .management-actions {
    grid-template-columns: 1fr;
  }

  footer {
    flex-direction: column;
    align-items: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
