:root {
  --bg: #120f1c;
  --bg2: #1b1729;
  --panel: #221d33;
  --panel2: #2b2541;
  --line: #3a3354;
  --text: #ece6f5;
  --muted: #a69cbd;
  --gold: #e8c26a;
  --gold2: #c08a2e;
  --red: #e0605a;
  --green: #5fbf7f;
  --blue: #6aa8e8;
  --me: #2f4a6b;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.5 Inter, system-ui, sans-serif;
  background: radial-gradient(120% 60% at 50% -10%, #2a2045 0%, var(--bg) 60%) fixed;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--gold); }
a.btn, a.game-item, a.icon-btn { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
h1, h2, h3 { font-family: Cinzel, serif; font-weight: 700; letter-spacing: .02em; margin: 0; }

/* --- układ --- */
.screen { min-height: 100dvh; display: flex; flex-direction: column; padding-top: var(--safe-t); }
.wrap { width: 100%; max-width: 720px; margin: 0 auto; padding: 16px; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-t)) 12px 8px; margin-top: calc(-1 * var(--safe-t));
  background: rgba(18, 15, 28, .92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 17px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  min-width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel);
  display: inline-flex; align-items: center; justify-content: center; padding: 0 10px; font-size: 15px;
}
.icon-btn svg { width: 20px; height: 20px; }

/* --- przyciski i pola --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px;
  padding: 12px 18px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel2);
  font-weight: 600;
}
.btn.primary { background: linear-gradient(180deg, var(--gold), var(--gold2)); color: #1d1405; border: 0; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label, .label { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.input, textarea.input, select.input {
  width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg2); outline: none; font-size: 16px;
}
.input:focus { border-color: var(--gold2); }
.hint { font-size: 13px; color: var(--muted); }

/* --- logowanie --- */
.login { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card img { width: 96px; height: 96px; border-radius: 24px; margin-bottom: 16px; box-shadow: 0 10px 40px rgba(232, 194, 106, .15); }
.login-card h1 { font-size: 26px; margin-bottom: 4px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.login-card form { text-align: center; }
.login-card .label { display: block; margin-bottom: 8px; }
.input.code {
  width: 200px; display: block; margin: 0 auto; min-height: 64px; text-align: center; font-size: 34px;
  letter-spacing: .5em; padding-left: .5em; font-variant-numeric: tabular-nums; -webkit-text-security: disc;
}
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.error { color: var(--red); font-size: 14px; min-height: 20px; margin: 8px 0 12px; text-align: center; }

/* --- ekran główny --- */
.hero { text-align: center; padding: 24px 0 8px; }
.hero h1 { font-size: 28px; }
.hero p { color: var(--muted); margin: 6px 0 0; font-family: "Crimson Pro", serif; font-size: 19px; font-style: italic; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 20px 0 28px; }
.actions .btn.primary { grid-column: 1 / -1; min-height: 56px; font-size: 17px; }
.section-title { font-size: 14px; color: var(--muted); margin: 0 0 10px; font-family: Inter, sans-serif; text-transform: uppercase; letter-spacing: .08em; }
.game-list { display: flex; flex-direction: column; gap: 10px; }
.game-item {
  display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line); text-align: left; width: 100%;
}
.game-item .gi-icon { font-size: 24px; width: 40px; text-align: center; }
.game-item .gi-main { flex: 1; min-width: 0; }
.game-item .gi-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-item .gi-sub { font-size: 13px; color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 24px; border: 1px dashed var(--line); border-radius: var(--radius); }

/* --- nowa gra --- */
.choice-grid { display: grid; gap: 10px; }
.choice {
  display: block; text-align: left; padding: 14px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--panel); width: 100%;
}
.choice b { display: block; margin-bottom: 2px; }
.choice span { font-size: 14px; color: var(--muted); }
.choice.on { border-color: var(--gold); background: linear-gradient(180deg, #3a2f1a, var(--panel)); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; min-height: 44px; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 14px; }
.seg button.on { border-color: var(--gold); color: var(--gold); background: #2f2718; }

/* --- gra --- */
.game-screen { height: 100dvh; display: flex; flex-direction: column; padding-top: 0; }
.game-screen .topbar { margin-top: 0; }
/* jeden pasek: życie · tura (dotknij = cały stół) · życie przeciwnika */
.statusbar { display: flex; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--bg2); align-items: stretch; }
.statusbar .life {
  flex: 0 0 68px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05;
  padding: 3px 4px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line);
}
.statusbar .life.me { border-color: #35557a; }
.statusbar .life.opp { border-color: #6a3434; }
.statusbar .life b { font-size: 21px; font-family: Cinzel, serif; }
.statusbar .life small { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
.statusbar .turn {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.25;
  border: 0; background: none; font-size: 13px; color: var(--muted); padding: 0 4px;
}
.statusbar .turn b { color: var(--text); }
.statusbar .turn small, .statusbar .turn span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.statusbar .turn i { font-style: normal; font-size: 11px; color: var(--gold); }
.life-edit { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 14px 0 6px; }
.life-edit .btn { min-width: 52px; padding: 10px 8px; }
.life-edit b { font-size: 34px; font-family: Cinzel, serif; min-width: 64px; text-align: center; }
.menu { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.btn.danger { color: #ffb3ae; border-color: #6a3434; }

.table-panel { border-bottom: 1px solid var(--line); background: #0d0b15; overflow-y: auto; }
.table-panel.full { max-height: 45dvh; }
.zone.compact { padding: 6px 10px; }
.zone.compact .cards-row { align-items: center; padding-bottom: 0; }
.opp-hand { flex: 0 0 auto; font-size: 13px; color: var(--muted); padding: 4px 8px; border: 1px solid var(--line); border-radius: 999px; margin-right: 2px; }
.zone { padding: 6px 12px; }
.zone h3 { font-family: Inter, sans-serif; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.zone h3 .count { color: var(--text); }
.cards-row { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.cards-row::-webkit-scrollbar { display: none; }
.mini {
  flex: 0 0 auto; width: 46px; border-radius: 4px; overflow: hidden; border: 0; padding: 0; background: #000;
  aspect-ratio: 63 / 88; position: relative; transition: transform .2s;
}
.mini img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mini.tapped img, .mini.tapped .ph { filter: brightness(.45) grayscale(.4); }
.mini .tap { position: absolute; top: 2px; left: 2px; font-size: 9px; padding: 0 3px; border-radius: 3px; background: #000c; color: var(--muted); }
.mini .cnt { position: absolute; top: 2px; right: 2px; font-size: 11px; font-weight: 600; padding: 0 4px; border-radius: 5px; background: #000d; color: var(--gold); }
.mini .ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 4px; font-size: 9px; line-height: 1.15; background: linear-gradient(160deg, #3a3354, #1b1729); color: var(--text); }
.mini .note { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.75); font-size: 9px; padding: 1px 3px; color: var(--gold); }
.back { flex: 0 0 auto; width: 26px; aspect-ratio: 63 / 88; border-radius: 4px; background: repeating-linear-gradient(45deg, #5a3d1e 0 4px, #3d2812 4px 8px); border: 2px solid #1a0f05; }

.chat { flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }
.msg { max-width: 100%; }
.msg.user { align-self: flex-end; max-width: 86%; }
.msg.user .bubble { background: var(--me); border-radius: 16px 16px 4px 16px; padding: 10px 14px; white-space: pre-wrap; }
.msg.user .photos { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; margin-bottom: 6px; }
.msg.user .photos img { width: 120px; height: 120px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }
.msg.user .tag { font-size: 12px; color: var(--muted); text-align: right; margin-bottom: 4px; }
.msg.assistant .bubble {
  background: linear-gradient(180deg, #241e36, #1e1a2d); border: 1px solid var(--line); border-radius: 4px 16px 16px 16px;
  padding: 12px 14px;
}
.msg.assistant .who { font-family: Cinzel, serif; font-size: 12px; color: var(--gold); margin-bottom: 4px; letter-spacing: .06em; }
.msg.system { align-self: center; font-size: 13px; color: var(--muted); font-style: italic; }
.md p { margin: 0 0 10px; }
.md p:last-child { margin-bottom: 0; }
.md em { font-family: "Crimson Pro", Georgia, serif; font-size: 1.12em; color: #e9dcc0; }
.md strong { color: var(--gold); font-weight: 600; }
.md em strong, .md strong em { color: #f3cf7c; }
.md h1, .md h2, .md h3, .md h4 { font-size: 16px; margin: 12px 0 6px; color: var(--gold); }
.md ul, .md ol { margin: 4px 0 10px; padding-left: 20px; }
.md li { margin: 2px 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.md code { background: #0006; padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.md blockquote { margin: 6px 0; padding: 4px 10px; border-left: 3px solid var(--gold2); color: #e9dcc0; }
.btn.retry { min-height: 40px; padding: 8px 16px; margin-top: 10px; border-color: var(--gold2); color: var(--gold); }
.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.dots span { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--gold); margin-right: 3px; animation: blink 1.2s infinite; }
.dots span:nth-child(2) { animation-delay: .2s; }
.dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
.msg-cards { display: flex; gap: 8px; overflow-x: auto; margin-top: 10px; padding-bottom: 2px; scrollbar-width: none; }
.msg-cards::-webkit-scrollbar { display: none; }
.msg-card { flex: 0 0 auto; width: 68px; border: 0; padding: 0; background: none; text-align: center; }
.msg-card .mini { width: 68px; }
.msg-card small { display: block; font-size: 10px; color: var(--muted); margin-top: 3px; line-height: 1.2; }
.msg-card small.opp { color: #f08b84; }

/* --- pole wpisywania --- */
.composer { border-top: 1px solid var(--line); background: rgba(18, 15, 28, .96); padding: 8px 10px calc(8px + var(--safe-b)); }
.quick { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }
.quick button.hot { border-color: var(--gold); color: var(--gold); background: #2f2718; font-weight: 600; }
.quick button { flex: 0 0 auto; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font-size: 13px; white-space: nowrap; }
.attach-row { display: flex; gap: 8px; align-items: center; padding: 6px 0 8px; overflow-x: auto; scrollbar-width: none; }
.attach-row::-webkit-scrollbar { display: none; }
.attach-row .labels { flex-wrap: nowrap; padding-bottom: 0; }
.attach-row .labels button { white-space: nowrap; }
.thumb { position: relative; flex: 0 0 auto; }
.thumb img { width: 48px; height: 48px; object-fit: cover; border-radius: 10px; border: 1px solid var(--gold2); display: block; }
.thumb button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--red); font-size: 12px; line-height: 1; }
.labels { display: flex; gap: 6px; }
.labels button { padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font-size: 13px; }
.labels button.on { border-color: var(--gold); color: var(--gold); background: #2f2718; }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
.cam-btn { width: 48px; height: 48px; flex: 0 0 auto; border-radius: 14px; border: 1px solid var(--gold2); background: #2f2718; display: flex; align-items: center; justify-content: center; }
.cam-btn svg { width: 24px; height: 24px; color: var(--gold); }
.gal-btn { border-color: var(--line); background: var(--panel); }
.gal-btn svg { color: var(--muted); }
.input-row textarea { flex: 1; min-height: 48px; max-height: 140px; resize: none; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg2); outline: none; font-size: 16px; line-height: 1.4; }
.send-btn { width: 48px; height: 48px; flex: 0 0 auto; border-radius: 14px; border: 0; background: linear-gradient(180deg, var(--gold), var(--gold2)); color: #1d1405; display: flex; align-items: center; justify-content: center; }
.send-btn svg { width: 22px; height: 22px; }
.send-btn:disabled { opacity: .4; }

/* --- kolekcja --- */
.coll-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.coll-item { position: relative; }
.coll-item .mini { width: 100%; }
.modal .mini, .coll-grid .mini { width: 100%; }
.coll-item .qty { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.8); color: var(--gold); border-radius: 8px; padding: 0 6px; font-weight: 600; font-size: 13px; }
.coll-item .nm { font-size: 11px; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .input { flex: 1; min-width: 160px; }

/* --- okno karty --- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(8, 6, 14, .88); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { width: 100%; max-width: 380px; max-height: 92dvh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 14px; }
.modal-card img.big { width: 100%; border-radius: 14px; display: block; }
.modal-card .oracle { white-space: pre-wrap; font-size: 15px; margin-top: 10px; }
.modal-card .tl { color: var(--muted); font-size: 13px; margin-top: 8px; }
.modal-card .row { display: flex; gap: 8px; margin-top: 12px; }
.modal-card .row .btn { flex: 1; }
.modal img.photo { max-width: 100%; max-height: 86dvh; border-radius: 12px; }

.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 60; background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; box-shadow: 0 8px 30px #0008; }

@media (min-width: 760px) {
  .chat { padding: 16px 20%; }
  .composer, .statusbar, .zone { padding-left: max(12px, calc(50% - 360px)); padding-right: max(12px, calc(50% - 360px)); }
}

/* rzadziej zmieniane ustawienia nowej gry */
details.more { margin-bottom: 16px; border: 1px solid var(--line); border-radius: var(--radius); padding: 0 14px; background: var(--bg2); }
details.more summary { padding: 14px 0; font-weight: 600; color: var(--muted); cursor: pointer; }
details.more[open] summary { margin-bottom: 4px; }
