:root {
  --bg: #1F5130;
  --bg-dark: #143820;
  --paper: #FFFDF7;
  --cream: #F2EEE3;
  --ink: #1B1F24;
  --muted: #667085;
  --gold: #FFC933;
  --red: #E5484D;
  --blue: #3E7BFA;
  --green: #2FBF71;
  --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: var(--bg) repeating-linear-gradient(90deg, #ffffff06 0 60px, transparent 60px 120px);
  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 { font: inherit; color: inherit; }
input, select {
  font-size: 16px; border: 2px solid #d8d3c4; border-radius: 10px; padding: 10px 12px; background: #fff; width: 100%; color: var(--ink);
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.error { color: var(--red); min-height: 1.5em; margin: 8px 0 0; font-weight: 600; text-align: center; }
.note { font-size: .9rem; color: var(--muted); margin: 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: .88rem; padding: 5px 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; }

/* דף הבית */
.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);
}
.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.8rem, 13vw, 3.8rem);
  line-height: 1; margin: 0; text-align: center; 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; }

/* חדר */
.room-screen { min-height: 100vh; padding: 16px 12px; display: grid; place-items: start center; }
.room-panel {
  width: min(860px, 100%); background: var(--paper); border: 3px solid var(--ink); border-radius: 20px;
  padding: 16px; box-shadow: 0 8px 0 var(--bg-dark); display: grid; gap: 14px;
}
.room-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.room-code { font-family: var(--display); font-size: 1.6rem; letter-spacing: .15em; margin-inline-start: 6px; }
.result-banner {
  display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
  border-radius: 14px; padding: 10px; background: var(--cream); font-size: 1.1rem;
}
.result-banner.red { background: #FDE2E3; }
.result-banner.blue { background: #E1EAFF; }
.result-banner small { width: 100%; text-align: center; color: var(--muted); }
.final { font-family: var(--display); font-size: 1.6rem; }
.final i { font-style: normal; }
.final .red { color: var(--red); } .final .blue { color: var(--blue); }

.teams { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.team { border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 180px; }
.team.red { background: #FDE2E3; }
.team.blue { background: #E1EAFF; }
.team.spec { background: var(--cream); }
.team h2 { margin: 0; font-size: 1rem; text-align: center; }
.team.red h2 { color: var(--red); } .team.blue h2 { color: var(--blue); }
.team ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; flex: 1; align-content: start; }
.team li { display: flex; align-items: center; gap: 6px; background: #ffffffb0; border-radius: 8px; padding: 4px 8px; font-size: .92rem; }
.team li.me { outline: 2px solid var(--ink); }
.team li.empty { background: none; justify-content: center; color: var(--muted); }
.team .join { align-self: center; }
.pname { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #b9b9b9; flex: none; }
.dot.on { background: var(--green); }
.badge { font-size: .68rem; font-weight: 800; padding: 0 7px; border-radius: 999px; background: var(--ink); color: #fff; white-space: nowrap; }
.goals { font-size: .8rem; }
.move { display: flex; gap: 3px; }
.mv { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--ink); padding: 0; cursor: pointer; font-size: .6rem; line-height: 1; }
.mv.red { background: var(--red); } .mv.blue { background: var(--blue); } .mv.spec { background: #ddd; }
.mv.x { background: #fff; color: var(--red); }
.host-bar { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.host-bar label { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: .92rem; }
.host-bar select { width: auto; padding: 6px 8px; }
.room-chat .chat-box { position: static; width: 100%; opacity: 1; background: var(--cream); color: var(--ink); }
.room-chat .log { max-height: 160px; min-height: 80px; }
.room-chat .log b.red { color: var(--red); } .room-chat .log b.blue { color: var(--blue); }

/* משחק */
.game { position: fixed; inset: 0; background: #5A8546; overflow: hidden; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.scoreboard {
  position: absolute; top: calc(8px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: 2px; direction: ltr;
  background: #1b1f24e6; border-radius: 12px; padding: 3px; color: #fff; font-family: var(--display);
}
.sc { min-width: 40px; text-align: center; font-size: 1.4rem; border-radius: 9px; padding: 0 8px; }
.sc.red { background: var(--red); } .sc.blue { background: var(--blue); }
.clock { min-width: 70px; text-align: center; font-size: 1.15rem; }
.clock.ot { color: var(--gold); }
.corner-btn {
  position: absolute; top: calc(8px + env(safe-area-inset-top, 0px)); right: 10px; z-index: 5;
  width: 40px; height: 40px; border-radius: 10px; border: 2px solid var(--ink); background: #fff; cursor: pointer; font-size: 1.2rem;
}
.goal-banner {
  position: absolute; top: 30%; left: 50%; transform: translate(-50%, -50%); z-index: 6; pointer-events: none;
  display: grid; justify-items: center; color: #fff; text-align: center; animation: pop .35s ease-out;
}
.goal-banner b { font-family: var(--display); font-weight: 400; font-size: clamp(3rem, 12vw, 6rem); line-height: 1; text-shadow: 0 4px 0 #0006; }
.goal-banner.red b { color: #FFD6D7; } .goal-banner.blue b { color: #D6E4FF; }
.goal-banner span { background: #1b1f24cc; padding: 2px 12px; border-radius: 8px; font-weight: 700; margin-top: 4px; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.4); opacity: 0; } }
.kickoff-note {
  position: absolute; top: calc(56px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); z-index: 5;
  background: #1b1f24b0; color: #fff; border-radius: 8px; padding: 1px 10px; font-size: .85rem; font-weight: 700; pointer-events: none;
}

/* צ'אט צף במשחק */
.game-chat { position: absolute; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); right: 10px; z-index: 5; width: min(340px, 60vw); }
.chat-box { background: #1b1f24b8; color: #fff; border-radius: 12px; overflow: hidden; opacity: .55; transition: opacity .3s; }
.chat-box.fresh, .chat-box:focus-within, .chat-box:hover { opacity: 1; }
.log { list-style: none; margin: 0; padding: 6px 10px; max-height: 120px; overflow-y: auto; font-size: .88rem; display: grid; gap: 1px; }
.log li { overflow-wrap: anywhere; }
.log b.red { color: #FF9EA1; } .log b.blue { color: #9DBBFF; }
.log-sys { opacity: .75; font-size: .82rem; }
.log-goal { font-weight: 800; color: var(--gold); }
.room-chat .log-goal { color: #9a6b00; }
.chat { padding: 6px; }
.chat input { padding: 5px 10px; font-size: 16px; background: #ffffffee; border-width: 1px; }

/* שליטה במגע */
.touch { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.stick-zone { position: absolute; left: 0; top: 0; bottom: 0; width: 55%; pointer-events: auto; touch-action: none; }
.stick-base {
  position: absolute; left: 90px; top: 75%; width: 110px; height: 110px; margin: -55px 0 0 -55px;
  border-radius: 50%; background: #ffffff26; border: 2px solid #ffffff66; opacity: .5;
}
.stick-base.on { opacity: 1; }
.stick-knob { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; margin: -25px 0 0 -25px; border-radius: 50%; background: #ffffffcc; }
.kick-btn {
  position: absolute; right: 24px; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); pointer-events: auto; touch-action: none;
  width: 86px; height: 86px; border-radius: 50%; border: 3px solid #fff; background: #ffffff33; font-size: 2.2rem; cursor: pointer;
}
.kick-btn.on { background: #ffffffaa; transform: scale(.94); }
.rotate-hint { display: none; }
@media (hover: none) and (pointer: coarse) and (orientation: portrait) {
  .rotate-hint {
    display: block; position: absolute; left: 50%; top: 22%; transform: translateX(-50%); z-index: 3;
    background: #1b1f24cc; color: #fff; padding: 6px 14px; border-radius: 10px; font-weight: 700; white-space: nowrap; pointer-events: none;
  }
}
/* בטלפון הצ'אט עובר למעלה, כדי לפנות את הפינות לשליטה */
@media (hover: none) and (pointer: coarse) {
  .game-chat { bottom: auto; top: calc(56px + env(safe-area-inset-top, 0px)); right: 8px; width: min(260px, 45vw); }
  .game-chat .log { max-height: 70px; font-size: .8rem; }
  .kickoff-note { top: auto; bottom: calc(120px + env(safe-area-inset-bottom, 0px)); }
}

.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(520px, 100%); max-height: 88vh; overflow-y: auto; }
.modal-box h2 { margin-top: 0; }
.modal-box ul { 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: 640px) {
  .teams { grid-template-columns: 1fr 1fr; }
  .team.spec { grid-column: 1 / -1; order: 3; min-height: 0; }
  .team { min-height: 140px; }
}
@media (prefers-reduced-motion: reduce) { .goal-banner { animation: none; } .btn { transition: none; } }
