:root {
  --bg: #12151c;
  --panel: #1a2030;
  --panel2: #222a3c;
  --text: #e8ecf4;
  --muted: #9aa3b5;
  --faint: #6b7382;
  --accent: #6cb6ff;
  --good: #5dcea0;
  --warn: #e6c07b;
  --bad: #e06c75;
  --strong: #c792ea;
  --border: #2e384e;
  --buy: #2a6f4e;
  --gold: #ffd76a;
  --dock: #171b26;
  --app-height: 100dvh;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { overflow: hidden; }
body {
  margin: 0;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.app {
  position: relative;
  width: 100%;
  max-width: 1100px;
  height: var(--app-height, 100dvh);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

h1 { margin: 0; font-size: 16px; font-weight: 700; }
h2 { font-size: 1.05rem; margin: 0 0 0.6rem; color: var(--accent); }
h3 { margin: 0 0 10px; font-size: 15px; }
.sub { margin: 0; color: var(--muted); font-size: 10px; }
.hidden { display: none !important; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 4px;
}
.header-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.save-status {
  flex: none;
  text-align: right;
  padding: 2px 14px 6px;
  font-size: 10px;
  color: var(--faint);
}

.expert-chip {
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 11px;
  min-height: 44px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
}

.scroll {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.scroll > * { max-width: 100%; }

.progress-bar {
  margin: 2px 12px 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.prog-id {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  background: none;
  border: 0;
  color: inherit;
  padding: 0;
  text-align: left;
  cursor: pointer;
}
.prog-id strong { font-size: 13px; font-weight: 600; }
.hero-id {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--good);
}
.prog-nav { display: flex; gap: 4px; align-items: center; flex: none; }
.prog-nav button {
  width: 44px;
  height: 44px;
  border-radius: 7px;
  padding: 0;
  font-size: 16px;
}
.jump-select { display: none; }

.gold-box {
  margin: 10px 12px 0;
  background: linear-gradient(145deg, #3a3018, #2a2414);
  border: 1px solid #8a7030;
  border-radius: 12px;
  padding: 10px 14px;
  text-align: center;
}
.gold-label { font-size: 10px; letter-spacing: 0.08em; color: var(--warn); }
.gold-amount { font-size: 34px; font-weight: 700; color: var(--gold); line-height: 1.1; }
.gold-policy { font-size: 11px; color: var(--muted); margin-top: 2px; }
.gold-policy .policy-id { font-family: ui-monospace, monospace; color: var(--faint); }
.gold-remain { margin-top: 4px; color: var(--good); font-weight: 600; font-size: 13px; }

.sp-row {
  margin: 10px 12px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  min-width: 0;
  padding-bottom: 2px;
}
.sp-label {
  flex: none;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sp-row ul {
  display: flex;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.sp-row li {
  flex: none;
  background: #2a2140;
  border: 1px solid #5a4780;
  color: var(--strong);
  border-radius: 999px;
  padding: 2px 9px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
}
.sp-row li.muted-chip { color: var(--muted); background: transparent; border-color: var(--border); }

.hero-info-btn {
  display: block;
  width: calc(100% - 24px);
  margin: 10px 12px 0;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 44px;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.hero-inline { display: none; }
.tag {
  display: inline-block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-right: 0.35rem;
}

.bag-block { margin: 10px 12px 0; }
.bag-label {
  font-size: 10px;
  color: var(--warn);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.bag {
  margin-top: 6px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.bag .card { min-height: 96px; }
.card.selling {
  background: #3a2a18;
  border-color: #c9a227;
}
.sell-flag {
  font-size: 10px;
  background: #3a2a18;
  color: var(--gold);
  border: 1px solid #8a7030;
  border-radius: 4px;
  padding: 2px 7px;
  font-weight: 700;
  letter-spacing: 0.03em;
  display: none;
}
.card.selling .sell-flag { display: inline-block; }
.bag-modes button { font-size: 12px; padding: 8px 4px; }

.shelf-heading {
  margin: 12px 12px 0;
  font-size: 13px;
}
.shelf {
  margin: 8px 12px 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  min-width: 0;
}
.card-wrap { position: relative; min-width: 0; }
.card {
  background: var(--panel2);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px 12px 28px;
  min-height: 118px;
  cursor: pointer;
  min-width: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  transition: border-color 0.15s, background 0.15s;
}
.card.bought {
  background: #163528;
  border-color: var(--good);
}
.card.unaffordable { opacity: 0.55; }
.card.unaffordable.bought { opacity: 1; }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.card-cost {
  background: #3a3018;
  color: var(--gold);
  border-radius: 6px;
  padding: 3px 8px;
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}
.card-name {
  margin-top: 10px;
  font-weight: 600;
  font-size: 13px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.card-meta { font-size: 10.5px; color: var(--muted); margin-top: 3px; }
.badge-strong {
  display: inline-block;
  margin-top: 7px;
  background: #3a2758;
  color: var(--strong);
  border: 1px solid #7a5aad;
  border-radius: 4px;
  font-size: 9.5px;
  padding: 1px 6px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-weight: 600;
}
.buy-flag {
  font-size: 10px;
  background: var(--buy);
  color: #dff8ea;
  border-radius: 4px;
  padding: 2px 7px;
  font-weight: 700;
  letter-spacing: 0.03em;
  display: none;
}
.card.bought .buy-flag { display: inline-block; }
.card-info {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
}
.card-info span {
  width: 22px;
  height: 22px;
  margin: 0 7px 7px 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-family: Georgia, serif;
  font-style: italic;
}

@keyframes cardShake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}
.card.shake { animation: cardShake 0.4s; }

.reason-row { margin: 12px 12px 0; }
.reason-row label, .custom-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
input[type="text"], select {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 16px;
  width: 100%;
}
.reason-row input { text-transform: none; letter-spacing: 0; }

.reroll-row { text-align: center; margin: 10px 0 14px; }
.text-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  min-height: 44px;
  padding: 8px 12px;
  text-decoration: underline;
  cursor: pointer;
}

.session { display: none; }
.session pre {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  overflow: auto;
  font-size: 0.8rem;
  color: #c8d0e0;
  max-height: 14rem;
}

.dock {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--dock);
  border-top: 1px solid var(--border);
}
.dock button {
  flex: 1;
  min-height: 44px;
  border-radius: 9px;
  padding: 12px 4px;
  font-size: 14px;
}
.dock .primary { flex: 1.3; font-weight: 600; }

button {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  touch-action: manipulation;
}
button.primary { background: #1e4d7a; border-color: #3d7eb8; }
button.accent { background: #3a2a18; border-color: #8a7030; color: var(--gold); }
button.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  max-width: calc(100% - 32px);
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12px;
  text-align: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
.backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 20;
}
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  max-height: 72%;
  overflow-y: auto;
  background: var(--panel);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  user-select: text;
  -webkit-user-select: text;
}
#sheet-menu { max-height: 80%; }
.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 12px;
}
.sheet-kicker {
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}
.sheet p { margin: 0 0 10px; font-size: 13px; }
.sheet-notes { color: var(--muted); line-height: 1.5; font-size: 12.5px; }
.sheet-close, .menu-row {
  width: 100%;
  min-height: 44px;
  text-align: left;
  padding: 11px 12px;
  margin-top: 6px;
}
.sheet-close { text-align: center; margin-top: 12px; }
.sheet-split { display: flex; gap: 8px; }
.sheet-split button { flex: 1; min-height: 44px; }
.card-sheet-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.card-sheet-top h3 { font-size: 16px; margin: 0; }
.card-sheet-meta { font-size: 11px; color: var(--muted); margin-bottom: 10px; }
.sheet-sp { margin-bottom: 10px; }
.card-sheet-desc { font-size: 13px; color: #c5ccd9; line-height: 1.5; }

.expert-picks { display: flex; gap: 6px; margin-bottom: 14px; }
.expert-picks button { flex: 1; min-height: 44px; }
.expert-picks button.is-on { background: #1e4d7a; border-color: #3d7eb8; }
.custom-label { margin-bottom: 12px; }
.custom-label input { text-transform: none; letter-spacing: 0; }
.menu-note { font-size: 11px; color: var(--faint); margin: 8px 2px; }
.reset-box {
  background: #2a1620;
  border: 1px solid var(--bad);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 6px;
}
.jump-list { display: flex; flex-direction: column; gap: 6px; }
.jump-list button {
  width: 100%;
  min-height: 44px;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 11px 12px;
}
.jump-list button.is-current { background: var(--panel2); }
.jump-list .mono { font-family: ui-monospace, monospace; overflow-wrap: anywhere; }

@media (min-width: 900px) {
  .jump-select { display: block; width: auto; min-width: 12rem; min-height: 44px; font-size: 14px; }
  .hero-info-btn { display: none; }
  .hero-inline {
    display: grid;
    gap: 0.35rem;
    margin: 10px 12px 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem 1rem;
  }
  .shelf { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .session { display: block; margin: 4px 12px 16px; }
  .gold-box {
    display: flex;
    align-items: baseline;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px 22px;
    text-align: left;
  }
  .gold-amount { font-size: 2rem; }
  .gold-policy, .gold-remain { margin-top: 0; }
  .card:hover { border-color: var(--accent); }
  .card.bought:hover { border-color: var(--good); }
}

@media (max-width: 899px) {
  .shelf-heading { display: none; }
}
