/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:   #0C2340;
  --navy2:  #16324f;
  --navy3:  #1e4268;
  --green:  #005C5C;
  --green2: #00b0b0;
  --white:  #ffffff;
  --muted:  #8fb8d4;
  --border: #2a6090;
  --text:   #ddeaf5;
  --radius: 12px;
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--navy);
  color: var(--white);
  min-height: 100vh;
  padding-bottom: max(40px, env(safe-area-inset-bottom));
}

/* ── Header ── */
.app-header {
  background: var(--navy2);
  border-bottom: 2px solid var(--green);
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.app-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  flex: 1;
}

.app-header h1 span { color: var(--green2); }

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

.season-pill {
  background: var(--green);
  color: var(--white);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 20px;
  cursor: pointer;
  border: none;
  white-space: nowrap;
}

.sync-btn {
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 20px;
  cursor: pointer;
  border: 1px solid var(--border);
  white-space: nowrap;
  transition: all 0.15s;
}

.sync-btn:hover { border-color: var(--green2); color: var(--green2); }
.sync-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Sticky wrapper (header + tab bar) ── */
.sticky-top {
  position: sticky;
  top: 0;
  z-index: 100;
}

/* ── Tab bar ── */
.tab-bar {
  background: var(--navy2);
  border-bottom: 1px solid var(--border);
  display: flex;
  padding: 0 16px;
}

.tab-btn {
  padding: 11px 20px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--white); border-bottom-color: var(--green2); }

/* ── Loading ── */
#loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--green2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Dashboard ── */
#dashboard {
  padding: 16px;
  max-width: 900px;
  margin: 0 auto;
}

.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.dash-card {
  background: var(--navy2);
  border: 1px solid var(--border);
  border-top: 3px solid var(--green);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.dash-card.accent-revenue {
  border-top-color: var(--green2);
}

.dash-card .dash-icon {
  font-size: 1.1rem;
  line-height: 1;
  margin-bottom: 6px;
  display: block;
}

.dash-card .num {
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--white);
  line-height: 1;
}

.dash-card.accent-revenue .num {
  color: var(--green2);
}

.dash-card .lbl {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 5px;
}

/* ── Filters ── */
.filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 0 16px;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
  align-items: center;
}

.filter-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 2px;
}

.filter-btn {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.filter-btn:hover { border-color: var(--green2); color: var(--text); }
.filter-btn.active {
  background: var(--green);
  border-color: var(--green);
  color: var(--white);
  box-shadow: 0 0 0 2px rgba(0,92,92,0.35);
}

/* ── Games List ── */
#games-list {
  padding: 0 16px;
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Game Card ── */
.game-card {
  background: var(--navy2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.game-card:hover { border-color: var(--green2); }
.game-card.expanded { border-color: var(--green); box-shadow: 0 0 0 2px rgba(0,92,92,0.2); }

.game-card.past { opacity: 0.6; }

.game-header {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.game-num {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 700;
  min-width: 26px;
  text-align: center;
  background: var(--navy3);
  border-radius: 6px;
  padding: 3px 5px;
}

.game-date {
  font-size: 0.88rem;
  font-weight: 700;
  min-width: 80px;
  color: var(--text);
}

.game-opp {
  font-size: 0.82rem;
  color: var(--muted);
  min-width: 36px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.game-promo {
  font-size: 0.73rem;
  color: var(--green2);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-status-pills {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.mini-badge {
  width: 24px; height: 24px;
  border-radius: 50%;
  font-size: 0.62rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.game-expand-icon {
  color: var(--muted);
  font-size: 0.8rem;
  margin-left: 4px;
  transition: transform 0.2s;
}

.game-card.expanded .game-expand-icon { transform: rotate(180deg); }

/* ── Game Detail (expanded) ── */
.game-detail {
  display: none;
  padding: 0 14px 14px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.game-card.expanded .game-detail { display: block; }

.game-meta {
  display: flex;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.game-meta span strong { color: var(--white); }

/* ── Item Rows ── */
.item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.item-row:last-child { border-bottom: none; }

.item-label {
  font-size: 0.82rem;
  font-weight: 600;
  min-width: 70px;
  color: var(--text);
}

.item-status-wrap { flex: 1; }

.status-select {
  background: var(--navy3);
  border: 1px solid var(--border);
  color: var(--white);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.82rem;
  width: 100%;
  max-width: 160px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238fb8d4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.status-select:focus { outline: none; border-color: var(--green2); }

.price-wrap {
  display: flex;
  gap: 6px;
  align-items: center;
}

.price-input {
  background: var(--navy3);
  border: 1px solid var(--border);
  color: var(--white);
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 0.82rem;
  width: 80px;
  text-align: right;
}

.price-input::placeholder { color: var(--muted); }
.price-input:focus { outline: none; border-color: var(--green2); }

.price-lbl {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ── Notes Row ── */
.notes-row {
  padding: 10px 0 4px;
  border-top: 1px solid rgba(255,255,255,0.07);
  margin-top: 4px;
}

.notes-row label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.notes-textarea {
  width: 100%;
  background: var(--navy3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
  line-height: 1.5;
}

.notes-textarea::placeholder { color: var(--muted); }
.notes-textarea:focus { outline: none; border-color: var(--green2); }

/* ── Save button area ── */
.save-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.save-btn {
  background: var(--green);
  color: var(--white);
  border: none;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.save-btn:hover { opacity: 0.85; }
.save-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.save-feedback {
  font-size: 0.78rem;
  min-height: 18px;
  flex: 1;
}

.save-feedback.ok  { color: #6ee89a; }
.save-feedback.err { color: #e88e6e; }

/* ── Result badge ── */
.result-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: auto;
  flex-shrink: 0;
}

.result-W { background: #0f3a1a; color: #6ee89a; }
.result-L { background: #3a0f0f; color: #e88e6e; }

/* ── Status colors ── */
.s-Josh     { background: #1a4090; color: #a8ccff; }
.s-Hiroe    { background: #1a4090; color: #a8ccff; }
.s-Himena   { background: #3a1a7a; color: #c0a0ff; }
.s-Mauricio { background: #3a1a7a; color: #c0a0ff; }
.s-Mizuki   { background: #0a3a2a; color: #80f0b8; }
.s-Sold     { background: #0f3a1a; color: #6ee89a; }
.s-Listed   { background: #3a2a00; color: #f0d060; }
.s-TurnIn   { background: #3a1a0a; color: #f0a06e; }
.s-Gifted   { background: #3a0a3a; color: #f08ef0; }
.s-Undecided{ background: #252525; color: #909090; }

/* ── No results ── */
.no-results {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--green);
  color: var(--white);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.88rem;
  font-weight: 600;
  z-index: 999;
  transition: transform 0.3s;
  pointer-events: none;
  white-space: nowrap;
}

#toast.show { transform: translateX(-50%) translateY(0); }

/* ── Season selector modal ── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--navy2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  min-width: 280px;
  max-width: 340px;
  width: 90%;
}

.modal h3 {
  font-size: 1rem;
  margin-bottom: 16px;
  color: var(--green2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.season-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.season-option:hover { border-color: var(--green2); }
.season-option.active { border-color: var(--green); background: rgba(0,92,92,0.15); }

.modal-close {
  display: block;
  width: 100%;
  padding: 10px;
  margin-top: 12px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  transition: border-color 0.15s;
}

.modal-close:hover { border-color: var(--green2); color: var(--text); }

/* ── Stats ── */
.stats-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stat-card {
  background: var(--navy2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat-section-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
  margin-bottom: 14px;
  font-weight: 700;
}

/* Record */
.stat-big-record {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}

.stat-w    { font-size: 2.4rem; font-weight: 800; color: #6ee89a; line-height: 1; }
.stat-l    { font-size: 2.4rem; font-weight: 800; color: #e88e6e; line-height: 1; }
.stat-dash { font-size: 1.6rem; color: var(--muted); }

.stat-win-bar {
  height: 8px;
  background: var(--navy3);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.stat-win-fill { height: 100%; border-radius: 4px; background: var(--green2); }

.stat-note { font-size: 0.76rem; color: var(--muted); margin-top: 5px; }
.stat-note.warn  { color: #f0a06e; }
.stat-note.muted { color: var(--muted); opacity: 0.75; }

/* Leaderboard */
.leader-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.leader-row:last-child { border-bottom: none; }

.leader-rank { font-size: 0.9rem; min-width: 22px; color: var(--muted); }
.leader-name { font-size: 0.88rem; font-weight: 700; min-width: 74px; color: var(--text); }

.leader-bar-wrap {
  flex: 1;
  height: 8px;
  background: var(--navy3);
  border-radius: 4px;
  overflow: hidden;
}

.leader-bar-fill { height: 100%; border-radius: 4px; transition: width 0.5s ease; }

.leader-stat {
  font-size: 0.84rem;
  font-weight: 700;
  min-width: 80px;
  text-align: right;
  color: var(--text);
}

.leader-stat small {
  display: block;
  font-size: 0.66rem;
  color: var(--muted);
  font-weight: 400;
  margin-top: 1px;
}

/* Disposition */
.disp-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
}

.disp-label { font-size: 0.78rem; min-width: 76px; color: var(--text); }

.disp-bar-wrap {
  flex: 1;
  height: 8px;
  background: var(--navy3);
  border-radius: 4px;
  overflow: hidden;
}

.disp-bar-fill { height: 100%; border-radius: 4px; }

.disp-count { font-size: 0.75rem; color: var(--text); min-width: 52px; text-align: right; }

/* Revenue */
.rev-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 10px;
}

.rev-card {
  background: var(--navy3);
  border-radius: 8px;
  padding: 12px 8px;
  text-align: center;
}

.rev-card .rev-num {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--green2);
  line-height: 1;
}

.rev-card .rev-lbl {
  font-size: 0.62rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-top: 5px;
}

/* Month table */
.month-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.month-table th {
  text-align: left;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 8px 10px 0;
  border-bottom: 1px solid var(--border);
}

.month-table td {
  padding: 9px 8px 9px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  color: var(--text);
}

.month-table tr:last-child td { border-bottom: none; }
.month-table .wl-win  { color: #6ee89a; font-weight: 700; }
.month-table .wl-loss { color: #e88e6e; font-weight: 700; }
.miss-warn { color: #f0a06e; font-size: 0.7rem; }

/* ── Responsive ── */
@media (max-width: 480px) {
  .price-wrap { flex-wrap: wrap; }
  .price-input { width: 70px; }
  .game-promo { display: none; }
  .dash-card .num { font-size: 1.4rem; }
  .dash-card .dash-icon { font-size: 0.95rem; }
}
