:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-soft: #f0f2f5;
  --text: #1a1d24;
  --muted: #4a5060;
  --line: #e0e3e8;
  --primary: #e31837;
  --primary-dark: #b8102a;
  --primary-deep: #8a0018;
  --primary-soft: #fce8eb;
  --blue: #4aafe8;
  --blue-dark: #2b8cc4;
  --accent: #e2a63c;
  --accent-soft: #fbf3e0;
  --accent-dark: #8a5a00;
  --danger: #c0392b;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow: 0 18px 44px rgba(26, 29, 36, 0.08);
  --shadow-soft: 0 8px 22px rgba(26, 29, 36, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Helvetica Neue", Arial, "Noto Sans TC", "PingFang TC",
    "Microsoft JhengHei", sans-serif;
}

button,
textarea,
input {
  font: inherit;
}

.app-shell {
  width: min(1680px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 20px 0 40px;
}

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

/* ---------- BNI 品牌列與 Hero ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 24px;
  background: var(--primary);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.topbar-brand .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.6;
}

.topbar-sub {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
}

.hero {
  position: relative;
  overflow: hidden;
  padding: 36px 24px 32px;
  background: linear-gradient(135deg, var(--primary) 0%, #c0102a 55%, var(--primary-deep) 100%);
  color: #fff;
  text-align: center;
}

.hero::before {
  content: "";
  position: absolute;
  top: -40px;
  right: -40px;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
}

.hero::after {
  content: "";
  position: absolute;
  bottom: -60px;
  left: -30px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
}

.hero h1 {
  position: relative;
  z-index: 1;
  margin-bottom: 0;
  font-size: clamp(1.8rem, 2.6vw, 2.3rem);
  font-weight: 800;
  letter-spacing: 0.02em;
}

.hero p {
  position: relative;
  z-index: 1;
  margin: 6px 0 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.92rem;
}

.hero-badges {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
}

.hero-badge {
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 20px;
  padding: 4px 14px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 0.76rem;
  letter-spacing: 0.05em;
}

.hero-badge.blue {
  border-color: var(--blue);
  background: var(--blue);
}

/* ---------- 統計列 ---------- */

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.summary-item {
  min-height: 74px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow-soft);
}

.summary-item span {
  display: block;
  color: var(--primary-dark);
  font-size: 1.85rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.summary-item small {
  color: var(--muted);
  font-weight: 700;
}

/* ---------- 訊息列 ---------- */

.notice {
  min-height: 48px;
  margin-bottom: 16px;
  padding: 13px 16px;
  border: 1px solid rgba(227, 24, 55, 0.22);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--primary-deep);
  font-weight: 700;
}

.notice.flash {
  animation: noticeFlash 0.5s ease;
}

.notice.warning {
  border-color: rgba(226, 166, 60, 0.5);
  border-left-color: var(--accent);
  background: #fdf7e8;
  color: var(--accent-dark);
}

.notice.error {
  border-color: rgba(179, 38, 30, 0.35);
  border-left-color: var(--danger);
  background: #fdf0ee;
  color: var(--danger);
}

/* ---------- 三欄面板 ---------- */

.tool-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.panel {
  display: flex;
  min-height: 620px;
  flex-direction: column;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  min-height: 64px;
  margin-bottom: 10px;
}

.panel-header > div:first-child {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 140px;
}

.icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
}

.icon svg {
  display: block;
  width: 23px;
  height: 23px;
}

.panel h2,
.drawbar h2,
.bonusbar h2 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 1.6vw, 1.6rem);
  font-weight: 900;
  line-height: 1.15;
}

.panel-actions,
.draw-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------- 按鈕 ---------- */

.button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 13px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    background 0.12s ease,
    color 0.12s ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.button.primary {
  min-width: 160px;
  padding: 11px 22px;
  background: linear-gradient(160deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  font-size: 1.02rem;
  box-shadow: 0 12px 26px rgba(227, 24, 55, 0.32);
}

.button.primary:hover {
  box-shadow: 0 14px 30px rgba(227, 24, 55, 0.4);
}

.button.primary:disabled {
  cursor: wait;
  opacity: 0.75;
  transform: none;
}

.button.secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.button.secondary:hover {
  border-color: rgba(227, 24, 55, 0.4);
  color: var(--primary-dark);
}

.button.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

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

/* 兩段式清空確認 */
.button[data-armed="true"] {
  border-color: var(--danger);
  background: var(--danger);
  color: white;
  animation: armPulse 0.9s ease infinite;
}

input[type="file"] {
  display: none;
}

/* ---------- 輸入區與結果 ---------- */

textarea,
.results-box {
  width: 100%;
  flex: 1;
  min-height: 440px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

textarea {
  resize: vertical;
  padding: 16px;
  color: var(--text);
  line-height: 1.62;
  outline: none;
}

textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(227, 24, 55, 0.14);
}

textarea::placeholder {
  color: #b0a9a0;
}

.result-filter {
  width: 100%;
  margin-bottom: 10px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  color: var(--text);
  outline: none;
}

.result-filter:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(227, 24, 55, 0.14);
}

.result-filter::placeholder {
  color: #b0a9a0;
}

.results-box {
  overflow: auto;
  padding: 0;
}

.empty {
  display: grid;
  height: 100%;
  min-height: 400px;
  place-items: center;
  color: #b0a9a0;
  font-size: 1.15rem;
  font-weight: 800;
}

.result-row {
  display: grid;
  grid-template-columns: minmax(100px, 0.9fr) 24px minmax(140px, 1.2fr);
  gap: 10px;
  align-items: center;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  line-height: 1.35;
}

.result-row:nth-child(even) {
  background: var(--surface-soft);
}

.result-row.reveal {
  animation: rowIn 0.4s ease both;
  animation-delay: var(--delay, 0s);
}

.result-row.filtered-out {
  display: none;
}

.result-name,
.result-prize {
  overflow-wrap: anywhere;
}

.result-name {
  font-weight: 800;
}

.result-badge {
  display: inline-flex;
  margin-left: 6px;
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.74rem;
  font-weight: 900;
  vertical-align: 1px;
}

.result-arrow {
  color: var(--primary);
  font-weight: 900;
  text-align: center;
}

.result-prize {
  color: var(--primary-dark);
  font-weight: 700;
}

.result-prize.no-prize {
  color: var(--muted);
  font-weight: 600;
}

.hint {
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.hint.warning {
  color: var(--accent-dark);
  font-weight: 800;
}

/* ---------- 抽獎列與加碼列 ---------- */

.drawbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 18px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
}

.drawbar p,
.bonusbar p {
  margin-bottom: 0;
  color: var(--muted);
}

.bonusbar {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(260px, 1.3fr) auto;
  gap: 14px;
  align-items: stretch;
  margin-top: 18px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
}

.bonus-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}

.bonusbar textarea {
  min-height: 108px;
  flex: initial;
  resize: vertical;
}

.bonus-actions {
  display: flex;
  min-width: 150px;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}

.toggle {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* ---------- 投影模式 ---------- */

.stage {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: clamp(20px, 3.5vw, 48px);
  background:
    radial-gradient(circle at 20% -10%, rgba(227, 24, 55, 0.28), transparent 34rem),
    radial-gradient(circle at 85% 110%, rgba(226, 166, 60, 0.18), transparent 30rem),
    #191419;
  color: #f7f2ea;
  overflow-y: auto;
}

.stage[hidden] {
  display: none;
}

.stage-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: clamp(18px, 3vh, 34px);
}

.stage-eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.stage-header h2 {
  margin-bottom: 6px;
  font-size: clamp(1.9rem, 4vw, 3.2rem);
  font-weight: 900;
  line-height: 1.05;
}

.stage-summary {
  margin: 0;
  color: rgba(247, 242, 234, 0.72);
  font-size: clamp(1rem, 1.6vw, 1.2rem);
  font-weight: 700;
}

.stage-close {
  flex-shrink: 0;
  border-color: rgba(247, 242, 234, 0.35);
  background: rgba(247, 242, 234, 0.08);
  color: #f7f2ea;
}

.stage-close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
  align-content: start;
}

.stage-card {
  padding: 16px 18px;
  border: 1px solid rgba(247, 242, 234, 0.14);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
  animation: rowIn 0.45s ease both;
  animation-delay: var(--delay, 0s);
}

.stage-card.is-bonus {
  border-color: rgba(226, 166, 60, 0.55);
  background: rgba(226, 166, 60, 0.08);
}

.stage-card .stage-number {
  color: rgba(247, 242, 234, 0.5);
  font-size: 0.85rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.stage-card .stage-name {
  margin: 2px 0 6px;
  font-size: clamp(1.25rem, 2vw, 1.55rem);
  font-weight: 900;
  overflow-wrap: anywhere;
}

.stage-card .stage-prize {
  color: var(--accent);
  font-size: clamp(1rem, 1.5vw, 1.2rem);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.stage-card .stage-prize.no-prize {
  color: rgba(247, 242, 234, 0.45);
}

.stage-card .stage-badge {
  display: inline-block;
  margin-left: 8px;
  border-radius: 999px;
  padding: 2px 9px;
  background: var(--accent);
  color: #3d2a00;
  font-size: 0.72rem;
  font-weight: 900;
  vertical-align: 3px;
}

/* ---------- 彩帶 ---------- */

.confetti {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti span {
  position: absolute;
  top: -24px;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  opacity: 0.95;
  animation: confettiFall var(--fall-duration, 3s) linear var(--fall-delay, 0s) forwards;
}

/* ---------- 動畫 ---------- */

@keyframes rowIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes noticeFlash {
  0% {
    box-shadow: 0 0 0 0 rgba(227, 24, 55, 0.35);
  }
  100% {
    box-shadow: 0 0 0 12px rgba(227, 24, 55, 0);
  }
}

@keyframes armPulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(179, 38, 30, 0.4);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(179, 38, 30, 0);
  }
}

@keyframes drawingPulse {
  0%,
  100% {
    box-shadow: 0 12px 26px rgba(227, 24, 55, 0.32);
  }
  50% {
    box-shadow: 0 12px 34px rgba(227, 24, 55, 0.55);
  }
}

.button.is-drawing {
  animation: drawingPulse 0.7s ease infinite;
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg);
  }
  100% {
    transform: translateY(110vh) rotate(var(--spin, 540deg));
    opacity: 0.6;
  }
}

/* ---------- 響應式 ---------- */

@media (max-width: 1180px) {
  .tool-grid {
    grid-template-columns: 1fr;
  }

  .panel {
    min-height: 520px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 24px, 1680px);
    padding: 18px 0 28px;
  }

  .topbar {
    padding: 0 14px;
  }

  .hero {
    padding: 28px 16px 26px;
  }

  .drawbar,
  .bonusbar {
    align-items: stretch;
    flex-direction: column;
  }

  .bonusbar {
    display: flex;
  }

  .panel {
    min-height: 0;
    padding: 16px;
  }

  .panel-header {
    min-height: 0;
    flex-direction: column;
  }

  .panel-actions,
  .draw-actions {
    justify-content: flex-start;
  }

  .button.primary {
    width: 100%;
  }

  textarea,
  .results-box,
  .empty {
    min-height: 340px;
  }

  .bonusbar textarea {
    min-height: 130px;
  }

  .result-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .result-arrow {
    display: none;
  }

  .stage-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- 動畫偏好 ---------- */

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