/* ════════════════════════════════════ Közös Legelő — mobil-first stíluslap ══ */

:root {
  color-scheme: dark;

  --bg:        #10150e;
  --bg-2:      #161d13;
  --surface:   #1c2418;
  --surface-2: #232d1e;
  --line:      #33402b;

  --text:      #eef3e8;
  --text-dim:  #a3b096;
  --text-mute: #74815f;

  --green:     #7fc45a;
  --green-ink: #16240d;
  --grass:     #4b8a2e;
  --amber:     #e8b451;
  --red:       #e5624a;
  --sky:       #6fb2d8;

  --radius:    18px;
  --radius-sm: 12px;
  --pad:       16px;

  --shadow: 0 10px 30px rgb(0 0 0 / 0.45);
  --tap: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(120% 60% at 50% 0%, #1d2717 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont,
               "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px
           calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.screen { display: flex; flex-direction: column; gap: 14px; }
[hidden] { display: none !important; }

/* ────────────────────────────────────────────────────── nyelvváltó ── */

.langbar { display: flex; justify-content: flex-end; margin-bottom: -6px; }
.lang {
  display: flex; gap: 3px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}
.lang button {
  min-width: 42px; min-height: 32px;
  font: inherit; font-size: 12px; font-weight: 800; letter-spacing: 0.06em;
  background: transparent; color: var(--text-mute);
  border: none; border-radius: 999px; cursor: pointer;
  touch-action: manipulation;
}
.lang button.on { background: var(--surface-2); color: var(--text); }

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 30px; letter-spacing: -0.02em; }

/* ─────────────────────────────────────────────────────────────── fejléc ── */

.hero { text-align: center; padding: 20px 8px 4px; }
.hero-cows { font-size: 40px; letter-spacing: 4px; margin-bottom: 6px; }
.hero-sub { color: var(--text-dim); font-size: 14.5px; margin: 8px 0 0; }

/* ────────────────────────────────────────────────────────────── kártyák ── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hint-inline { font-weight: 400; color: var(--text-mute); font-size: 13px; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.hint { color: var(--text-mute); font-size: 13.5px; margin: 0; }
.hint.warn { color: var(--amber); font-weight: 600; }

/* Tartós magyarázat a belépőképernyőn — nem tűnik el, mint a buborék. */
.notice {
  margin: 0;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: rgb(232 180 81 / 0.10);
  border: 1px solid rgb(232 180 81 / 0.45);
  border-radius: var(--radius-sm);
}
.centered { text-align: center; }

.chip-count {
  background: var(--surface-2);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 13px;
  color: var(--text);
}

/* ──────────────────────────────────────────────────── űrlapok, gombok ── */

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-mute);
}

input[type="text"] {
  width: 100%;
  min-height: var(--tap);
  padding: 0 14px;
  font: inherit;
  font-size: 17px;                 /* 16px alatt iOS ráközelít */
  color: var(--text);
  background: var(--bg-2);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
}
input[type="text"]:focus { border-color: var(--green); }
input::placeholder { color: var(--text-mute); }

.code-input {
  text-align: center;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  font-size: 26px;
  font-weight: 800;
  padding-left: 0.4em;
}

.btn {
  min-height: var(--tap);
  padding: 0 18px;
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform .06s ease, filter .15s ease, opacity .15s ease;
  touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: scale(0.975); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-lg { min-height: 56px; font-size: 17px; }
.btn-sm { min-height: 42px; font-size: 14px; }

.btn-primary { background: var(--green); color: var(--green-ink); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.btn-ghost { background: transparent; color: var(--text-dim); border-color: var(--line); }

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

.seg {
  display: flex; gap: 6px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.seg button {
  flex: 1; min-height: 42px;
  font: inherit; font-weight: 700;
  background: transparent; color: var(--text-dim);
  border: none; border-radius: 9px; cursor: pointer;
}
.seg button.on { background: var(--green); color: var(--green-ink); }
.setting { display: flex; flex-direction: column; gap: 6px; }

/* ─────────────────────────────────────────── kezdő választás ── */

.choices { display: flex; flex-direction: column; gap: 10px; }

.choice {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 76px;
  padding: 14px 16px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .06s ease, border-color .15s ease;
}
.choice:active { transform: scale(0.985); }

/* A csatlakozás a gyakoribb szándék (egy indít, többen belépnek), ezért
   ez kapja a hangsúlyt — de a másik sem "eldugott", hogy ne lehessen
   reflexből mellényúlni. */
.choice-primary {
  background: linear-gradient(180deg, rgb(127 196 90 / 0.16), rgb(127 196 90 / 0.06));
  border-color: rgb(127 196 90 / 0.55);
}
.choice-primary b { color: var(--green); }

.choice-icon { font-size: 26px; line-height: 1; flex: none; }
.choice-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.choice-body b { font-size: 16.5px; font-weight: 800; }
.choice-body small { font-size: 13px; color: var(--text-mute); }

/* ───────────────────────────────────────────────────────── szabályok ── */

.rules summary {
  cursor: pointer; font-weight: 700; font-size: 15px;
  color: var(--text-dim); list-style: none;
}
.rules summary::after { content: " ⌄"; }
.rules[open] summary::after { content: " ⌃"; }
.rules summary::-webkit-details-marker { display: none; }
.rules ol { margin: 4px 0 0; padding-left: 20px; font-size: 14.5px; color: var(--text-dim); }
.rules li { margin-bottom: 9px; }
.rules li b { color: var(--text); }
.rules-note {
  margin: 4px 0 0; font-size: 13.5px; color: var(--text-mute);
  border-left: 3px solid var(--grass); padding-left: 10px;
}

/* ──────────────────────────────────────────────────────── szobakód ── */

.code-card { align-items: center; text-align: center; }
.code-display {
  font-size: 46px; font-weight: 800; letter-spacing: 0.22em;
  color: var(--green); padding-left: 0.22em;
  font-variant-numeric: tabular-nums;
}

/* ──────────────────────────────────────────────────── játékoslista ── */

.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.player-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  min-height: 48px;
}
.player-row.is-me { border-color: var(--grass); }
.player-row.is-off { opacity: 0.45; }
.player-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-tag {
  font-size: 11px; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--amber); background: rgb(232 180 81 / 0.14);
  padding: 2px 7px; border-radius: 999px;
}
.player-score { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text-dim); }
.player-state { font-size: 18px; width: 22px; text-align: center; }

/* ───────────────────────────────────────────────────────── topbar ── */

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 2px 4px;
}
.topbar-round { display: flex; align-items: baseline; gap: 6px; }
.topbar-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-mute); }
.topbar-round b { font-size: 18px; font-variant-numeric: tabular-nums; }
.topbar-badge {
  font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--amber); background: rgb(232 180 81 / 0.14);
  border: 1px solid rgb(232 180 81 / 0.3);
  padding: 3px 8px; border-radius: 999px;
}
.topbar-code {
  margin-left: auto; font-weight: 800; letter-spacing: 0.18em;
  color: var(--text-mute); font-size: 14px;
}

/* ────────────────────────────────────────────────────────── legelő ── */

.pasture {
  position: relative;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
  background: #12170f;
  box-shadow: var(--shadow);
}
.pasture-grass {
  position: absolute; inset: 0;
  width: 100%;
  background: linear-gradient(180deg, rgb(75 138 46 / 0.55), rgb(75 138 46 / 0.15));
  transform-origin: left center;
  transition: transform .6s cubic-bezier(.22,.8,.3,1), filter .6s ease;
}
.pasture.dry .pasture-grass { filter: hue-rotate(-38deg) saturate(0.65); }
.pasture.dead .pasture-grass { filter: hue-rotate(-55deg) saturate(0.35) brightness(0.8); }

.pasture-body { position: relative; padding: var(--pad); display: flex; flex-direction: column; gap: 6px; }
.pasture-row { display: flex; align-items: baseline; justify-content: space-between; }
.pasture-label { font-weight: 700; font-size: 15px; }
.pasture-pct { font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.pasture-pct b { color: var(--text); font-size: 15px; }

.capacity { display: flex; align-items: baseline; gap: 8px; margin-top: 2px; }
.capacity-num {
  font-size: 40px; font-weight: 800; line-height: 1;
  color: var(--green); font-variant-numeric: tabular-nums;
}
.capacity-text { font-size: 14px; color: var(--text-dim); }
.capacity-hint { font-size: 13px; color: var(--text-mute); }

/* ────────────────────────────────────────────────── tehénválasztó ── */

.picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(56px, 1fr)); gap: 8px; }
.picker button {
  min-height: 58px;
  font: inherit; font-size: 21px; font-weight: 800;
  color: var(--text);
  background: var(--bg-2);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  touch-action: manipulation;
  transition: transform .06s ease;
}
.picker button:active { transform: scale(0.94); }
.picker button.on {
  background: var(--green); color: var(--green-ink);
  border-color: var(--green);
}
.picker button.risky.on { background: var(--amber); border-color: var(--amber); }

.picker-preview {
  text-align: center; font-size: 24px; letter-spacing: 2px;
  min-height: 32px; color: var(--text-dim);
}

/* ────────────────────────────────────────────────────── eredmény ── */

.verdict {
  border-radius: var(--radius);
  padding: 20px var(--pad);
  text-align: center;
  border: 1px solid var(--line);
  background: var(--surface);
  animation: pop .35s cubic-bezier(.2,.9,.3,1.2);
}
.verdict.ok { border-color: rgb(127 196 90 / 0.5); background: rgb(127 196 90 / 0.09); }
.verdict.bad { border-color: rgb(229 98 74 / 0.5); background: rgb(229 98 74 / 0.10); }
.verdict-icon { font-size: 44px; line-height: 1; }
.verdict-title { font-size: 23px; font-weight: 800; margin-top: 8px; }
.verdict.ok .verdict-title { color: var(--green); }
.verdict.bad .verdict-title { color: var(--red); }
.verdict-sub { font-size: 14px; color: var(--text-dim); margin-top: 6px; }

@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

.load-bar {
  position: relative;
  height: 30px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.load-fill {
  height: 100%;
  background: var(--grass);
  border-radius: 999px;
  transition: width .5s cubic-bezier(.22,.8,.3,1);
}
.load-fill.over { background: var(--red); }
.load-mark {
  position: absolute; top: 0; bottom: 0;
  border-left: 2px dashed rgb(238 243 232 / 0.65);
}
.load-mark span {
  position: absolute; top: 50%; left: 6px; transform: translateY(-50%);
  font-size: 10px; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--text-dim); white-space: nowrap;
}
.load-legend {
  display: flex; justify-content: space-between;
  font-size: 13px; color: var(--text-dim);
}
.load-legend b { color: var(--text); font-size: 15px; }

.result-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.result-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  align-items: center;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.result-row.is-me { border-color: var(--grass); }
.result-name { font-weight: 600; }
.result-cows { font-size: 15px; letter-spacing: 1px; grid-column: 1; color: var(--text-dim); }
.result-gain {
  grid-row: 1 / span 2; grid-column: 2;
  font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums;
  text-align: right;
}
.result-gain.plus { color: var(--green); }
.result-gain.minus { color: var(--red); }
.result-gain small { display: block; font-size: 11.5px; font-weight: 600; color: var(--text-mute); }

.grass-change {
  text-align: center; font-size: 14px; color: var(--text-dim);
  border-top: 1px solid var(--line); padding-top: 12px;
}
.grass-change b { color: var(--text); }
.grass-change .down { color: var(--red); }
.grass-change .up { color: var(--green); }

/* ────────────────────────────────────────────────────────── chat ── */

.chat-card { gap: 10px; }
.chat-log {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 6px;
  max-height: 168px; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.chat-log li { font-size: 14px; color: var(--text-dim); word-break: break-word; }
.chat-log b { color: var(--green); font-weight: 700; }
.chat-empty { color: var(--text-mute); font-style: italic; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; min-height: 46px; font-size: 16px; }

/* ─────────────────────────────────────────────────── végeredmény ── */

.rank-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; counter-reset: rank; }
.rank-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px;
}
.rank-row.first { border-color: var(--amber); background: rgb(232 180 81 / 0.09); }
.rank-pos { font-size: 20px; width: 30px; text-align: center; font-weight: 800; color: var(--text-mute); }
.rank-row.first .rank-pos { color: var(--amber); }
.rank-name { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-score { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }

.history-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.history { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
.history th, .history td { padding: 6px 8px; text-align: center; white-space: nowrap; }
.history thead th { color: var(--text-mute); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.history th:first-child, .history td:first-child { text-align: left; }
.history tbody tr { border-top: 1px solid var(--line); }
.history td.bad { color: var(--red); font-weight: 700; }
.history td.ok { color: var(--green); }

/* ──────────────────────────────────────────────── statisztika ── */

.stats { gap: 16px; }
.stat-group { display: flex; flex-direction: column; gap: 8px; }
.stat-group-title {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-mute);
}

.stat-grid {
  margin: 0;
  display: grid;
  /* Szélesebb csempe, mert a címkék most egész mondatok, nem tőszavak. */
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 10px;
}
.stat {
  /* A nagy szám kerül felülre, a címke alá — a jelentés viszont (dt, majd dd)
     helyes sorrendben marad a DOM-ban. */
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 2px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
}
.stat dd {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.05;
  color: var(--green);
  font-variant-numeric: tabular-nums;
}
.stat dt {
  font-size: 12px;
  line-height: 1.3;
  color: var(--text-dim);
  text-wrap: balance;
}

/* ───────────────────────────────────────────────── támogató ── */

.sponsor {
  text-align: center;
  font-size: 13px;
  color: var(--text-mute);
  padding: 10px 0 4px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}
.sponsor a {
  color: var(--text-dim);
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1px solid var(--line);
  padding-bottom: 1px;
}
.sponsor a:hover { color: var(--green); border-bottom-color: var(--green); }

/* ───────────────────────────────────────────── toast, kapcsolat ── */

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 460px);
  background: var(--red); color: #fff;
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 14.5px; font-weight: 600; text-align: center;
  box-shadow: var(--shadow); z-index: 40;
  animation: pop .2s ease;
}
.conn {
  position: fixed; top: env(safe-area-inset-top); left: 0; right: 0;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  background: var(--amber); color: #2a1e05;
  font-size: 13px; font-weight: 700; text-align: center;
  padding: 8px 12px; z-index: 50;
}
/* Az ébresztés hosszabb és nem hibaállapot — nyugodtabb szín jelzi. */
.conn.waking { background: var(--sky); color: #0a2333; }

.conn-spinner {
  width: 14px; height: 14px; flex: none;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

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