:root {
  --bg: #fdf6ec;
  --ink: #2b2d42;
  --muted: #6c6f85;
  --card: #ffffff;
  --line: #e7dccb;
  --accent: #ff5a5f;
  --accent-ink: #ffffff;
  --error: #d62839;
  --font: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
}

.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: 6px 6px 0 var(--ink);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.card.wide { max-width: 520px; }

h1 { margin: 0; font-size: 40px; letter-spacing: 1px; }
h2 { margin: 0; font-size: 24px; }
.sub { margin: -6px 0 6px; color: var(--muted); }
.muted { color: var(--muted); margin: 0; font-size: 14px; }
.error { color: var(--error); margin: 0; min-height: 1.2em; font-size: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: bold; font-size: 14px; }
.field.inline { flex-direction: row; align-items: center; gap: 10px; flex: 1; }

input, select, button {
  font: inherit;
  font-size: 16px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
}
select { flex: 1; min-width: 0; }
input:focus, select:focus, button:focus-visible { outline: 3px solid #ffc93c; outline-offset: 1px; }

button {
  cursor: pointer;
  font-weight: bold;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform .05s, box-shadow .05s;
}
button:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; box-shadow: none; border-color: var(--line); color: var(--muted); }
button.small { padding: 6px 10px; font-size: 13px; box-shadow: 2px 2px 0 var(--ink); }

.row { display: flex; gap: 10px; }
.row input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 4px; font-weight: bold; }

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

.lobby-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.code { letter-spacing: 4px; color: var(--accent); }
.won { margin: 0; padding: 10px 12px; border-radius: 10px; background: #fff3c4; font-weight: bold; }

#playerList { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
#playerList li {
  display: flex; align-items: center; gap: 8px;
  border: 2px solid var(--line); border-radius: 10px; padding: 8px 10px;
  font-weight: bold; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
#playerList .dot { flex: none; width: 18px; height: 18px; border-radius: 5px; border: 2px solid var(--ink); }
#playerList .tag { margin-left: auto; font-size: 11px; color: var(--muted); font-weight: normal; }
#playerList li.empty { border-style: dashed; color: var(--line); justify-content: center; }

.host-controls { display: flex; gap: 10px; align-items: center; }

.mode-switch { display: flex; gap: 8px; }
.mode-switch button { flex: 1; background: #fff; box-shadow: 2px 2px 0 var(--ink); }
.mode-switch button.active { background: var(--ink); color: #fff; }
.mode-switch button:disabled { opacity: 1; cursor: default; }
.mode-switch button:disabled:not(.active) { color: var(--muted); border-color: var(--line); box-shadow: none; }

#scoreBar { margin-top: 6px; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
#scoreBar > div { display: flex; align-items: center; gap: 6px; }
#scoreBar .dot { flex: none; width: 10px; height: 10px; border-radius: 3px; border: 1.5px solid var(--ink); }
#scoreBar .name { font-weight: bold; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; }
#scoreBar .stars { color: #e9a800; letter-spacing: 1px; }

.help { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; font-size: 13px; color: var(--muted); }
kbd {
  display: inline-block; min-width: 20px; text-align: center;
  border: 1.5px solid var(--muted); border-bottom-width: 3px; border-radius: 5px;
  padding: 0 4px; font-family: inherit; font-size: 11px; color: var(--ink); background: #fff;
}

#game { padding: 0; display: block; background: #e9f5f9; }
#canvas { display: block; width: 100%; height: 100%; }

#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 12px 16px; pointer-events: none;
}
#hud button { pointer-events: auto; }
.hud-left { background: rgba(255,255,255,.85); border: 2px solid var(--ink); border-radius: 12px; padding: 8px 12px; max-width: 60%; }
#levelName { font-weight: bold; font-size: 18px; }
#levelHint { font-size: 13px; color: var(--muted); }
.hud-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.pill { background: rgba(255,255,255,.85); border: 2px solid var(--ink); border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: bold; }

.banner {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%);
  background: #fff; border: 4px solid var(--ink); border-radius: 20px; box-shadow: 6px 6px 0 var(--ink);
  padding: 18px 36px; font-size: 44px; font-weight: bold; pointer-events: none;
  animation: pop .35s ease-out;
}
@keyframes pop { from { transform: translate(-50%, -50%) scale(.6); opacity: 0; } }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); z-index: 10;
}

@media (max-width: 520px) {
  .card { padding: 20px; }
  h1 { font-size: 32px; }
  .help { grid-template-columns: 1fr; }
  .hud-left { max-width: 100%; }
  #hud { flex-direction: column; }
  .banner { font-size: 30px; padding: 14px 24px; }
}
