:root {
  --bg: #0a120d;
  --card: rgba(15, 26, 20, 0.96);
  --card-solid: #0f1a14;
  --border: rgba(212, 168, 83, 0.12);
  --border-light: rgba(212, 168, 83, 0.06);
  --text: #e8e4dc;
  --text-muted: #6a6558;
  --text-dim: #4a4540;
  --gold: #d4a853;
  --gold-light: #e8c36a;
  --gold-dark: #b8893a;
  --gold-glow: rgba(212,168,83,0.15);
  --green: #78dd9a;
  --green-dim: rgba(120,221,154,0.15);
  --red: #ff8a84;
  --red-dim: rgba(255,138,132,0.15);
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --input-h: 48px;
  --btn-h: 48px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  font-family: "Noto Sans SC", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(212,168,83,0.05) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(120,221,154,0.03) 0%, transparent 50%);
  z-index: 0;
}

.status-banner {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-size: 0.88rem;
}

.status-banner.info {
  background: rgba(212,168,83,0.08);
  border-color: rgba(212,168,83,0.18);
}

.status-banner.success {
  background: var(--green-dim);
  border-color: rgba(120,221,154,0.28);
}

.status-banner.error {
  background: var(--red-dim);
  border-color: rgba(255,138,132,0.28);
}

/* ===== LAYOUT ===== */
.app-shell {
  position: relative;
  z-index: 1;
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: 20px 16px calc(88px + env(safe-area-inset-bottom));
}

/* ===== HEADER ===== */
.top-header {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0;
}

.brand-left {
  position: relative;
}

.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #1e3022, #0f1a14);
  border: 1px solid var(--border);
  color: var(--gold);
  font-family: "DM Sans", sans-serif;
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3), inset 0 1px 0 rgba(212,168,83,0.15);
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.brand-mark::after {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: conic-gradient(from 0deg, transparent, rgba(212,168,83,0.08), transparent 30%);
  animation: shimmer 8s linear infinite;
}

@keyframes shimmer {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.brand-copy {
  padding-left: 14px;
  border-left: 1px solid var(--border-light);
  margin-left: 2px;
}

.brand-copy .eyebrow {
  font-family: "DM Sans", sans-serif;
  font-weight: 800;
  font-size: clamp(1.1rem, 4vw, 1.4rem);
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.1;
  margin-bottom: 3px;
}

.brand-copy .brand-sub {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ===== NAV ===== */
.desktop-tabs { display: none; }

.mobile-tabs {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  padding: 8px;
  border-radius: var(--radius-xl);
  background: var(--card);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow), 0 0 0 1px rgba(0,0,0,0.4);
  z-index: 30;
}

.nav-tab {
  border: none;
  cursor: pointer;
  padding: 10px 4px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  background: transparent;
  font-weight: 600;
  font-size: 0.75rem;
  font-family: inherit;
  transition: background 0.18s, color 0.18s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
.nav-tab.active {
  color: var(--gold);
  background: rgba(212,168,83,0.1);
}
.tab-icon { font-size: 1.15rem; line-height: 1; }

/* ===== TABS PANELS ===== */
.tab-panels { position: relative; }
.tab-panel { display: none; animation: fadeUp 0.2s ease; }
.tab-panel.active { display: block; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== PANEL ===== */
.panel {
  border-radius: var(--radius-xl);
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-glow { position: relative; }
.panel-glow::before {
  content: "";
  position: absolute;
  top: 0; right: 0;
  width: 140px; height: 140px;
  background: radial-gradient(circle, rgba(212,168,83,0.07) 0%, transparent 70%);
  pointer-events: none;
}

.stage-panel { padding: 20px; }

.stage-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 20px;
}

.section-tag {
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0.7;
  margin-bottom: 4px;
}

.stage-head h2 {
  font-family: "DM Sans", sans-serif;
  font-weight: 800;
  font-size: clamp(1.15rem, 4vw, 1.5rem);
  letter-spacing: -0.02em;
  color: var(--text);
}

.section-empty,
.loading-copy {
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border);
  background: rgba(255,255,255,0.02);
  color: var(--text-muted);
  font-size: 0.86rem;
}

.error-copy {
  color: var(--red);
}

/* ===== INPUTS ===== */
.field { display: flex; flex-direction: column; gap: 6px; }
.field,
.meta-grid,
.buyin-grid {
  min-width: 0;
}

.field-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.field-input {
  height: var(--input-h);
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: rgba(212,168,83,0.04);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.field-input:focus {
  outline: none;
  border-color: var(--gold);
  background: rgba(212,168,83,0.07);
  box-shadow: 0 0 0 3px rgba(212,168,83,0.08);
}
.field-input::placeholder { color: rgba(232,228,220,0.2); }
.date-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  width: 100%;
}

.stepper-input {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  gap: 8px;
  align-items: center;
}

.stepper-btn {
  height: var(--input-h);
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: rgba(212,168,83,0.06);
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.stepper-btn:hover {
  border-color: rgba(212,168,83,0.35);
  background: rgba(212,168,83,0.12);
}

.stepper-btn:active {
  transform: scale(0.97);
}

select.field-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236a6558' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
  cursor: pointer;
}

/* ===== FORM LAYOUT ===== */
.entry-form { display: flex; flex-direction: column; gap: 18px; }

.meta-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.meta-grid .field,
.meta-grid .field-input {
  min-width: 0;
}

.buyin-grid {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 12px;
  max-width: 360px;
}

/* ===== PLAYER CHIP PICKER ===== */
.player-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.picker-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.picker-hint {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.player-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.player-chip {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.18s;
}
.player-chip:hover {
  border-color: rgba(212,168,83,0.3);
  color: var(--text);
}
.player-chip.selected {
  border-color: var(--gold);
  background: rgba(212,168,83,0.1);
  color: var(--gold);
}

/* ===== PLAYER NAME BADGE ===== */
.player-name-badge {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
}

/* ===== SUMMARY BAR ===== */
.summary-bar {
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border-light);
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.summary-totals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  flex: 1;
}

.summary-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.summary-item .field-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.summary-item strong {
  font-family: "DM Sans", sans-serif;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
}

.summary-item strong.zero { color: var(--text-muted); }

.summary-check {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.summary-check.ok {
  background: var(--green-dim);
  color: var(--green);
}

.summary-check.error {
  background: var(--red-dim);
  color: var(--red);
}

.check-icon {
  font-size: 1.1rem;
  font-weight: 800;
}

.check-text {
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}

/* Settlement form */
.settlement-list { display: flex; flex-direction: column; gap: 10px; }

.player-entry {
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border-light);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.player-entry-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.player-entry-head select { flex: 1; min-width: 0; }

.row-net {
  font-family: "DM Sans", sans-serif;
  font-size: 1.15rem;
  font-weight: 800;
  min-width: 68px;
  text-align: right;
  flex-shrink: 0;
}

.player-entry-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ===== BUTTONS ===== */
.action-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 4px;
}

.action-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn {
  height: var(--btn-h);
  padding: 0 20px;
  border-radius: var(--radius-md);
  border: none;
  font-weight: 700;
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s, border-color 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(135deg, var(--gold-light) 0%, var(--gold) 50%, var(--gold-dark) 100%);
  color: #1a1206;
  box-shadow: 0 4px 16px rgba(212,168,83,0.25), inset 0 1px 0 rgba(255,255,255,0.2);
}
.btn-primary:hover {
  box-shadow: 0 6px 20px rgba(212,168,83,0.35), inset 0 1px 0 rgba(255,255,255,0.2);
}

.btn-secondary {
  background: transparent;
  color: var(--gold);
  border: 1.5px solid rgba(212,168,83,0.28);
}
.btn-secondary:hover {
  border-color: var(--gold);
  background: rgba(212,168,83,0.07);
}

.btn-ghost {
  background: rgba(255,255,255,0.04);
  color: var(--text-muted);
  border: 1px solid var(--border-light);
}
.btn-ghost:hover {
  background: rgba(255,255,255,0.07);
  color: var(--text);
}

.btn-full { width: 100%; }
.btn-sm { height: 40px; padding: 0 14px; font-size: 0.82rem; }
.btn-xs { height: 34px; padding: 0 12px; font-size: 0.78rem; }
.btn-danger {
  background: rgba(255, 138, 132, 0.12);
  color: var(--red);
  border: 1px solid rgba(255, 138, 132, 0.24);
}

/* ===== CHIP CALCULATOR ===== */
.calculator-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(212,168,83,0.08) 0%, rgba(212,168,83,0.03) 100%);
  border: 1px solid rgba(212,168,83,0.1);
  margin-bottom: 16px;
}

.summary-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.summary-value {
  font-family: "DM Sans", sans-serif;
  font-size: 2rem;
  font-weight: 800;
  color: var(--gold);
  letter-spacing: -0.02em;
}

.chip-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.chip-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 10px;
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border-light);
}

.chip-face {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  font-family: "DM Sans", sans-serif;
  font-weight: 800;
  font-size: 0.95rem;
  color: #fff;
}

.chip-label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.chip-input {
  height: 40px;
  width: 100%;
  max-width: 112px;
  text-align: center;
  padding: 0 8px;
  font-size: 0.9rem;
  background: rgba(0,0,0,0.2);
}

/* Chip colors */
.chip-5   { --chip-bg: linear-gradient(135deg, #d77461, #c85d47); }
.chip-10  { --chip-bg: linear-gradient(135deg, #eda244, #d98b34); }
.chip-20  { --chip-bg: linear-gradient(135deg, #6d94dc, #4e7ecb); }
.chip-50  { --chip-bg: linear-gradient(135deg, #86a04d, #647a43); }
.chip-100 { --chip-bg: linear-gradient(135deg, #8888a0, #5a5a6a); }
.chip-500 { --chip-bg: linear-gradient(135deg, #9f70c8, #7656a8); }

.chip-face { background: var(--chip-bg); }

/* ===== EXPANDABLE CARDS ===== */
.expand-list { display: flex; flex-direction: column; gap: 8px; }

.swipe-row {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
}

.swipe-row-track {
  display: flex;
  width: calc(100% + var(--swipe-action-width, 88px));
  min-width: calc(100% + var(--swipe-action-width, 88px));
  transition: transform 0.2s ease;
  will-change: transform;
}

.swipe-row-action {
  width: var(--swipe-action-width, 88px);
  flex: 0 0 var(--swipe-action-width, 88px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 138, 132, 0.1);
  border-radius: var(--radius-lg);
  padding: 10px 8px;
}

.swipe-row-content {
  position: relative;
  width: 100%;
  flex: 0 0 100%;
  min-width: 0;
  background: var(--bg);
  touch-action: pan-y;
}

.expand-card {
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border-light);
  overflow: hidden;
  transition: border-color 0.2s;
}
.expand-card.is-open {
  border-color: rgba(212,168,83,0.2);
}

.expand-trigger {
  width: 100%;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 14px;
  text-align: left;
  display: block;
}

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

.expand-info { flex: 1; min-width: 0; }
.expand-info h3 {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.expand-info .meta { font-size: 0.72rem; color: var(--text-muted); }

.expand-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.winner-tag {
  font-size: 0.65rem;
  color: var(--text-muted);
  background: rgba(255,255,255,0.04);
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

.expand-arrow {
  font-size: 0.6rem;
  color: var(--text-dim);
  transition: transform 0.25s ease;
  flex-shrink: 0;
}
.expand-card.is-open .expand-arrow {
  transform: rotate(90deg);
}

/* Expand body */
.expand-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.expand-card.is-open .expand-body {
  max-height: 600px;
}

/* ===== RESULT TABLE (历史展开) ===== */
.result-table {
  padding: 4px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.result-header,
.result-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
}

.result-header {
  font-size: 0.65rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border-light);
}

.result-row {
  border-bottom: 1px solid rgba(255,255,255,0.02);
}
.result-row:last-child { border-bottom: none; }

.result-player {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
}

.result-hands {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: right;
}

.result-final {
  font-family: "DM Sans", sans-serif;
  font-size: 0.85rem;
  color: var(--text);
  text-align: right;
  min-width: 50px;
}

.result-net {
  font-family: "DM Sans", sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  text-align: right;
  min-width: 60px;
}

.positive { color: var(--green); }
.negative { color: var(--red); }
.zero { color: var(--text); }

/* ===== PLAYER STATS (玩家展开) ===== */
.player-stats {
  padding: 4px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-value {
  font-family: "DM Sans", sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.stat-main {
  font-family: "DM Sans", sans-serif;
  font-size: 1.1rem;
  font-weight: 800;
}

.stat-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 8px 10px;
  background: rgba(255,255,255,0.02);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}

/* ===== RESPONSIVE ===== */
@media (min-width: 640px) {
  .app-shell { padding: 28px 24px 40px; }

  .top-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .desktop-tabs {
    display: flex;
    gap: 4px;
    padding: 5px;
    border-radius: 999px;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border-light);
  }

  .desktop-tabs .nav-tab {
    padding: 9px 16px;
    border-radius: 999px;
    font-size: 0.85rem;
    color: var(--text-muted);
    background: transparent;
  }

  .desktop-tabs .nav-tab.active {
    color: #1a1206;
    background: linear-gradient(135deg, var(--gold-light), var(--gold));
  }

  .mobile-tabs { display: none; }

  .stage-panel { padding: 24px; }

  .meta-grid {
    grid-template-columns: 1fr 1fr;
    align-items: end;
  }

  .buyin-grid {
    grid-template-columns: 1fr 140px;
  }

  .player-entry-grid {
    grid-template-columns: 1fr 1fr;
  }

  .action-area {
    flex-direction: row;
    align-items: center;
  }

  .action-area .btn-full { width: auto; flex: 1; }

  .action-btns { grid-template-columns: auto auto; }

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

  .result-header,
  .result-row {
    grid-template-columns: 1fr 80px 80px 80px;
  }

  .expand-info h3 { font-size: 1rem; }

  .swipe-row {
    --swipe-action-width: 96px;
  }
}

@media (max-width: 639px) {
  .meta-grid,
  .buyin-grid,
  .date-grid,
  .player-entry-grid,
  .summary-totals {
    grid-template-columns: minmax(0, 1fr);
  }

  .summary-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .summary-check {
    width: 100%;
  }
}

@media (min-width: 960px) {
  .chip-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}
