:root {
  color-scheme: light;
  --ink: #201a14;
  --muted: #75685d;
  --paper: #fbf3df;
  --paper-line: rgba(76, 54, 31, 0.28);
  --panel: rgba(255, 250, 241, 0.94);
  --line: rgba(32, 26, 20, 0.14);
  --accent: #d67a09;
  --gold: #d7a30a;
  --red: #c63d2f;
  --shadow: 0 18px 40px rgba(32, 26, 20, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Microsoft JhengHei", "Noto Sans TC", Arial, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(rgba(245, 235, 214, 0.86), rgba(228, 211, 181, 0.9)),
    url("/assets/01.png") center / cover fixed;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
}

.app-shell {
  width: min(1460px, calc(100% - 24px));
  min-height: calc(100vh - 20px);
  margin: 10px auto;
  display: grid;
  grid-template-columns: 250px minmax(620px, 1fr) 270px;
  gap: 12px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.player-panel,
.leaderboard-panel {
  padding: 14px;
}

.player-panel {
  position: relative;
  overflow: hidden;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.panel-heading h1,
.panel-heading h2,
.recent-wins h3 {
  margin: 0;
}

.panel-heading h1 {
  font-size: 28px;
  line-height: 1.1;
}

.panel-heading h2 {
  font-size: 22px;
}

.title-pill {
  padding: 7px 10px;
  border-radius: 999px;
  background: #2d231a;
  color: #fff8ea;
  font-weight: 700;
  white-space: nowrap;
}

#player-name-heading {
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.money-board {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.money-board div {
  padding: 12px;
  border-radius: 8px;
  background: #2d231a;
  color: #fff8ea;
}

.money-board span,
.ticket-result span,
.ticket-tab span {
  display: block;
  font-size: 13px;
  color: rgba(255, 248, 234, 0.72);
}

.money-board strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
}

.field-label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 14px;
}

.inline-field {
  display: flex;
  gap: 8px;
}

.inline-field input,
.uuid-row code {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--paper-line);
  border-radius: 6px;
  background: rgba(255, 252, 245, 0.96);
}

.inline-field input {
  padding: 10px 12px;
}

.inline-field button,
.uuid-row button,
#buy-ticket-btn,
.result-actions button {
  border-radius: 6px;
  background: var(--accent);
  color: #fff8ea;
  font-weight: 700;
}

.inline-field button,
.uuid-row button {
  flex: 0 0 auto;
  padding: 0 12px;
}

.uuid-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.uuid-row code {
  overflow: hidden;
  padding: 10px 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-panel {
  min-width: 0;
}

.ticket-stage {
  min-height: calc(100vh - 20px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 14px;
}

.ticket-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  margin-bottom: 12px;
}

.ticket-header span {
  color: var(--muted);
}

.ticket-header h2 {
  margin: 4px 0 0;
  font-size: 30px;
}

.ticket-actions {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.purchase-stack {
  display: grid;
  gap: 8px;
}

.ticket-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(132px, 1fr));
  gap: 8px;
}

.ticket-tab {
  min-height: 58px;
  padding: 9px 12px;
  border: 1px solid var(--paper-line);
  border-radius: 6px;
  background: #fff8ea;
  color: var(--ink);
  text-align: left;
}

.ticket-tab span {
  color: var(--muted);
}

.ticket-tab strong {
  display: block;
  margin-top: 4px;
}

.ticket-tab.active {
  border-color: #2d231a;
  background: #2d231a;
  color: #fff8ea;
}

.ticket-tab.active span {
  color: rgba(255, 248, 234, 0.72);
}

.ticket-tab:disabled,
#buy-ticket-btn:disabled,
.batch-buy-btn:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

#buy-ticket-btn {
  min-width: 112px;
  min-height: 58px;
  padding: 0 16px;
}

.batch-buy-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.batch-buy-btn {
  min-height: 32px;
  border: 1px solid var(--paper-line);
  border-radius: 6px;
  background: #fff8ea;
  color: var(--ink);
  font-weight: 700;
}

.batch-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0;
  margin-bottom: 12px;
  border: 1px solid var(--paper-line);
  border-radius: 6px;
  background: rgba(255, 248, 234, 0.92);
}

.batch-summary[hidden] {
  display: none;
}

.batch-summary-item {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
}

.batch-summary-item + .batch-summary-item {
  border-left: 1px solid var(--paper-line);
}

.batch-summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.batch-summary strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.ticket-card {
  position: relative;
  min-height: 620px;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  padding: 14px;
  overflow: hidden;
  border: 10px solid #f3d28e;
  border-radius: 10px;
  background: #d1d5db;
}

.ticket-art {
  position: absolute;
  inset: 0;
  background-position: center;
  background-size: cover;
}

.ticket-250 .ticket-art {
  background-image: linear-gradient(rgba(38, 28, 20, 0.18), rgba(38, 28, 20, 0.42)), url("/assets/01.png");
}

.ticket-500 .ticket-art {
  background-image: linear-gradient(rgba(38, 28, 20, 0.18), rgba(38, 28, 20, 0.42)), url("/assets/02.png");
}

.ticket-banner {
  position: relative;
  z-index: 1;
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
  display: grid;
  gap: 2px;
  padding: 9px 12px;
  border-radius: 6px;
  background: rgba(45, 35, 26, 0.88);
  color: #fff8ea;
}

.ticket-banner span {
  font-size: 12px;
  color: rgba(255, 248, 234, 0.72);
}

.ticket-banner strong {
  font-size: 18px;
}

.ticket-hype {
  position: relative;
  z-index: 1;
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 8px;
}

.hype-chip {
  min-width: 88px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 248, 234, 0.28);
  border-radius: 6px;
  background: rgba(45, 35, 26, 0.84);
  color: #fff8ea;
}

.hype-chip span {
  display: block;
  color: rgba(255, 248, 234, 0.72);
  font-size: 11px;
}

.hype-chip strong {
  display: block;
  margin-top: 2px;
  font-size: 16px;
}

.scratch-zone {
  position: relative;
  z-index: 1;
  grid-column: 1 / -1;
  grid-row: 2;
  min-height: 0;
  display: flex;
  align-items: end;
  overflow: visible;
}

.player-meow {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: calc(100% - 20px);
  max-height: 250px;
  object-fit: contain;
  opacity: 0.96;
  pointer-events: none;
}

.ticket-content {
  width: 100%;
  display: grid;
  gap: 10px;
  align-content: end;
}

.empty-state {
  min-height: 180px;
  display: grid;
  place-items: center;
  padding: 18px;
  border: 3px dashed rgba(255, 248, 234, 0.72);
  border-radius: 10px;
  color: #fff8ea;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
}

.paper-zone {
  position: relative;
  overflow: hidden;
  border: 2px solid #6f512f;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.38), transparent 38%),
    var(--paper);
  box-shadow: inset 0 0 0 2px rgba(255, 248, 234, 0.7);
}

.paper-zone::before {
  position: absolute;
  inset: 7px;
  border: 1px dashed rgba(111, 81, 47, 0.72);
  content: "";
  pointer-events: none;
}

.zone-inner {
  position: relative;
  z-index: 1;
  padding: 10px;
}

.zone-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}

.zone-heading h3 {
  margin: 0;
  font-size: 15px;
}

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

.ticket-grid {
  display: grid;
  gap: 8px;
}

.ticket-grid.jobs {
  grid-template-columns: repeat(3, 1fr);
}

.ticket-grid.jobs-eight {
  grid-template-columns: repeat(4, 1fr);
}

.job-card,
.row-card,
.bonus-card,
.winning-number,
.symbol-chip {
  background: #fffaf0;
  color: var(--ink);
}

.job-card,
.row-card {
  border: 1px solid rgba(111, 81, 47, 0.35);
  border-radius: 5px;
}

.job-card {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 58px;
  padding: 8px;
}

.job-card strong,
.row-card strong {
  display: block;
  font-size: 17px;
}

.job-card span,
.row-card span {
  color: var(--muted);
  font-size: 12px;
}

.symbol-chip {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(111, 81, 47, 0.35);
  border-radius: 4px;
}

.symbol-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hero-symbol {
  width: 44px;
  height: 44px;
}

.lucky-task {
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 10px;
}

.lucky-task-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.winning-number-list {
  display: flex;
  gap: 8px;
}

.winning-number {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(111, 81, 47, 0.35);
  border-radius: 4px;
  font-weight: 700;
}

.row-card {
  display: grid;
  grid-template-columns: 38px 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
}

.ticket-grid.rows-eight {
  grid-template-columns: repeat(2, 1fr);
}

.overtime-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.overtime-symbol {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 6px;
  border: 1px solid rgba(111, 81, 47, 0.35);
  border-radius: 5px;
  background: #fffaf0;
  font-size: 12px;
}

.bonus-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 42px;
  border: 1px solid rgba(111, 81, 47, 0.35);
  border-radius: 5px;
  font-weight: 700;
}

.job-card.win,
.row-card.win,
.bonus-card.win,
.lucky-task.win {
  color: #7b1f12;
}

.job-card.win strong,
.row-card.win strong,
.bonus-card.win {
  color: var(--red);
}

.celebrate {
  animation: win-pop 720ms ease both, win-glow 1200ms ease-in-out infinite alternate;
}

@keyframes win-pop {
  0% { transform: scale(0.96); }
  55% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

@keyframes win-glow {
  from { box-shadow: 0 0 0 rgba(215, 163, 10, 0); }
  to { box-shadow: 0 0 0 3px rgba(215, 163, 10, 0.28), 0 0 20px rgba(215, 163, 10, 0.45); }
}

@keyframes foil-flash {
  0% { filter: brightness(1); }
  50% { filter: brightness(1.8); }
  100% { filter: brightness(1); }
}

.scratch-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.scratch-layer.complete {
  pointer-events: none;
}

.scratch-layer.zone-finished {
  animation: foil-flash 420ms ease;
}

.ticket-result {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.ticket-result img {
  width: 64px;
  height: 64px;
  border-radius: 8px;
}

.result-copy {
  min-width: 150px;
}

.ticket-result span {
  color: var(--muted);
}

.ticket-result strong {
  display: block;
  margin-top: 4px;
  font-size: 21px;
}

.result-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.result-actions button {
  min-width: 108px;
  min-height: 40px;
  padding: 0 14px;
}

.result-actions button:disabled {
  cursor: not-allowed;
  background: #b7a58c;
}

.leaderboard-list,
.recent-wins ul {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.leaderboard-list strong {
  display: block;
}

.leaderboard-list span,
.recent-wins li {
  color: var(--muted);
  font-size: 14px;
}

.leaderboard-tools {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.dashboard-link {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 6px;
  background: #2d231a;
  color: #fff8ea;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.recent-wins {
  margin-top: 14px;
}

.recent-wins li {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(360px, calc(100% - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #2d231a;
  color: #fff8ea;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.mobile-action-dock {
  display: none;
}

@media (max-width: 1160px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .leaderboard-panel {
    order: 3;
  }

  .ticket-card {
    min-height: 640px;
  }
}

@media (max-width: 760px) {
  body.mobile-dock-active {
    padding-bottom: calc(98px + env(safe-area-inset-bottom));
  }

  .app-shell {
    width: min(100% - 20px, 760px);
    margin: 10px auto;
  }

  .player-panel,
  .leaderboard-panel,
  .ticket-stage {
    padding: 14px;
  }

  .ticket-header {
    align-items: stretch;
    flex-direction: column;
  }

  .ticket-actions,
  .ticket-result {
    flex-direction: column;
    align-items: stretch;
  }

  .purchase-stack {
    grid-template-columns: 1fr;
  }

  .ticket-tabs {
    grid-template-columns: 1fr;
  }

  #buy-ticket-btn,
  .result-actions button {
    width: 100%;
  }

  .batch-summary {
    flex-wrap: wrap;
  }

  .batch-summary-item {
    min-width: 33.333%;
  }

  .batch-summary-item + .batch-summary-item {
    border-left: 1px solid var(--paper-line);
  }

  .result-actions {
    margin-left: 0;
  }

  .ticket-grid.jobs {
    grid-template-columns: repeat(2, 1fr);
  }

  .ticket-grid.jobs-eight,
  .ticket-grid.rows-eight,
  .overtime-grid,
  .lucky-task-list {
    grid-template-columns: repeat(2, 1fr);
  }

  .row-card {
    grid-template-columns: 38px 1fr;
  }

  .zone-heading {
    display: grid;
  }

  .ticket-hype {
    grid-column: 1;
    grid-row: 2;
    justify-self: stretch;
    grid-template-columns: 1fr;
  }

  .ticket-card {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr);
    min-height: 760px;
  }

  .scratch-zone {
    grid-row: 3;
  }

  .player-meow {
    position: static;
    display: block;
    width: min(240px, 100%);
    max-height: 220px;
    margin: 16px auto 0;
  }

  .mobile-action-dock.visible {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 20;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
    align-items: center;
    padding: 10px;
    border: 1px solid rgba(32, 26, 20, 0.18);
    border-radius: 10px;
    background: rgba(45, 35, 26, 0.96);
    color: #fff8ea;
    box-shadow: 0 18px 36px rgba(32, 26, 20, 0.28);
    backdrop-filter: blur(12px);
  }

  .mobile-action-copy {
    min-width: 0;
  }

  .mobile-action-copy span {
    display: block;
    color: rgba(255, 248, 234, 0.72);
    font-size: 12px;
  }

  .mobile-action-copy strong {
    display: block;
    overflow: hidden;
    margin-top: 2px;
    font-size: 16px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-action-copy em {
    display: block;
    margin-top: 2px;
    overflow: hidden;
    color: rgba(255, 248, 234, 0.72);
    font-size: 12px;
    font-style: normal;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-action-dock button {
    min-height: 42px;
    padding: 0 12px;
    border-radius: 6px;
    background: var(--accent);
    color: #fff8ea;
    font-weight: 700;
  }

  .mobile-action-dock button:disabled {
    cursor: not-allowed;
    background: #8c7861;
  }

  body.mobile-dock-active .toast {
    bottom: calc(108px + env(safe-area-inset-bottom));
  }
}
