:root {
  --felt: #14302e; --felt2: #1d4440; --ink: #2b2118; --paper: #f5ecd9; --paper2: #e9dcc0;
  --gold: #e2b65b; --text: #f3ead8; --muted: #a9b9b4; --danger: #e06b5b; --ok: #7fcf8f;
  --radius: 14px; --cw: 104px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { background: #14302e; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse at 50% 30%, var(--felt2), var(--felt) 70%) fixed;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
h1, h2, h3, .bigcode, .mename, .cname { font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; justify-content: center; }
.grow { flex: 1; }
#app { max-width: 920px; margin: 0 auto; min-height: 100%; padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom); }
.screen { padding: 16px 0 24px; }

/* Buttons & inputs */
.btn {
  appearance: none; border: 1px solid #ffffff30; background: #ffffff14; color: var(--text);
  padding: 11px 16px; border-radius: 12px; font: inherit; font-weight: 600; cursor: pointer;
  transition: transform .08s, background .2s;
}
.btn:active { transform: scale(.97); }
.btn:hover { background: #ffffff22; }
.btn.primary { background: var(--gold); color: #2a1d08; border-color: transparent; }
.btn.primary:hover { background: #ecc676; }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.wide { width: 100%; }
.btn.small { padding: 6px 10px; font-size: 14px; }
.link { display: block; margin: 14px auto 0; background: none; border: 0; color: var(--gold); font: inherit; text-decoration: underline; cursor: pointer; }
.iconbtn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid #ffffff30; background: #ffffff10; color: var(--text); font-size: 18px; cursor: pointer; }
input {
  width: 100%; padding: 12px 14px; font: inherit; border-radius: 12px; border: 1px solid #ffffff35;
  background: #0d211f; color: var(--text); outline: none;
}
input:focus { border-color: var(--gold); }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.row { display: flex; gap: 10px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.row input { flex: 1; min-width: 0; }
#code { text-transform: uppercase; letter-spacing: .3em; text-align: center; font-weight: 700; max-width: 140px; }
.panel { background: #0b1d1bcc; border: 1px solid #ffffff1a; border-radius: 20px; padding: 20px; max-width: 440px; margin: 0 auto; box-shadow: 0 10px 40px #0006; }
.or { text-align: center; margin: 16px 0; color: var(--muted); position: relative; }
.or::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid #ffffff20; }
.or span { background: #0d1f1d; padding: 0 10px; position: relative; }

/* Home */
.hero { text-align: center; padding: 28px 0 20px; }
.hero-dove { font-size: 64px; animation: float 4s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px) rotate(-4deg); } }
.hero h1 { font-size: 44px; margin: 4px 0; color: var(--gold); letter-spacing: .02em; }
.tag { color: var(--muted); margin: 6px auto 0; max-width: 380px; }
#rejoin { margin-top: 12px; }

/* Lobby */
.bigcode { font-size: 56px; text-align: center; letter-spacing: .25em; color: var(--gold); font-weight: 700; margin: 0 0 6px; }
.plist { list-style: none; padding: 0; margin: 0 0 16px; }
.plist li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: #ffffff0d; margin-bottom: 6px; }
.plist li .grow { font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.dot.off { background: #777; }

/* Game layout */
.topbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.pill { background: #ffffff12; border-radius: 99px; padding: 5px 11px; font-size: 13px; font-weight: 600; }
.opponents { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 6px; }
@media (max-width: 480px) { .opp { padding: 6px 8px; } .opp-head { font-size: 14px; } .minis { min-height: 0; } .table { margin: 10px 0 4px; gap: 10px; } .hand { min-height: 0; padding-top: 10px; } }
.opp {
  background: #0b1d1bb3; border: 2px solid transparent; border-radius: var(--radius); padding: 8px 10px;
  transition: border-color .2s, opacity .2s, transform .1s; position: relative;
}
.opp.turn { border-color: var(--gold); box-shadow: 0 0 0 3px #e2b65b33; }
.opp.out { opacity: .5; }
.opp.targetable { cursor: pointer; border-color: #ffffff60; animation: pulse 1.2s ease-in-out infinite; }
.opp.targeted { border-color: var(--gold); background: #3b3317; animation: none; }
@keyframes pulse { 50% { border-color: #ffffffb0; } }
.opp-head { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.opp-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.opp-sub { font-size: 13px; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tokens { color: var(--gold); letter-spacing: -2px; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: #ffffff1c; color: var(--text); letter-spacing: 0; }
.badge.out { background: #e06b5b44; }
.badge.shield { background: #6b8f5a66; }
.minis { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 6px; min-height: 22px; }
.mini { width: 20px; height: 22px; border-radius: 4px; font-size: 11px; font-weight: 800; display: grid; place-items: center; color: #2a1d08; box-shadow: inset 0 0 0 1px #0003; }
.backs { display: inline-flex; gap: 2px; }
.backs i { width: 10px; height: 14px; border-radius: 2px; background: linear-gradient(135deg, #7d2f2a, #4c1a17); box-shadow: inset 0 0 0 1px #e2b65b66; }

.table { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 16px 0 8px; flex-wrap: wrap; }
.deck { position: relative; width: 56px; height: 78px; flex: none; }
.deck .back { position: absolute; inset: 0; border-radius: 8px; background: linear-gradient(135deg, #7d2f2a, #4c1a17); box-shadow: 3px 3px 0 #3a1512, 6px 6px 0 #2b0f0d, inset 0 0 0 3px #e2b65b77; }
.deck .back::after { content: "🕊️"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 24px; opacity: .8; }
.deck span { position: absolute; bottom: -8px; right: -10px; background: var(--gold); color: #2a1d08; font-weight: 800; border-radius: 99px; padding: 1px 8px; font-size: 13px; }
.faceup { display: flex; gap: 4px; }
.lastlog { flex: 1 1 260px; max-width: 460px; font-size: 14px; color: var(--paper); background: #00000033; border-radius: 12px; padding: 8px 12px; min-height: 40px; }
.status { text-align: center; font-weight: 700; margin: 6px 0 10px; min-height: 24px; }
.status.mine { color: var(--gold); }

.me { background: #0b1d1bcc; border-radius: 20px; padding: 12px; border: 2px solid transparent; }
.me.turn { border-color: var(--gold); }
.me.out { opacity: .65; }
.me-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mename { font-size: 20px; font-weight: 700; }
.hand { display: flex; gap: 14px; justify-content: center; padding: 14px 0 6px; min-height: 180px; }
.discards { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }

/* Cards */
.card {
  width: var(--cw); height: calc(var(--cw) * 1.45); flex: none; border-radius: 12px; position: relative;
  background: linear-gradient(170deg, var(--paper), var(--paper2)); color: var(--ink);
  box-shadow: 0 6px 18px #0007, inset 0 0 0 1px #0002; overflow: hidden; user-select: none;
  transition: transform .15s, box-shadow .15s; display: flex; flex-direction: column; align-items: center;
}
.card::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 46%; background: var(--c); opacity: .9; }
.card .val { position: absolute; top: 4px; left: 7px; font: 800 20px/1 Georgia, serif; color: #fff; text-shadow: 0 1px 2px #0008; z-index: 1; }
.card .ico { position: relative; font-size: calc(var(--cw) * .36); margin-top: calc(var(--cw) * .1); filter: drop-shadow(0 2px 2px #0004); }
.card .cname { position: relative; font-weight: 700; font-size: calc(var(--cw) * .135); margin-top: calc(var(--cw) * .1); text-align: center; line-height: 1.1; }
.card .ctext { position: relative; font-size: calc(var(--cw) * .085); line-height: 1.25; padding: 4px 7px 0; text-align: center; color: #4a3d2e; }
.hand .card { --cw: min(150px, 40vw); cursor: pointer; }
.hand .card:hover { transform: translateY(-4px); }
.hand .card.sel { transform: translateY(-10px); box-shadow: 0 0 0 3px var(--gold), 0 12px 24px #0009; }
.hand .card.locked { filter: grayscale(.6); opacity: .7; }
.card.sm { --cw: 46px; border-radius: 6px; }
.card.sm .ctext, .card.sm .cname { display: none; }
.card.sm .val { font-size: 13px; top: 2px; left: 4px; }
.card.md { --cw: 84px; }
.card.md .ctext { display: none; }

/* Action panel */
.action { background: #00000040; border-radius: 14px; padding: 12px; margin-top: 8px; }
.action h4 { margin: 0 0 8px; font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { border: 1px solid #ffffff40; background: #ffffff10; color: var(--text); border-radius: 99px; padding: 7px 12px; font: inherit; font-size: 14px; cursor: pointer; }
.chip.on { background: var(--gold); color: #2a1d08; border-color: transparent; font-weight: 700; }
.action .note { font-size: 13px; color: var(--muted); margin: 0 0 10px; }

/* Drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(360px, 88vw); background: #0b1b19; border-left: 1px solid #ffffff20; transform: translateX(100%); transition: transform .25s; z-index: 20; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
.drawer.open { transform: none; box-shadow: -10px 0 40px #0008; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid #ffffff15; }
#logList { margin: 0; padding: 8px 14px 20px 34px; overflow-y: auto; font-size: 14px; flex: 1; }
#logList li { margin-bottom: 8px; }
#logList li.priv { color: var(--gold); }

/* Modal */
.modal { position: fixed; inset: 0; background: #000a; z-index: 30; display: grid; place-items: center; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal-box { background: #10302c; border: 1px solid #ffffff25; border-radius: 20px; padding: 20px; width: min(560px, 100%); max-height: 88vh; overflow-y: auto; box-shadow: 0 20px 60px #000a; }
.modal-box h2 { margin: 0 0 10px; color: var(--gold); }
.modal-cards { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 14px 0; }
.modal-cards figure { margin: 0; text-align: center; font-size: 13px; }
.modal-cards figcaption { margin-top: 6px; font-weight: 600; }
.rcards { display: grid; gap: 8px; }
.rcard { display: flex; gap: 12px; align-items: center; background: #ffffff0a; border-radius: 12px; padding: 8px; }
.rcard p { margin: 2px 0 0; font-size: 14px; color: #d8d0bd; }
.rcard .cnt { font-size: 12px; color: var(--muted); }
.score { list-style: none; padding: 0; }
.score li { display: flex; justify-content: space-between; padding: 6px 4px; border-bottom: 1px solid #ffffff12; }
.score li.win { color: var(--gold); font-weight: 700; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 140%); background: #2b1c0e; color: #ffe7c2; border: 1px solid #e2b65b66; padding: 10px 16px; border-radius: 12px; transition: transform .25s, opacity .25s; opacity: 0; pointer-events: none; z-index: 40; max-width: 90vw; text-align: center; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.conn { position: fixed; top: 8px; left: 50%; transform: translateX(-50%); background: var(--danger); color: #fff; padding: 5px 14px; border-radius: 99px; font-size: 13px; z-index: 50; }

@media (min-width: 760px) {
  .opponents { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
  .hand .card { --cw: 160px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
