:root {
  --bg: #0b1220;
  --bg2: #0f172a;
  --panel: #131c31;
  --border: #22304d;
  --text: #e6edf7;
  --muted: #93a4c5;
  --accent: #f7b500;   /* Pokemon-yellow */
  --accent2: #e53935;  /* Pokeball red */
  --good: #34d399;
  --bad: #f87171;
  --you: #1e3a5f;
  --gm: #1a2a1f;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}

#app {
  display: flex; flex-direction: column;
  height: 100dvh;
  max-width: 640px; margin: 0 auto;
  background: var(--bg2);
}

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  background: linear-gradient(180deg, #101a30, #0d1526);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
header h1 { font-size: 17px; margin: 0; letter-spacing: 0.5px; }
.title { display: flex; align-items: center; gap: 8px; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #64748b; box-shadow: 0 0 0 3px rgba(100,116,139,0.15);
}
.dot.listening { background: var(--good); box-shadow: 0 0 0 4px rgba(52,211,153,0.2); animation: pulse 1.2s infinite; }
.dot.thinking  { background: var(--accent); box-shadow: 0 0 0 4px rgba(247,181,0,0.2); animation: pulse 0.9s infinite; }
.dot.speaking  { background: var(--accent2); box-shadow: 0 0 0 4px rgba(229,57,53,0.2); animation: pulse 0.7s infinite; }
.dot.error     { background: var(--bad);   box-shadow: 0 0 0 4px rgba(248,113,113,0.2); }
@keyframes pulse { 50% { transform: scale(1.15); } }

.header-buttons button {
  margin-left: 6px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
}

main#transcript {
  flex: 1; overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
}

.msg {
  padding: 10px 14px;
  border-radius: 16px;
  max-width: 88%;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.msg.you  { align-self: flex-end;   background: var(--you); border-bottom-right-radius: 4px; }
.msg.gm   { align-self: flex-start; background: var(--gm);  border-bottom-left-radius: 4px; }
.msg.sys  { align-self: center; font-size: 12px; color: var(--muted); background: transparent; box-shadow: none; }

/* Character-tagged spoken segments */
.msg.segment { padding: 8px 12px 10px; }
.msg.segment .speaker-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.msg.segment.character { background: #1e2a3f; border-left: 3px solid var(--accent); }
.msg.segment.character .speaker-label { color: var(--accent); }
.msg.segment .segment-body { line-height: 1.4; }

.tool-tag {
  display: inline-block;
  font-size: 11px;
  color: var(--muted);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  margin: 2px 4px 0 0;
}

footer {
  border-top: 1px solid var(--border);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
}
#statusLine { font-size: 12px; color: var(--muted); min-height: 16px; }
#partial { min-height: 20px; font-size: 14px; color: var(--muted); font-style: italic; }
.partial:not(:empty)::before { content: "\201C"; }
.partial:not(:empty)::after  { content: "\201D"; }

.controls { display: flex; gap: 8px; margin-top: 8px; }
.controls button {
  flex: 1;
  border: 1px solid var(--border);
  background: #1a2440; color: var(--text);
  border-radius: 12px; padding: 12px 10px;
  font-size: 15px; font-weight: 600;
  touch-action: manipulation;
}
.controls button.mic.on { background: var(--good); color: #052; border-color: transparent; }
.controls button.ptt.on { background: var(--accent2); color: #fff; border-color: transparent; }
.controls button.mute.off { background: #333; color: var(--muted); }
.controls button.stop { background: #b91c1c; color: #fff; border-color: transparent; }
.controls button.stop:active { background: #7f1d1d; }
.controls button.sendnow { background: #16a34a; color: #fff; border-color: transparent; }
.controls button.sendnow:active { background: #15803d; }

.type-form { display: flex; gap: 6px; margin-top: 8px; }
.type-form input {
  flex: 1;
  background: #0e1730; color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; font-size: 14px;
}
.type-form button {
  background: var(--accent); color: #1a1200; border: 0;
  border-radius: 12px; padding: 0 14px; font-weight: 700;
}

/* ---------- Slide-up state panel with tabs ---------- */
/* Per-tab accent colors — each page tints its background, border, and
 * section headers so the tabs feel distinct like Game Boy menu screens. */
:root {
  --party-accent:   #34d399;   /* emerald */
  --bag-accent:     #f7b500;   /* amber */
  --pokedex-accent: #e53935;   /* pokeball red */
  --log-accent:     #60a5fa;   /* sky blue */
  --cast-accent:    #a78bfa;   /* violet */
}

#statePanel[hidden] { display: none !important; }
#statePanel {
  position: fixed; inset: 0;
  background: rgba(6,10,20,0.7);
  backdrop-filter: blur(6px);
  z-index: 20;
  overflow-y: auto;
  display: flex; flex-direction: column; align-items: center;
  padding: 0;
}
#statePanel > * { width: 100%; max-width: 620px; }

.panel-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom)) 10px;
  position: sticky; top: 0;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  z-index: 2;
}
.panel-header .tabs {
  display: flex; flex: 1; gap: 4px; overflow-x: auto;
  scrollbar-width: none;
}
.panel-header .tabs::-webkit-scrollbar { display: none; }
.panel-header .tab {
  background: transparent; color: var(--muted);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, border-color .15s, background .15s;
}
.panel-header .tab:hover { color: var(--text); }
.panel-header .tab.active { color: var(--text); background: rgba(255,255,255,0.05); }
.panel-header .tab[data-accent="party"].active   { border-color: var(--party-accent);   box-shadow: 0 2px 0 0 var(--party-accent) inset; }
.panel-header .tab[data-accent="bag"].active     { border-color: var(--bag-accent);     box-shadow: 0 2px 0 0 var(--bag-accent) inset; }
.panel-header .tab[data-accent="pokedex"].active { border-color: var(--pokedex-accent); box-shadow: 0 2px 0 0 var(--pokedex-accent) inset; }
.panel-header .tab[data-accent="log"].active     { border-color: var(--log-accent);     box-shadow: 0 2px 0 0 var(--log-accent) inset; }
.panel-header .tab[data-accent="cast"].active    { border-color: var(--cast-accent);    box-shadow: 0 2px 0 0 var(--cast-accent) inset; }

#closeState {
  background: var(--accent); color: #1a1200;
  border: 0; border-radius: 999px;
  padding: 8px 14px; font-size: 13px; font-weight: 700;
}

/* Pages */
#statePages { padding: 12px; }
.page[hidden] { display: none; }
.page { animation: fadeIn 0.18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Each page gets a subtle top accent stripe and matching section headings.
 * The base card background stays dark for text contrast. */
.page-party   { --page-accent: var(--party-accent); }
.page-bag     { --page-accent: var(--bag-accent); }
.page-pokedex { --page-accent: var(--pokedex-accent); }
.page-log     { --page-accent: var(--log-accent); }
.page-cast    { --page-accent: var(--cast-accent); }

.page::before {
  content: '';
  display: block; height: 3px;
  border-radius: 3px;
  background: var(--page-accent);
  margin-bottom: 14px;
  opacity: 0.85;
}
.page .section-title { color: var(--page-accent); border-bottom-color: rgba(255,255,255,0.06); }
.page .trainer-card { border-color: var(--page-accent); }
.page .slot { background: var(--page-accent); color: #0b1220; }
.page .status-badge { color: var(--page-accent); border-color: var(--page-accent); background: color-mix(in srgb, var(--page-accent) 20%, transparent); }

/* Tighter card variant used on non-Party pages for denser info. */
.mini-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; margin-bottom: 4px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; font-size: 14px;
}
.mini-row .qty { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.mini-row .sub { color: var(--muted); font-size: 12px; }

/* Pokedex grid */
.dex-grid {
  display: grid; gap: 6px;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}
.dex-cell {
  padding: 8px 10px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; text-align: center;
}
.dex-cell.caught { border-color: var(--page-accent); color: var(--text); }
.dex-cell.seen   { color: var(--muted); font-style: italic; }
.dex-cell::before {
  content: '●'; margin-right: 6px; font-size: 10px;
  color: var(--muted);
}
.dex-cell.caught::before { color: var(--page-accent); }
.mon {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 8px;
}
.mon.trainer-card { border-color: var(--accent); background: linear-gradient(180deg, #1a2440, #131c31); }
.mon.fainted { opacity: 0.55; border-style: dashed; }
.mon.event { background: #101a30; }
.mon .row1 { display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.mon .row2 { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 4px; }
.mon .moves { font-size: 12px; color: var(--muted); margin-top: 6px; font-family: ui-monospace, "SF Mono", Consolas, monospace; }
.slot {
  display: inline-block; width: 20px; height: 20px; line-height: 20px; text-align: center;
  background: var(--accent); color: #1a1200; border-radius: 50%; font-size: 11px; font-weight: 700;
  margin-right: 6px; vertical-align: middle;
}
.status-badge {
  display: inline-block; background: rgba(247,181,0,0.2); color: var(--accent);
  border: 1px solid var(--accent); border-radius: 4px;
  font-size: 10px; padding: 1px 5px; margin-left: 4px; font-weight: 700;
  vertical-align: middle;
}
.status-badge.faint { background: rgba(248,113,113,0.2); color: var(--bad); border-color: var(--bad); }
.hpbar {
  height: 8px; background: #22304d; border-radius: 4px; margin-top: 8px; overflow: hidden;
}
.hpbar > span { display: block; height: 100%; background: var(--good); transition: width 0.4s ease; }
.hpbar > span.mid { background: var(--accent); }
.hpbar > span.low { background: var(--bad); }
.section-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--muted); margin: 18px 0 8px 4px;
  border-bottom: 1px solid var(--border); padding-bottom: 4px;
}

/* D&D ability score grid (STR/DEX/CON/INT/WIS/CHA). */
.ability-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin: 6px 0 4px;
}
.ability-cell {
  background: #0f1830; border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 6px; text-align: center;
}
.ability-cell .ab-label {
  font-size: 11px; letter-spacing: 1.5px; color: var(--muted);
}
.ability-cell .ab-score {
  font-size: 22px; font-weight: 700; color: var(--text); margin: 2px 0;
}
.ability-cell .ab-mod {
  font-size: 13px; color: var(--accent); font-weight: 600;
}

/* Alignment badge. */
.align-badge {
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  letter-spacing: 0.5px;
}
.align-badge.good    { background: #14532d; color: #bbf7d0; }
.align-badge.kind    { background: #052e16; color: #86efac; }
.align-badge.neutral { background: #1f2937; color: #cbd5e1; }
.align-badge.cruel   { background: #431407; color: #fdba74; }
.align-badge.evil    { background: #7f1d1d; color: #fecaca; }

/* Police-heat / bounty badge. Colors escalate: yellow -> orange -> red. */
.bounty-badge {
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  letter-spacing: 0.5px;
}
.bounty-badge.clean      { background: #1f2937; color: #cbd5e1; }
.bounty-badge.suspicious { background: #78350f; color: #fef3c7; }
.bounty-badge.wanted     { background: #92400e; color: #fed7aa; }
.bounty-badge.marked     { background: #9a3412; color: #fed7aa; }
.bounty-badge.priority   { background: #b91c1c; color: #fecaca; }
.bounty-badge.enemy      { background: #7f1d1d; color: #fecaca; }
.bounty-badge.notorious  {
  background: linear-gradient(90deg, #7f1d1d, #b91c1c);
  color: #fee2e2;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}

/* Shiny Pokemon: gold sparkle border + label. */
.mon.shiny {
  border-color: #facc15;
  box-shadow: 0 0 0 1px rgba(250, 204, 21, 0.35), 0 0 16px rgba(250, 204, 21, 0.15);
  background: linear-gradient(180deg, #1c2440, #131c31 65%, #2a2314);
}
.shiny-badge {
  background: linear-gradient(90deg, #facc15, #f59e0b);
  color: #422006; font-size: 10px; font-weight: 800;
  letter-spacing: 1.2px; padding: 2px 6px; border-radius: 6px;
  vertical-align: middle;
}
