:root {
  --bg: #0d0a14;
  --panel: rgba(16, 11, 26, 0.94);
  --panel2: rgba(30, 21, 46, 0.95);
  --edge: #3a2e4a;
  --edge2: #5a4a6e;
  --accent: #ff8a2a;
  --accent2: #ffd35c;
  --text: #efe6d4;
  --muted: #a898b8;
  --good: #5ad06a;
  --bad: #ff5a4a;
  --head: 'Press Start 2P', 'Courier New', monospace;
  --body: 'Silkscreen', 'Courier New', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; overflow: hidden; color: var(--text); font-family: var(--body); font-size: 14px; }
#game { position: fixed; left: 0; top: 0; image-rendering: pixelated; image-rendering: crisp-edges; cursor: crosshair; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#boot { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; font-family: var(--head); color: var(--accent2); background: #0d0a14; font-size: 14px; letter-spacing: 2px; }
canvas.px, img.px { image-rendering: pixelated; image-rendering: crisp-edges; }

.screen { position: absolute; inset: 0; pointer-events: auto; display: flex; flex-direction: column; align-items: center; overflow-y: auto; padding: 18px 16px 24px; }
.screen.dim { background: rgba(8, 5, 14, 0.78); }
.screen.clear { background: linear-gradient(180deg, rgba(8, 5, 14, 0.2) 0%, rgba(8, 5, 14, 0.55) 60%, rgba(8, 5, 14, 0.85) 100%); justify-content: center; }
.hidden { display: none !important; }

h1, h2, h3 { font-family: var(--head); font-weight: normal; margin: 0 0 12px; letter-spacing: 1px; }
h2 { font-size: 18px; color: var(--accent2); text-shadow: 3px 3px 0 #000; }
h3 { font-size: 11px; color: var(--accent); margin-top: 14px; }
p { line-height: 1.5; margin: 6px 0; }

/* ---- title -------------------------------------------------------------- */
.logo { font-family: var(--head); text-align: center; line-height: 1.05; user-select: none; margin-bottom: 8px; }
.logo .l1, .logo .l3 { display: block; font-size: clamp(34px, 7vw, 76px); color: var(--accent2);
  text-shadow: 4px 4px 0 #b8421a, 8px 8px 0 #000, 0 0 30px rgba(255, 140, 40, 0.35); letter-spacing: 4px; }
.logo .l2 { display: block; font-size: clamp(14px, 2.4vw, 22px); color: #fff; text-shadow: 3px 3px 0 #000; margin: 10px 0; letter-spacing: 10px; }
.tagline { font-family: var(--head); font-size: 10px; color: var(--muted); letter-spacing: 3px; margin-bottom: 26px; text-shadow: 2px 2px 0 #000; text-align: center; }
.menu { display: flex; flex-direction: column; gap: 10px; width: min(340px, 90vw); }
.footer { position: absolute; bottom: 10px; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--muted); text-shadow: 1px 1px 0 #000; pointer-events: none; }

/* ---- buttons & controls ------------------------------------------------ */
.btn { font-family: var(--head); font-size: 11px; line-height: 1.4; color: var(--text); background: #2a1e3a; border: 3px solid #000;
  box-shadow: inset -3px -3px 0 #1a1226, inset 3px 3px 0 #4e3d64; padding: 11px 14px; cursor: pointer; text-transform: uppercase; letter-spacing: 1px; }
.btn:hover, .btn:focus-visible { background: var(--accent); color: #1a0e06; box-shadow: inset -3px -3px 0 #b8521a, inset 3px 3px 0 #ffc07a; outline: none; }
.btn.primary { background: #b8421a; }
.btn.primary:hover { background: var(--accent2); }
.btn.small { font-size: 9px; padding: 7px 9px; }
.btn.danger:hover { background: var(--bad); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.center { justify-content: center; }
.grow { flex: 1; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.seg button { font-family: var(--body); font-size: 13px; background: #1e1530; color: var(--text); border: 2px solid #000; box-shadow: inset 0 0 0 1px #3a2e4a; padding: 6px 10px; cursor: pointer; }
.seg button:hover { background: #3a2a52; }
.seg button.on { background: var(--accent); color: #1a0e06; box-shadow: inset 0 0 0 1px #ffc07a; }
select, input[type=text] { font-family: var(--body); font-size: 14px; background: #120c1e; color: var(--text); border: 2px solid #000; box-shadow: inset 0 0 0 1px var(--edge2); padding: 6px 8px; }
input[type=range] { accent-color: var(--accent); }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }

.panel { background: var(--panel); border: 3px solid #000; box-shadow: inset 0 0 0 2px var(--edge), 0 6px 0 rgba(0, 0, 0, 0.5); padding: 16px; }
.wrap { width: min(1180px, 100%); }
.cols { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .cols.two { grid-template-columns: 360px 1fr; } .cols.setup { grid-template-columns: 1fr 1fr; } }
.topbar { display: flex; align-items: center; gap: 12px; width: min(1180px, 100%); margin-bottom: 12px; }
.topbar h2 { margin: 0; flex: 1; }

/* ---- cards ---------------------------------------------------------------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.card { display: flex; gap: 10px; background: #1a1228; border: 2px solid #000; box-shadow: inset 0 0 0 1px var(--edge); padding: 8px; cursor: pointer; text-align: left; color: var(--text); font-family: var(--body); font-size: 12px; }
.card:hover { box-shadow: inset 0 0 0 1px var(--accent); background: #241836; }
.card.on { box-shadow: inset 0 0 0 2px var(--accent2); background: #2e2040; }
.card.disabled { opacity: 0.45; }
.card img { width: 48px; height: 48px; flex: none; }
.card .t { font-family: var(--head); font-size: 9px; color: #fff; margin-bottom: 4px; line-height: 1.4; }
.card .meta { color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.card .d { font-size: 11px; line-height: 1.35; color: #d8cfe0; }
.card .m { font-size: 11px; color: #ff9af0; margin-top: 3px; }
.tag { display: inline-block; padding: 1px 5px; font-size: 10px; border: 1px solid #000; color: #120a18; margin-right: 4px; }

.slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.slot { background: #120c1e; border: 2px solid #000; box-shadow: inset 0 0 0 1px var(--edge2); padding: 6px; text-align: center; cursor: pointer; min-height: 88px; font-size: 11px; }
.slot.on { box-shadow: inset 0 0 0 2px var(--accent2); }
.slot img { width: 40px; height: 40px; display: block; margin: 2px auto 4px; }
.slot .k { font-family: var(--head); font-size: 9px; color: var(--accent2); }

.swatches { display: flex; flex-wrap: wrap; gap: 4px; }
.sw { width: 24px; height: 24px; border: 2px solid #000; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2); }
.sw.on { outline: 2px solid var(--accent2); outline-offset: 1px; }

.preview { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.preview canvas { background: radial-gradient(circle at 50% 70%, #3a5a2e 0%, #1a2a16 70%); border: 3px solid #000; box-shadow: inset 0 0 0 2px var(--edge); }
.stat { display: flex; justify-content: space-between; font-size: 12px; padding: 3px 0; border-bottom: 1px dashed #2e2440; width: 100%; }
.stat b { color: var(--accent2); font-weight: normal; }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { font-family: var(--head); font-size: 9px; padding: 9px 11px; background: #1e1530; color: var(--muted); border: 2px solid #000; cursor: pointer; }
.tabs button.on { background: var(--accent); color: #1a0e06; }

.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.rcard { background: #1a1228; border: 2px solid #000; box-shadow: inset 0 0 0 1px var(--edge); padding: 8px; text-align: center; cursor: pointer; font-size: 11px; position: relative; }
.rcard:hover { box-shadow: inset 0 0 0 1px var(--accent); }
.rcard.on { box-shadow: inset 0 0 0 2px var(--accent2); background: #2e2040; }
.rcard canvas { width: 72px; height: 66px; display: block; margin: 0 auto 4px; }
.rcard .n { font-family: var(--head); font-size: 8px; line-height: 1.5; color: #fff; }
.rcard .el { font-size: 10px; }
.rcard .badge { position: absolute; top: 4px; right: 4px; font-size: 9px; background: var(--accent); color: #120a18; padding: 1px 4px; }

.slotlist { display: flex; flex-direction: column; gap: 5px; max-height: 52vh; overflow-y: auto; padding-right: 4px; }
.srow { display: grid; grid-template-columns: 34px 1fr auto auto; gap: 6px; align-items: center; background: #160f24; border: 1px solid #000; padding: 4px; }
.srow canvas { width: 32px; height: 29px; }
.srow .you { font-family: var(--head); font-size: 8px; color: var(--accent2); }

.howto { columns: 2 320px; column-gap: 26px; }
.howto section { break-inside: avoid; margin-bottom: 12px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.key { font-family: var(--head); font-size: 9px; background: #2a1e3a; border: 2px solid #000; box-shadow: inset -2px -2px 0 #1a1226; padding: 4px 6px; color: var(--accent2); white-space: nowrap; text-align: center; }
.wheel { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; margin: 6px 0; }

table.res { width: 100%; border-collapse: collapse; font-size: 13px; }
table.res th { font-family: var(--head); font-size: 8px; color: var(--muted); text-align: right; padding: 6px; border-bottom: 2px solid var(--edge); }
table.res th:first-child, table.res td:first-child, table.res th:nth-child(2), table.res td:nth-child(2) { text-align: left; }
table.res td { padding: 5px 6px; text-align: right; border-bottom: 1px solid #241a34; }
table.res tr.me td { background: rgba(255, 211, 92, 0.1); }
table.res canvas { width: 32px; height: 29px; vertical-align: middle; }
.bigresult { font-family: var(--head); font-size: clamp(28px, 6vw, 56px); text-shadow: 4px 4px 0 #000; margin: 10px 0 18px; text-align: center; }
.mvp { font-family: var(--head); font-size: 8px; background: var(--accent2); color: #120a18; padding: 2px 4px; margin-left: 6px; }
.note { font-size: 11px; color: var(--muted); }
.pausebox { margin: auto; display: flex; flex-direction: column; gap: 10px; width: min(320px, 90vw); text-align: center; }

/* ---- controller navigation --------------------------------------------- */
body.pad-nav #ui :focus { outline: 3px solid var(--accent2); outline-offset: 2px; }
body.pad-nav #ui .btn:focus { background: var(--accent); color: #1a0e06; }
.toast { position: fixed; left: 50%; bottom: 18px; transform: translate(-50%, 40px); opacity: 0; transition: transform 0.25s, opacity 0.25s;
  font-family: var(--head); font-size: 10px; letter-spacing: 1px; color: #120a18; background: var(--accent2); border: 3px solid #000; padding: 10px 14px; pointer-events: none; z-index: 10; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
