:root {
  --bg: #2F5BD3;
  --bg-2: #4A74E8;
  --bg-dark: #1D3C96;
  --paper: #FFFDF7;
  --cream: #F2EEE3;
  --ink: #1B1F24;
  --muted: #667085;
  --gold: #FFC933;
  --green: #2FBF71;
  --green-soft: #DDF6E8;
  --orange: #FF8A1F;
  --red: #E0433B;
  --blue: #2F5BD3;
  --display: 'Secular One', 'Assistant', 'Arial Hebrew', sans-serif;
  --body: 'Assistant', 'Segoe UI', 'Arial Hebrew', Arial, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html, body, button { touch-action: manipulation; }
body {
  background-color: var(--bg);
  background-image: radial-gradient(#ffffff1f 1.5px, transparent 1.5px);
  background-size: 22px 22px;
  color: var(--ink);
  font: 16px/1.5 var(--body);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  font-size: 16px; /* מונע זום אוטומטי באייפון */
  border: 2px solid #d8d3c4; border-radius: 10px; padding: 10px 12px; background: #fff; width: 100%; color: var(--ink);
}
textarea { resize: vertical; line-height: 1.4; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--red); min-height: 1.5em; margin: 8px 0 0; font-weight: 600; text-align: center; }
.note { font-size: .88rem; color: var(--muted); margin: 8px 0 0; }

.btn {
  border: 2px solid var(--ink); background: #fff; color: var(--ink); border-radius: 12px;
  padding: 9px 16px; font-weight: 700; cursor: pointer; line-height: 1.2;
  box-shadow: 0 3px 0 var(--ink); transition: transform .08s, box-shadow .08s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--gold); }
.btn.big { font-size: 1.1rem; padding: 12px 22px; width: 100%; }
.btn.small { font-size: .9rem; padding: 6px 12px; box-shadow: 0 2px 0 var(--ink); }
.link { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; padding: 4px; font-size: .9rem; }
.icon-btn { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.icon-btn:hover { background: #0001; color: var(--red); }
.row { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }

/* דף הבית ולובי */
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }
.card-panel {
  width: min(420px, 100%); background: var(--paper); border-radius: 20px; padding: 28px 22px;
  border: 3px solid var(--ink); box-shadow: 0 8px 0 var(--bg-dark);
}
.card-panel.wide { width: min(480px, 100%); }
.back-link {
  display: inline-block; margin: -10px 0 14px; font-size: .9rem; font-weight: 700;
  color: var(--muted); text-decoration: none;
}
.back-link:hover { color: var(--ink); text-decoration: underline; }
.logo {
  font-family: var(--display); font-weight: 400; font-size: clamp(2.6rem, 12vw, 3.6rem);
  line-height: 1; margin: 0; text-align: center; color: var(--ink);
  text-shadow: 3px 3px 0 var(--gold);
}
.tagline { text-align: center; margin: 10px 0 22px; color: var(--muted); }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 700; margin-bottom: 4px; font-size: .9rem; }
.or { display: flex; align-items: center; gap: 10px; margin: 22px 0 12px; color: var(--muted); font-size: .9rem; }
.or::before, .or::after { content: ''; flex: 1; height: 2px; background: #e4ddca; }
.join-row { display: flex; gap: 8px; }
.code-input { text-transform: uppercase; letter-spacing: .25em; font-weight: 800; text-align: center; }
.card-panel .link { display: block; margin: 10px auto 0; }
.big-code { font-family: var(--display); font-size: 2.8rem; letter-spacing: .15em; text-align: center; line-height: 1.1; margin: 0 0 12px; }
#shareBtn { display: block; margin: 0 auto; }
.section-title { font-size: 1rem; margin: 22px 0 8px; }
.lobby-players { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.lobby-players li { display: flex; align-items: center; gap: 8px; background: var(--cream); border-radius: 10px; padding: 8px 12px; }
.pname { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #b9b9b9; flex: none; display: inline-block; }
.dot.on { background: var(--green); }
.badge { font-size: .72rem; font-weight: 800; padding: 1px 8px; border-radius: 999px; background: var(--ink); color: #fff; white-space: nowrap; }
.badge.me { background: var(--blue); }
.settings { display: grid; gap: 10px; margin-top: 16px; }
.setting { display: flex; align-items: center; gap: 10px; font-size: .92rem; font-weight: 600; }
.setting > span { flex: 1; }
.setting select { width: auto; padding: 6px 10px; }
.setting.check input { width: 20px; height: 20px; flex: none; }
.setting.check span { font-weight: 400; }
.settings .field { margin: 0; }
.settings .field > span { font-weight: 600; font-size: .88rem; }

/* משחק */
.game {
  min-height: 100vh; max-width: 1200px; margin: 0 auto;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 10px calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 8px;
}
.topbar {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  background: var(--paper); border: 2px solid var(--ink); border-radius: 14px; padding: 6px 10px;
}
.timer {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  border: 3px solid var(--ink); font-family: var(--display); font-size: 1.2rem; background: #fff;
}
.timer.low { background: var(--red); color: #fff; animation: beat 1s infinite; }
@keyframes beat { 50% { transform: scale(1.08); } }
.word-box { text-align: center; min-width: 0; }
.word { display: flex; justify-content: center; align-items: flex-end; gap: 5px; flex-wrap: wrap; min-height: 32px; font-family: var(--display); font-size: 1.5rem; line-height: 1.2; }
.word .blank { width: 18px; height: 26px; border-bottom: 3px solid var(--ink); }
.word .letter { width: 18px; text-align: center; border-bottom: 3px solid var(--green); }
.word .gap { width: 12px; }
.word .known { color: var(--blue); letter-spacing: .02em; }
.word-note { font-size: .8rem; color: var(--muted); }
.top-right { display: flex; align-items: center; gap: 4px; }
.round-tag { font-weight: 800; font-size: .85rem; white-space: nowrap; }

.layout { display: grid; grid-template-columns: 200px minmax(0, 1fr) 270px; gap: 8px; align-items: start; }
.players-col, .chat-col { background: var(--paper); border: 2px solid var(--ink); border-radius: 14px; overflow: hidden; }

.players { list-style: none; margin: 0; padding: 0; }
.players li { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid #ece6d6; }
.players li:last-child { border-bottom: 0; }
.players li.me .pname { color: var(--blue); }
.players li.guessed { background: var(--green-soft); }
.players li.drawer { background: #FFF4CC; }
.rank { font-weight: 800; font-size: .85rem; color: var(--muted); width: 26px; }
.pinfo { flex: 1; min-width: 0; display: grid; }
.pscore { font-size: .82rem; color: var(--muted); }
.pen { font-size: 1.2rem; }

.canvas-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.canvas-wrap { position: relative; border: 3px solid var(--ink); border-radius: 14px; overflow: hidden; background: #fff; box-shadow: 0 5px 0 var(--bg-dark); }
canvas { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; touch-action: none; }
canvas.drawing { cursor: crosshair; }
canvas.drawing[data-tool="fill"] { cursor: cell; }
.overlay {
  position: absolute; inset: 0; background: #1b1f24cc; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 16px; text-align: center; overflow-y: auto;
}
.overlay h2 { font-family: var(--display); font-weight: 400; font-size: clamp(1.3rem, 4vw, 2rem); margin: 0; }
.overlay .reveal-word { color: var(--gold); }
.overlay .reason { margin: 0; font-weight: 700; color: #ffd98a; }
.choices { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.btn.choice { font-size: 1.2rem; padding: 12px 20px; }
.gains { list-style: none; padding: 0; margin: 0; min-width: min(280px, 100%); display: grid; gap: 4px; }
.gains li { display: flex; justify-content: space-between; gap: 16px; background: #ffffff14; padding: 4px 12px; border-radius: 8px; }
.gains .plus { color: #7CF0AE; }
.gains .zero { color: #ffffff77; }
.podium li:first-child { background: #ffc93333; font-size: 1.15rem; }

.tools { background: var(--paper); border: 2px solid var(--ink); border-radius: 14px; padding: 8px; display: grid; gap: 8px; }
.colors { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; }
.swatch { aspect-ratio: 1; border-radius: 6px; border: 2px solid #0003; cursor: pointer; padding: 0; min-width: 0; }
.swatch.on { border-color: var(--ink); box-shadow: 0 0 0 2px var(--gold); transform: scale(1.1); }
.tool-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center; }
.sizes { display: flex; gap: 4px; margin-inline-end: 8px; }
.size, .tool {
  width: 40px; height: 40px; border-radius: 10px; border: 2px solid #d8d3c4; background: #fff;
  display: grid; place-items: center; cursor: pointer; padding: 0; font-size: 1.15rem;
}
.size span { display: block; border-radius: 50%; }
.size.on, .tool.on { border-color: var(--ink); background: #FFF4CC; }

.chat-col { display: flex; flex-direction: column; height: 100%; min-height: 300px; max-height: calc(100vh - 110px); }
.log { list-style: none; margin: 0; padding: 8px 10px; flex: 1; overflow-y: auto; font-size: .92rem; display: grid; gap: 2px; align-content: start; }
.log li { overflow-wrap: anywhere; }
.log-sys, .log-turn { color: var(--muted); font-size: .85rem; }
.log-turn { color: var(--blue); font-weight: 700; }
.log-good { color: #138a4b; font-weight: 800; background: var(--green-soft); border-radius: 6px; padding: 0 6px; }
.log-close { color: var(--orange); font-weight: 700; }
.log-secret { color: #138a4b; font-style: italic; }
.log-word { font-weight: 800; }
.chat { display: flex; gap: 6px; padding: 8px; border-top: 2px solid #ece6d6; }
.chat input { padding: 7px 10px; }
.chat input.guess { border-color: var(--blue); background: #F2F6FF; }

.conn { position: fixed; top: 0; inset-inline: 0; z-index: 90; text-align: center; background: var(--red); color: #fff; font-weight: 700; padding: 6px; }
.modal { position: fixed; inset: 0; z-index: 80; background: #0009; display: grid; place-items: center; padding: 16px; }
.modal-box {
  position: relative; background: var(--paper); border: 3px solid var(--ink); border-radius: 18px;
  padding: 22px 18px 18px; width: min(540px, 100%); max-height: 88vh; overflow-y: auto; box-shadow: 0 8px 0 var(--bg-dark);
}
.modal-box h2 { margin-top: 0; }
.modal-box ol { padding-inline-start: 20px; }
.modal-x { position: absolute; top: 8px; left: 10px; background: none; border: 0; font-size: 1.2rem; cursor: pointer; color: var(--muted); }
.toast {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%);
  z-index: 95; background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px;
  font-weight: 600; max-width: min(90vw, 460px); text-align: center; box-shadow: 0 6px 20px #0006;
}

/* טאבלט: הצ'אט יורד מתחת */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 180px minmax(0, 1fr); }
  .chat-col { grid-column: 1 / -1; max-height: 260px; min-height: 200px; }
}
/* טלפון: קנבס למעלה, שחקנים בשורה, צ'אט מתחת */
@media (max-width: 700px) {
  .game { padding-inline: 6px; gap: 6px; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .canvas-col { order: 1; }
  .players-col { order: 2; overflow-x: auto; }
  .chat-col { order: 3; max-height: 240px; }
  .players { display: flex; }
  .players li { flex: none; border-bottom: 0; border-inline-end: 1px solid #ece6d6; padding: 5px 8px; gap: 5px; }
  .rank { width: auto; font-size: .75rem; }
  .players .pname { font-size: .85rem; max-width: 90px; }
  .players .icon-btn { display: none; }
  .topbar { padding: 4px 8px; gap: 6px; }
  .timer { width: 38px; height: 38px; font-size: 1rem; }
  .word { font-size: 1.2rem; gap: 3px; }
  .word .blank, .word .letter { width: 14px; }
  .top-right .link { font-size: .8rem; padding: 2px; }
  .round-tag { font-size: .75rem; }
  .colors { grid-template-columns: repeat(7, 1fr); }
  .size, .tool { width: 36px; height: 36px; }
}
@media (prefers-reduced-motion: reduce) { .timer.low { animation: none; } .btn { transition: none; } }
