:root {
  --bg: #0b0d12;
  --bg-2: #12161f;
  --line: #243044;
  --text: #e8eef8;
  --muted: #8b9bb4;
  --accent: #3d8bfd;
  --good: #3dd68c;
  --gold: #f0c14b;
  --chip: #1a2230;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --fab-space: 5.5rem;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #0b0d12;
  background-image: linear-gradient(180deg, #141a28 0%, #0b0d12 40%);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--accent);
}

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 0.85rem 0.85rem var(--fab-space);
}

.site-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.85rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
}

.brand p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  justify-content: flex-end;
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 0.55rem;
}

.mode-tab {
  appearance: none;
  border: 1px solid var(--line);
  background: #0e1420;
  color: var(--muted);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  cursor: pointer;
  font: inherit;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.mode-tab .mode-sub {
  font-size: 0.7rem;
  color: #6b7c94;
  font-weight: 400;
}

.mode-tab.active {
  color: var(--text);
  border-color: var(--accent);
  background: #173056;
  box-shadow: inset 0 0 0 1px rgba(61, 139, 253, 0.35);
}

.mode-tab.active .mode-sub {
  color: #9ec0f5;
}

.mode-banner {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  margin-bottom: 0.65rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 0.82rem;
}

.mode-banner strong {
  font-size: 0.92rem;
}

.mode-banner span {
  color: var(--muted);
  font-size: 0.78rem;
}

.mode-banner.mode-singles {
  border-color: #2f6b4a;
  background: linear-gradient(90deg, rgba(61, 214, 140, 0.14), #12161f 70%);
}

.mode-banner.mode-combos {
  border-color: #3d5a8a;
  background: linear-gradient(90deg, rgba(61, 139, 253, 0.16), #12161f 70%);
}

.btn,
.tabs button {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 8px;
  padding: 0.4rem 0.65rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}

.btn-ghost {
  min-width: 2rem;
  padding-inline: 0.5rem;
}

.btn-primary {
  background: #1b4f9c;
  border-color: #2f6fd0;
}

.btn-block {
  width: 100%;
}

.btn:hover {
  border-color: #3a4f6e;
}

.panel {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.panel-head h2 {
  margin: 0;
  font-size: 1rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 0.65rem;
}

.toolbar-pet .field.grow {
  flex: 1 1 140px;
}

.toolbar-compact .field {
  flex: 1 1 90px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.field-sm {
  flex: 0 0 4.2rem;
  max-width: 4.5rem;
}

.field label {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field select,
.field input {
  width: 100%;
  background: #0e1420;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.5rem;
  font: inherit;
  font-size: 0.9rem;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0 0 0.65rem;
}

.muted {
  color: var(--muted);
}

.rank-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.3rem;
}

.rank-list li {
  display: grid;
  grid-template-columns: 1.5rem 2.2rem minmax(0, 1fr) auto auto;
  gap: 0.3rem;
  align-items: center;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0e1420;
  font-size: 0.82rem;
}

.rank-list .medal {
  font-size: 1rem;
  text-align: center;
}

.rank-list .rank {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.rank-list .stars {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.rank-list .income {
  color: var(--good);
  text-align: right;
  font-variant-numeric: tabular-nums;
  min-width: 4.5rem;
}

.rank-list .recipe {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-list li.top-1 {
  border-color: #c9a227;
  background: linear-gradient(90deg, rgba(240, 193, 75, 0.28), #0e1420 55%);
  box-shadow: 0 0 18px rgba(240, 193, 75, 0.18);
}

.rank-list li.top-2 {
  border-color: #7a8799;
  background: linear-gradient(90deg, rgba(180, 196, 220, 0.16), #0e1420 55%);
}

.rank-list li.top-3 {
  border-color: #8a5a2b;
  background: linear-gradient(90deg, rgba(205, 127, 50, 0.14), #0e1420 55%);
}

.rank-list li.top-1 .rank,
.rank-list li.top-2 .rank,
.rank-list li.top-3 .rank {
  color: var(--text);
  font-weight: 700;
}

.rank-list li.row-click {
  cursor: pointer;
}

.rank-list li.row-click:hover {
  border-color: #3d5a8a;
  filter: brightness(1.08);
}

.rank-list li.row-click:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  margin-top: 0.75rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid var(--line);
}

.data-table th {
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
}

.site-footer {
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}

/* FAB */
.fab {
  position: fixed;
  right: max(0.85rem, env(safe-area-inset-right));
  bottom: max(0.85rem, env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid #2f6fd0;
  background: #1b4f9c;
  color: #fff;
  border-radius: 999px;
  padding: 0.7rem 1rem;
  font: inherit;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

.fab-label {
  font-size: 0.85rem;
}

/* Owned sheet */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.sheet[hidden] {
  display: none;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(88vh, 720px);
  overflow: auto;
  background: #101622;
  border-radius: 16px 16px 0 0;
  border: 1px solid var(--line);
  border-bottom: 0;
  padding: 0.4rem 0.85rem calc(1rem + env(safe-area-inset-bottom));
}

.sheet-handle {
  width: 2.5rem;
  height: 0.3rem;
  border-radius: 999px;
  background: #334155;
  margin: 0.35rem auto 0.65rem;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.sheet-head h2 {
  margin: 0;
  font-size: 1rem;
}

.add-form {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem;
  margin-bottom: 0.75rem;
  background: #0e1420;
}

.form-title {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.form-hint {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.combo-hint {
  margin: 0 0 0.75rem;
}

.form-error {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  color: #ff7b7b;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.custom-list-wrap {
  margin-bottom: 0.75rem;
}

.custom-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
}

.custom-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0e1420;
  font-size: 0.85rem;
}

.custom-list .meta-bonus {
  color: var(--gold);
  font-size: 0.78rem;
}

.custom-list .actions {
  display: flex;
  gap: 0.3rem;
}

.btn-danger {
  border-color: #6b3030;
  background: #2a1515;
  color: #ffb4b4;
}

.sheet-tools {
  margin-bottom: 0.55rem;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding-bottom: 0.5rem;
}

.chip {
  border: 1px solid var(--line);
  background: var(--chip);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.35rem 0.55rem;
  font-size: 0.78rem;
  cursor: pointer;
}

.chip.on {
  color: var(--text);
  border-color: #2f6b4a;
  background: #143526;
}

.chip.custom {
  outline: 1px dashed #4b6285;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 50;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(400px, 100%);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
}

.modal-card h3 {
  margin: 0 0 0.75rem;
}

.modal-card dl {
  margin: 0;
  display: grid;
  grid-template-columns: 2.5rem 1fr;
  gap: 0.35rem 0.75rem;
  font-size: 0.9rem;
}

.modal-card dt {
  color: var(--accent);
  font-weight: 700;
}

.modal-card dd {
  margin: 0;
  color: var(--muted);
}

.modal-actions {
  margin-top: 1rem;
  text-align: right;
}

@media (min-width: 640px) {
  .wrap {
    max-width: 640px;
    padding-top: 1.25rem;
  }
}
