:root {
  --wood: #2b1a0e;
  --wood-2: #3a2414;
  --wood-3: #4b301b;
  --felt: #2f5d43;
  --felt-2: #24493a;
  --ink: #f5ead6;
  --muted: #c2ab8c;
  --accent: #f0b84a;
  --red: #d9483b;
  --green: #5cbf7a;
  --paper: #f6ecd4;
  --paper-edge: #d7c29a;
  --paper-ink: #3b2412;
  --blue: #3f74b5;
  --brown: #9a6a3a;
  --radius: 12px;
  /* 5 hand cards per row must fit inside #me at any phone width */
  --card-w: min(calc((min(100vw, 560px) - 70px) / 5.4), 74px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at 50% 20%, var(--wood-3), var(--wood) 75%) fixed;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  padding: env(safe-area-inset-top) 10px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

header { display: flex; align-items: center; height: 52px; gap: 8px; }
header h1 { flex: 1; margin: 0; font-size: 21px; display: flex; align-items: center; gap: 6px; letter-spacing: .02em; }
.logo { font-size: 20px; }
.header-right { display: flex; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px;
  border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .09);
  font-size: 17px; cursor: pointer;
}
.pill-btn { border: 0; border-radius: 18px; height: 36px; padding: 0 14px; background: rgba(255, 255, 255, .09); font-weight: 600; }
#btn-lang {
  display: flex; align-items: center; padding: 2px; border: 0; border-radius: 999px;
  background: rgba(255, 255, 255, .09); font-size: 12px; font-weight: 700; height: 36px;
}
#btn-lang span { padding: 4px 8px; border-radius: 999px; color: var(--muted); }
#btn-lang span.on { background: var(--accent); color: #2a1a05; }

button { cursor: pointer; }
.primary, #btn-join, #btn-addbot, #action-bar button, .pbtns button, .seg button {
  border: 0;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-weight: 700;
  background: rgba(255, 255, 255, .12);
}
.primary, #action-bar button.primary, .pbtns button.primary { background: var(--accent); color: #2a1a05; }
.primary.wide { width: 100%; margin-top: 8px; }
button:disabled { opacity: .4; cursor: default; }
.danger, .pbtns button.danger { background: var(--red); color: #fff; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 8px; }
.muted { color: var(--muted); }
.mini { border: 0; border-radius: 8px; padding: 4px 8px; font-size: 12px; background: rgba(255, 255, 255, .14); margin-left: auto; }

/* ---------- lobby ---------- */
#lobby { display: flex; flex-direction: column; gap: 14px; padding-top: 8vh; }
.tagline { text-align: center; color: var(--muted); margin: 0 0 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; color: var(--muted); }
input {
  border: 1px solid rgba(255, 255, 255, .18);
  background: rgba(0, 0, 0, .25);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 16px;
  outline: none;
}
input:focus { border-color: var(--accent); }
.or { text-align: center; color: var(--muted); font-size: 13px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: .2em; }

/* ---------- waiting ---------- */
#waiting { display: flex; flex-direction: column; gap: 12px; padding-top: 12px; }
.chip { border: 1px dashed var(--accent); background: rgba(240, 184, 74, .08); border-radius: var(--radius); padding: 12px; color: var(--ink); }
.chip b { color: var(--accent); letter-spacing: .15em; }
#waiting h2 { font-size: 16px; margin: 8px 0 0; }
#wait-players { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
#wait-players li { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: rgba(0, 0, 0, .2); border-radius: 10px; }
#wait-players li.offline { opacity: .5; }
#host-controls { display: flex; flex-direction: column; gap: 10px; }
.opt-row { display: flex; align-items: center; gap: 10px; }
.opt-label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.seg { display: flex; flex: 1; gap: 4px; background: rgba(0, 0, 0, .2); border-radius: var(--radius); padding: 4px; }
.seg button { flex: 1; padding: 8px 4px; font-size: 13px; background: transparent; color: var(--muted); }
.seg button.on { background: rgba(255, 255, 255, .14); color: var(--ink); }
.btn-row { display: flex; gap: 8px; }
.btn-row .primary { flex: 1; }
.hint { color: var(--muted); font-size: 14px; text-align: center; margin: 0; }

.name { font-weight: 700; color: var(--c, var(--ink)); }
.badge { font-size: 11px; padding: 2px 6px; border-radius: 6px; background: rgba(255, 255, 255, .12); }
.badge.host { background: var(--accent); color: #2a1a05; }

.role { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; white-space: nowrap; }
.role.big { font-size: 13px; padding: 4px 8px; }
.role-sheriff { background: #e8b93c; color: #3a2405; }
.role-deputy { background: #4b8fd6; color: #fff; }
.role-outlaw { background: #3a3a3a; color: #fff; border: 1px solid #777; }
.role-renegade { background: #8c4bc9; color: #fff; }

.hp { display: inline-flex; gap: 1px; font-size: 13px; letter-spacing: -1px; }
.hp i { font-style: normal; color: rgba(255, 255, 255, .2); }
.hp i.on { color: var(--red); }

/* ---------- game: table ring ---------- */
#game { display: flex; flex-direction: column; gap: 8px; }
#table {
  position: relative;
  width: 100%;
  height: clamp(300px, calc((100vw - 20px) * .95), 500px);
}
/* the felt in the middle; seats sit on the ring around it */
#table::before {
  content: '';
  position: absolute;
  inset: 13% 11%;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 40%, var(--felt), var(--felt-2) 75%);
  box-shadow: inset 0 0 30px rgba(0, 0, 0, .45), 0 0 0 7px #6b4423, 0 0 0 9px #3a2414, 0 6px 18px rgba(0, 0, 0, .5);
}
/* layers: felt < seats < arrows < stage < badges, so an arrow between neighbours still shows over the boxes */
#seats { z-index: 1; }
#arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; z-index: 2; }
#stage { z-index: 3; }
#fx { z-index: 4; }
#arrows line {
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw .35s ease-out forwards;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .7));
}
#arrows marker path { fill: var(--accent); }
@keyframes draw { to { stroke-dashoffset: 0; } }

#seats { position: absolute; inset: 0; }
.opp {
  position: absolute;
  width: 29%;
  transform: translate(-50%, -50%);
  background: rgba(20, 10, 4, .78);
  border: 2px solid rgba(255, 255, 255, .1);
  border-radius: 10px;
  padding: 5px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}
.opp.active { border-color: var(--c); box-shadow: 0 0 12px color-mix(in srgb, var(--c) 60%, transparent); }
.opp.waiting::after, .me-seat.waiting::after { content: '…'; position: absolute; top: -2px; right: 5px; color: var(--accent); font-weight: 700; animation: blink 1s infinite; }
.opp.dead { opacity: .5; }
.opp.target-ok { border-color: var(--accent); background: rgba(90, 60, 10, .9); animation: pulse 1.2s infinite; }
.opp.target-no { opacity: .35; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(240, 184, 74, .35); } }
@keyframes blink { 50% { opacity: .2; } }
.opp-head { display: flex; align-items: center; gap: 3px; min-width: 0; }
.opp-head .name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ricon { font-size: 12px; flex-shrink: 0; }
.opp-head .bot { font-size: 11px; flex-shrink: 0; }
.opp-char { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opp-meta { display: flex; align-items: center; gap: 4px; font-size: 11px; flex-wrap: wrap; }
.opp-meta .hp { font-size: 10px; letter-spacing: -1.5px; }
.opp-meta .dist { color: var(--muted); }
.opp-meta .dist.in { color: var(--accent); font-weight: 700; }
.opp-table { display: flex; flex-wrap: wrap; gap: 2px; }
.opp-dead { font-size: 11px; color: var(--muted); }
.ichip { font-size: 12px; line-height: 17px; padding: 0 3px; border-radius: 4px; background: rgba(63, 116, 181, .45); border: 1px solid rgba(120, 170, 230, .45); white-space: nowrap; cursor: pointer; }
.ichip.t-jail { background: rgba(120, 120, 120, .45); border-color: #aaa; }
.ichip.t-dynamite { background: rgba(217, 72, 59, .4); border-color: #ff8a7a; }

.me-seat {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(20, 10, 4, .85);
  border: 2px solid var(--c);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}
.me-seat.active { box-shadow: 0 0 12px color-mix(in srgb, var(--c) 60%, transparent); }
.me-seat.dead { opacity: .5; }
.me-seat .hp { font-size: 11px; }

#stage {
  position: absolute;
  left: 50%; top: 46%;
  transform: translate(-50%, -50%);
  width: 46%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  text-align: center;
  pointer-events: none;
  transition: opacity .6s;
}
#stage.stale { opacity: .45; }
#stage .caption {
  width: 100%; /* -webkit-box would otherwise size itself to the unwrapped text and spill over the seats */
  font-size: 12px;
  line-height: 1.35;
  word-break: keep-all;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .9);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
#stage .caption.big { font-size: 15px; font-weight: 700; }
#stage .cchip { color: var(--accent); }
.card.pop { animation: pop .35s cubic-bezier(.2, 1.4, .5, 1); }
@keyframes pop { from { transform: scale(.3) rotate(-12deg); opacity: 0; } }

#fx { position: absolute; inset: 0; pointer-events: none; }
.badge-fx {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 900;
  font-size: 24px;
  text-shadow: 0 1px 4px #000, 0 0 10px rgba(0, 0, 0, .8);
  animation: rise 1.6s ease-out forwards;
}
.badge-fx.hit { color: #ff5a4a; }
.badge-fx.heal { color: var(--green); }
.badge-fx.dead { color: #fff; font-size: 30px; }
@keyframes rise {
  0% { opacity: 0; margin-top: -4px; }
  15% { opacity: 1; }
  100% { opacity: 0; margin-top: -44px; }
}

/* ---------- game: ticker, prompt, me ---------- */
#ticker { display: flex; gap: 8px; align-items: center; background: rgba(0, 0, 0, .18); border-radius: 10px; padding: 6px 8px; }
#piles { display: flex; gap: 4px; }
.pile { display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11px; color: var(--muted); }
#feed { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; font-size: 12px; }
#feed .line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .55; }
#feed .line:last-child { opacity: 1; }
.cchip { font-weight: 700; color: var(--accent); }
.face { font-weight: 700; padding: 0 1px; }
.face.red { color: #ff7b6b; }

#prompt { border-radius: var(--radius); padding: 10px; background: rgba(0, 0, 0, .3); display: flex; flex-direction: column; gap: 8px; }
#prompt.mine { background: rgba(217, 72, 59, .2); border: 2px solid var(--red); animation: glow 1.4s infinite; }
@keyframes glow { 50% { border-color: #ff9b8c; } }
.ptext { font-weight: 600; line-height: 1.5; }
.pbtns { display: flex; flex-wrap: wrap; gap: 6px; }
.pbtns button { flex: 1 1 auto; padding: 11px 12px; }
.pcards { display: flex; flex-wrap: wrap; gap: 6px; }

#me { background: rgba(0, 0, 0, .22); border: 2px solid transparent; border-radius: 14px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
#me.active { border-color: var(--accent); }
#me.dead { opacity: .6; }
.me-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.char-btn { border: 0; background: rgba(255, 255, 255, .1); border-radius: 8px; padding: 4px 8px; font-size: 13px; font-weight: 600; }
.reach { font-size: 13px; color: var(--muted); margin-left: auto; }
.table-row { display: flex; flex-wrap: wrap; gap: 4px; min-height: 0; }
.table-row:empty { display: none; }
.tchip { font-size: 11px; padding: 2px 5px; border-radius: 5px; background: rgba(63, 116, 181, .35); border: 1px solid rgba(120, 170, 230, .45); white-space: nowrap; cursor: pointer; }
.tchip.t-jail { background: rgba(120, 120, 120, .45); border-color: #aaa; }
.tchip.t-dynamite { background: rgba(217, 72, 59, .4); border-color: #ff8a7a; }
#status { font-size: 14px; color: var(--muted); min-height: 1.2em; }
#status.mine { color: var(--accent); font-weight: 700; }
#my-hand { display: flex; flex-wrap: wrap; gap: 5px; }
#action-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#action-bar:empty { display: none; }
#action-bar button { flex: 1 1 auto; }
.sel-desc { flex-basis: 100%; font-size: 14px; line-height: 1.5; background: rgba(255, 255, 255, .06); border-radius: 8px; padding: 8px 10px; }
.hint-target { flex: 1; color: var(--accent); font-weight: 700; }

/* ---------- cards ---------- */
.card {
  width: var(--card-w);
  aspect-ratio: 5 / 7;
  border-radius: 7px;
  background: var(--paper);
  color: var(--paper-ink);
  border: 3px solid var(--brown);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .35);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 2px;
  transition: transform .12s;
}
.card.blue { border-color: var(--blue); }
.card .face { position: absolute; top: 2px; left: 4px; font-size: 11px; color: var(--paper-ink); }
.card .face.red { color: #c0392b; }
.card .icon { font-size: calc(var(--card-w) * .38); line-height: 1; }
.card .cname { font-size: 11px; font-weight: 800; text-align: center; line-height: 1.1; word-break: keep-all; }
.card .range { position: absolute; top: 2px; right: 4px; font-size: 11px; font-weight: 800; color: var(--blue); }
.card.xs { width: 30px; border-width: 2px; border-radius: 4px; }
.card.xs .icon { font-size: 14px; }
.card.xs .cname, .card.xs .face, .card.xs .range { display: none; }
.card.sm { width: 40px; border-width: 2px; }
.card.sm .icon { font-size: 15px; }
.card.sm .cname { font-size: 8px; }
.card.sm .face, .card.sm .range { font-size: 8px; }
.card.md { width: 58px; }
.card.md .icon { font-size: 23px; }
.card.md .cname { font-size: 10px; }
.card.md .face, .card.md .range { font-size: 10px; }
.card.lg { width: 110px; flex-shrink: 0; }
.card.lg .icon { font-size: 42px; }
.card.lg .cname { font-size: 14px; }
.card.back { background: repeating-linear-gradient(45deg, #7a3b20, #7a3b20 4px, #8c4a2a 4px, #8c4a2a 8px); border: 2px solid #5a2a14; }
.card.empty { background: transparent; border: 2px dashed rgba(255, 255, 255, .2); box-shadow: none; }
.card.playable { cursor: pointer; }
.card.selected { transform: translateY(-8px); box-shadow: 0 0 0 3px var(--accent), 0 6px 10px rgba(0, 0, 0, .4); }
.card.picked { transform: translateY(-6px); box-shadow: 0 0 0 3px var(--red); opacity: .8; }

/* ---------- result ---------- */
#result { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.result-card { background: var(--wood-2); border: 2px solid var(--accent); border-radius: 16px; padding: 18px; width: min(100%, 420px); display: flex; flex-direction: column; gap: 10px; }
.result-card h2 { margin: 0; text-align: center; }
#result-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
#result-list li { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; background: rgba(0, 0, 0, .2); font-size: 14px; }
#result-list li.won { background: rgba(240, 184, 74, .2); }
#result-list li span:last-child { margin-left: auto; }

/* ---------- dialogs ---------- */
dialog {
  border: 0;
  border-radius: 16px;
  background: var(--wood-2);
  color: var(--ink);
  width: min(92vw, 480px);
  max-height: 85vh;
  padding: 16px 18px;
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h2 { margin: 0 0 10px; font-size: 18px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
dialog h3 { margin: 14px 0 4px; font-size: 15px; color: var(--accent); }
dialog p { margin: 4px 0; line-height: 1.55; font-size: 14px; }
dialog form { margin-top: 14px; }
dialog form button { width: 100%; border: 0; border-radius: var(--radius); padding: 12px; font-weight: 700; background: rgba(255, 255, 255, .12); }
dialog form button.primary { background: var(--accent); color: #2a1a05; }
.info-card { display: flex; gap: 14px; align-items: flex-start; }
.info-card h3 { margin-top: 0; }
.info-row { font-size: 14px; line-height: 1.5; padding: 6px 0; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.info-row.blue b { color: #8fb8ec; }
.roles { padding-left: 18px; margin: 4px 0; font-size: 14px; line-height: 1.6; }
#pick-title { display: block; }
.pick-opt { display: block; width: 100%; text-align: left; border: 0; border-radius: 10px; padding: 12px; margin-bottom: 6px; background: rgba(255, 255, 255, .1); font-weight: 600; }
.log-line { font-size: 13px; padding: 4px 0; border-bottom: 1px solid rgba(255, 255, 255, .06); line-height: 1.5; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: rgba(20, 12, 5, .92);
  border: 1px solid var(--accent);
  border-radius: 20px;
  padding: 10px 18px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: .2s;
  z-index: 20;
  max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
