/* ===== Tokens ===== */
:root {
  --bg: #f2f0ea;
  --surface: #ffffff;
  --surface-2: #f7f6f1;
  --ink: #1d2b25;
  --muted: #68756e;
  --line: #ddd9cf;
  --accent: #0e8f63;
  --accent-hover: #0c7d57;
  --accent-soft: #e3f4ec;
  --accent-ink: #ffffff;
  --danger: #d64545;
  --gold: #d9a514;
  --felt1: #2e8b62;
  --felt2: #20684a;
  --felt-line: rgba(255, 255, 255, 0.18);
  --card-face: #ffffff;
  --shadow: 0 10px 30px rgba(23, 34, 28, 0.12);
  --shadow-sm: 0 3px 10px rgba(23, 34, 28, 0.1);
  --r: 14px;
  --r-sm: 10px;
}

[data-theme="dark"] {
  --bg: #0f1413;
  --surface: #1a201d;
  --surface-2: #222925;
  --ink: #e9eeea;
  --muted: #94a19a;
  --line: #2e3732;
  --accent: #2cc488;
  --accent-hover: #25af79;
  --accent-soft: #18382a;
  --accent-ink: #07271a;
  --danger: #ef6b6b;
  --gold: #e6b422;
  --felt1: #1d5c40;
  --felt2: #143f2c;
  --felt-line: rgba(255, 255, 255, 0.1);
  --card-face: #f4f6f4;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 3px 10px rgba(0, 0, 0, 0.4);
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background:
    radial-gradient(900px 500px at 85% -10%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 60%),
    radial-gradient(700px 420px at -10% 110%, color-mix(in srgb, var(--gold) 8%, transparent), transparent 60%),
    var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }

.screen { min-height: 100dvh; display: flex; flex-direction: column; }

/* ===== Controles genéricos ===== */
.btn {
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  padding: 11px 20px;
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-big { padding: 13px 22px; font-size: 1.05rem; }
.btn-small { padding: 7px 14px; font-size: 0.9rem; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, black); }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: var(--r-sm);
  transition: background 0.15s, border-color 0.15s;
}
.ghost-btn:hover { background: var(--surface-2); border-color: var(--muted); }

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 7px 10px;
  font-size: 1.05rem;
  line-height: 1;
  list-style: none;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--surface-2); }

.linkish {
  background: none;
  border: 0;
  color: var(--accent);
  padding: 4px 2px;
  font-size: 0.92rem;
  text-decoration: none;
}
.linkish:hover { text-decoration: underline; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.field input, .field select {
  background: var(--surface-2);
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  padding: 11px 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
.field input:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.float-theme { position: fixed; top: 10px; right: 12px; z-index: 60; }

/* Switch */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  font-size: 0.95rem;
}
.switch-row span { flex: 1; }
input.switch {
  appearance: none;
  width: 42px;
  height: 24px;
  flex: none;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  outline: none;
  transition: background 0.2s;
  margin: 0;
}
input.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: left 0.2s;
}
input.switch:checked { background: var(--accent); }
input.switch:checked::after { left: 21px; }
input.switch:disabled { opacity: 0.5; cursor: not-allowed; }
input.switch:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

/* Menu dropdown */
.menu { position: relative; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary { cursor: pointer; user-select: none; display: inline-block; }
.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-width: 170px;
  padding: 6px;
  z-index: 70;
}
.menu-list button {
  background: none;
  border: 0;
  text-align: left;
  padding: 9px 12px;
  border-radius: 7px;
  font-size: 0.95rem;
}
.menu-list button:hover { background: var(--surface-2); }

/* Dialog */
.dlg {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 22px;
  max-width: min(92vw, 380px);
  width: 100%;
}
.dlg::backdrop { background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(2px); }
.dlg p { margin: 0 0 18px; line-height: 1.5; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ===== Tela inicial ===== */
.home { align-items: center; justify-content: center; padding: 24px 16px; }
.home-card {
  width: min(94vw, 430px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 34px 30px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.hero { text-align: center; margin-bottom: 2px; }
.hero h1 { margin: 6px 0 8px; font-size: 1.9rem; letter-spacing: -0.5px; }
.hero p { margin: 0; color: var(--muted); line-height: 1.45; }
.hero-cards { display: inline-flex; gap: 4px; }
.hero-cards span {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 48px;
  background: var(--card-face);
  color: #1d2b25;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 1.15rem;
  box-shadow: var(--shadow-sm);
}
.hero-cards span:nth-child(1) { transform: rotate(-12deg) translateY(4px); }
.hero-cards span:nth-child(2) { transform: translateY(-2px); color: #c0392b; z-index: 1; }
.hero-cards span:nth-child(3) { transform: rotate(12deg) translateY(4px); color: #c0392b; }

.join-row { display: flex; align-items: flex-end; gap: 10px; }
.join-row .grow { flex: 1; }
.join-row .btn { padding-block: 12px; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.85rem;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.create-box { display: flex; flex-direction: column; gap: 14px; }
.home-foot { text-align: center; color: var(--muted); font-size: 0.78rem; margin-top: 4px; }

/* ===== Topbar da sala ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 64px 10px 18px;
  flex-wrap: wrap;
}
.brand { font-size: 1.3rem; display: flex; align-items: center; gap: 8px; }
.brand-name { font-weight: 800; font-size: 1rem; letter-spacing: -0.3px; }
.code-chip {
  font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  transition: border-color 0.15s, background 0.15s;
}
.code-chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.conn-banner {
  background: var(--gold);
  color: #1d2b25;
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 7px 12px;
}

/* ===== Palco ===== */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 16px 180px;
  gap: 16px;
}
.topic-row { width: min(94vw, 620px); }
#inp-topic {
  width: 100%;
  text-align: center;
  font-size: 1.18rem;
  font-weight: 600;
  background: transparent;
  border: 0;
  border-bottom: 2px dashed transparent;
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s;
}
#inp-topic:hover { border-bottom-color: var(--line); }
#inp-topic:focus { border-bottom-color: var(--accent); }
#inp-topic::placeholder { color: var(--muted); font-weight: 500; }

.arena {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 100%;
  max-width: 980px;
}
.players-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px 18px;
  min-height: 10px;
  width: 100%;
}

/* ===== Jogadores ===== */
.player { display: flex; flex-direction: column; align-items: center; gap: 7px; min-width: 84px; max-width: 150px; }
.player.offline { opacity: 0.45; }
.pname {
  display: flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  font-size: 0.85rem;
  font-weight: 600;
}
.pname .nm {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pname .nm.is-you { cursor: pointer; border-bottom: 1px dashed var(--muted); }
.pname .dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: #44c767; }
.player.offline .dot { background: var(--muted); }
.badges { font-size: 0.8rem; flex: none; }
.you-tag { color: var(--muted); font-weight: 500; font-size: 0.75rem; flex: none; }

/* Slot de carta na mesa */
.slot { width: 48px; height: 70px; perspective: 600px; }
.flip {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.25, 0.7, 0.3, 1.05);
}
.slot.flipped .flip { transform: rotateY(180deg); }
.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.05rem;
}
.face-front {
  border: 2px dashed color-mix(in srgb, var(--muted) 55%, transparent);
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 40%, transparent);
  transition: all 0.2s;
}
.slot.voted .face-front {
  border: 2px solid color-mix(in srgb, var(--accent) 70%, white);
  background:
    repeating-linear-gradient(45deg, var(--accent), var(--accent) 5px, var(--accent-hover) 5px, var(--accent-hover) 10px);
  box-shadow: var(--shadow-sm);
  animation: pop 0.25s ease;
}
.face-back {
  transform: rotateY(180deg);
  background: var(--card-face);
  color: #1d2b25;
  border: 2px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.slot.novote .face-back { color: var(--muted); background: var(--surface-2); border-style: dashed; }
.slot.spec-slot .face-front {
  border-style: solid;
  border-color: var(--line);
  background: var(--surface-2);
  font-size: 1.1rem;
}
@keyframes pop {
  0% { transform: scale(0.85); }
  60% { transform: scale(1.07); }
  100% { transform: scale(1); }
}

/* ===== Mesa ===== */
.table {
  width: min(92vw, 680px);
  min-height: 180px;
  border-radius: 28px;
  background: radial-gradient(120% 160% at 50% 0%, var(--felt1), var(--felt2));
  border: 3px solid var(--felt-line);
  box-shadow: inset 0 2px 18px rgba(0, 0, 0, 0.25), var(--shadow);
  display: grid;
  place-items: center;
  padding: 22px;
  transition: box-shadow 0.4s;
}
.table.consensus-glow {
  box-shadow: inset 0 2px 18px rgba(0, 0, 0, 0.25), 0 0 0 4px color-mix(in srgb, var(--gold) 75%, transparent), 0 0 34px color-mix(in srgb, var(--gold) 45%, transparent);
}
.table-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 13px;
  color: #fff;
  text-align: center;
  width: 100%;
}
.progress { font-size: 1.02rem; font-weight: 600; opacity: 0.95; }
.auto-hint { font-size: 0.78rem; opacity: 0.75; margin-top: -6px; }
.waiting-host { font-size: 0.9rem; opacity: 0.85; font-style: italic; }
.invite { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.invite p { margin: 0; opacity: 0.95; font-weight: 600; }
.invite .ghost-btn { border-color: rgba(255, 255, 255, 0.5); color: #fff; }
.invite .ghost-btn:hover { background: rgba(255, 255, 255, 0.12); border-color: #fff; }

.timer-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.timer-chip.urgent { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { background: color-mix(in srgb, var(--danger) 70%, transparent); } }
.timer-chip button {
  background: none;
  border: 0;
  color: #fff;
  opacity: 0.8;
  padding: 0 2px;
  font-size: 0.85rem;
}
.timer-chip button:hover { opacity: 1; }

/* Resultados */
.consensus { font-size: 1.25rem; font-weight: 800; color: var(--gold); text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4); }
.stats { display: flex; gap: 26px; align-items: flex-end; justify-content: center; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat small { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.6px; opacity: 0.8; font-weight: 700; }
.stat .stat-val { font-size: 1.7rem; font-weight: 800; line-height: 1.1; }
.stat.main .stat-val { font-size: 2.3rem; color: #ffe9a8; }
.dist { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.dist-item { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.mini-card {
  width: 34px;
  height: 48px;
  border-radius: 6px;
  background: var(--card-face);
  color: #1d2b25;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.95rem;
  border: 1.5px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.dist-count { font-size: 0.75rem; font-weight: 700; opacity: 0.9; }

/* ===== Mão (cartas do jogador) ===== */
.hand-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  z-index: 40;
}
.hand-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(96vw, 860px);
  margin: 0 auto 8px;
}
.hand-label { font-size: 0.83rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.hand-scroll { overflow-x: auto; scrollbar-width: thin; }
.hand { display: flex; gap: 10px; width: max-content; margin: 0 auto; padding: 14px 6px 4px; }

.card {
  width: 58px;
  height: 86px;
  flex: none;
  background: var(--card-face);
  color: #1d2b25;
  border: 2px solid var(--line);
  border-radius: 10px;
  font-weight: 800;
  font-size: 1.3rem;
  position: relative;
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s ease, border-color 0.16s, background 0.16s, box-shadow 0.16s;
}
.card .corner { position: absolute; top: 4px; left: 7px; font-size: 0.62rem; font-weight: 700; opacity: 0.55; }
.card .corner.br { top: auto; left: auto; bottom: 4px; right: 7px; transform: rotate(180deg); }
.card:hover { transform: translateY(-7px); border-color: var(--accent); }
.card.selected {
  background: var(--accent);
  border-color: var(--accent-hover);
  color: var(--accent-ink);
  transform: translateY(-12px);
  box-shadow: 0 10px 22px color-mix(in srgb, var(--accent) 45%, transparent);
}
.card.selected .corner { opacity: 0.8; }
.card.muted { opacity: 0.45; cursor: not-allowed; }
.card.muted:hover { transform: none; border-color: var(--line); }
.card:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 2px; }

.spect-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 8px;
  font-weight: 600;
  color: var(--muted);
}

/* ===== Painel lateral ===== */
.panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(92vw, 360px);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 80;
  transform: translateX(105%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.3, 1);
  display: flex;
  flex-direction: column;
}
.panel.open { transform: translateX(0); }
.panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 75;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 10px;
}
.panel-head h2 { margin: 0; font-size: 1.1rem; }
.panel-content { overflow-y: auto; padding: 0 18px 24px; flex: 1; }

.p-section { border-top: 1px solid var(--line); padding: 14px 0; }
.p-section:first-child { border-top: 0; }
.p-title {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
  margin: 0 0 10px;
}
.p-hint { font-size: 0.8rem; color: var(--muted); margin: 6px 0 10px; }
.copy-row { display: flex; flex-direction: column; gap: 8px; }
.apply-row { display: flex; gap: 8px; margin-top: 8px; }
.apply-row input { flex: 1; }

.p-player-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  font-size: 0.95rem;
}
.p-player-row .dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: #44c767; }
.p-player-row.offline { opacity: 0.5; }
.p-player-row.offline .dot { background: var(--muted); }
.p-player-row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; gap: 2px; }
.row-actions button {
  background: none;
  border: 0;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 0.9rem;
  opacity: 0.65;
}
.row-actions button:hover { opacity: 1; background: var(--surface-2); }
.row-actions button.danger:hover { background: color-mix(in srgb, var(--danger) 15%, transparent); }

.hist-item { border: 1px solid var(--line); border-radius: var(--r-sm); margin-bottom: 8px; overflow: hidden; }
.hist-item summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 0.9rem;
}
.hist-item summary::-webkit-details-marker { display: none; }
.hist-item summary:hover { background: var(--surface-2); }
.hist-round { font-weight: 800; color: var(--accent); flex: none; }
.hist-topic { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-topic.none { color: var(--muted); font-style: italic; }
.hist-avg { color: var(--muted); font-size: 0.82rem; flex: none; }
.hist-votes { padding: 4px 12px 10px; font-size: 0.85rem; color: var(--muted); line-height: 1.7; }

/* ===== Toasts ===== */
.toasts {
  position: fixed;
  top: 54px;
  right: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 90;
  pointer-events: none;
}
.toast {
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease;
  max-width: 320px;
}
.toast.err { background: var(--danger); color: #fff; }
.toast.fade { opacity: 0; transition: opacity 0.4s; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 100; }

/* ===== Responsivo ===== */
@media (max-width: 720px) {
  .brand-name { display: none; }
  .topbar { padding: 8px 56px 8px 12px; gap: 8px; }
  .stage { padding-bottom: 200px; }
  #inp-topic { font-size: 1.05rem; }
  .card { width: 50px; height: 76px; font-size: 1.15rem; }
  .slot { width: 42px; height: 62px; }
  .player { min-width: 70px; max-width: 120px; }
  .players-row { gap: 10px 12px; }
  .table { min-height: 150px; padding: 16px; }
  .stat .stat-val { font-size: 1.4rem; }
  .stat.main .stat-val { font-size: 1.9rem; }
  .stats { gap: 16px; }
  .toasts { top: auto; bottom: 215px; right: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
