/* 5x5 — sopstveni stil, prvo telefon; svetla i tamna tema po prefers-color-scheme. */

:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #1f2328;
  --muted: #6b6f76;
  --line: #d9d4c7;
  --accent: #2f6fdf;
  --accent-text: #ffffff;
  --accept: #17803f;    /* beo tekst na njemu: kontrast >= 4.5:1 */
  --danger: #c93a3a;
  --on-strong: #ffffff; /* tekst na --accept i --danger */
  --word: #ffe08a;      /* polje u bodovanoj reči */
  --word2: #ffb547;     /* polje u reči i po redu i po koloni */
  --focus: #9cc2ff;
  --first: #2f6fdf;
  --select: #2f6fdf;
  --notice: #eaf1fd;
  --ok: #e3f5ea;
  --err: #fbe7e7;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  --radius: 10px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1d22;
    --surface: #262930;
    --surface-2: #30343c;
    --text: #e8e9ec;
    --muted: #9aa0aa;
    --line: #3d424c;
    --accent: #5b8ff0;
    --accent-text: #0e1420;
    --accept: #3cc47a;
    --danger: #ef6b6b;
    --on-strong: #10141c; /* svetle boje u tamnoj temi: beo tekst bi imao kontrast 2–3:1 */
    --word: #6d5a1e;
    --word2: #a5641a;
    --focus: #2c4f8f;
    --first: #7fa9f5;
    --select: #7fa9f5;
    --notice: #233149;
    --ok: #1f3a2a;
    --err: #4a2626;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[x-cloak] { display: none !important; }
a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.25rem; margin: .2rem 0 .4rem; }
h3 { font-size: 1.05rem; margin: 1.2rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }

.shell { max-width: 560px; margin: 0 auto; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); min-height: 100vh; }
main { padding-bottom: 2rem; }

/* zaglavlje */
.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; }
.logo { font-weight: 800; font-size: 1.5rem; text-decoration: none; color: var(--text); letter-spacing: .02em; }
.logo span { color: var(--accent); }
.top-right { display: flex; align-items: center; gap: 10px; }
.bell { position: relative; color: var(--text); display: inline-flex; padding: 6px; }
.badge {
  background: var(--danger); color: var(--on-strong); border-radius: 999px; font-size: .7rem; font-weight: 700;
  min-width: 18px; height: 18px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center;
}
.bell .badge { position: absolute; top: 0; right: -2px; }
.badge.inline { margin-left: 6px; }
.pill { background: var(--accent); color: var(--accent-text); border-radius: 999px; padding: 4px 12px; font-size: .85rem; text-decoration: none; font-weight: 600; }

.banner { border-radius: var(--radius); padding: 6px 12px; margin-bottom: 10px; font-size: .85rem; text-align: center; }
.banner.mock { background: var(--surface-2); color: var(--muted); }
.banner.offline { background: var(--err); }
.loading { text-align: center; color: var(--muted); padding: 2rem 0; }

/* dugmad i polja */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: var(--radius); padding: 10px 16px; font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; min-height: 44px; box-shadow: var(--shadow);
}
.btn:disabled { opacity: .45; cursor: default; box-shadow: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--on-strong); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.ghost.danger { color: var(--danger); background: transparent; border-color: var(--line); }
.btn.big { width: 100%; padding: 14px 16px; font-size: 1.05rem; margin: 6px 0; }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: .9rem; }
.btn.google { background: var(--surface); }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 10px 0; }
.row .btn { flex: 1 1 0; }

.field { display: block; margin: 10px 0; }
.field > span { display: block; font-weight: 600; margin-bottom: 4px; font-size: .95rem; }
.field small { display: block; color: var(--muted); margin-top: 4px; font-size: .8rem; }
input[type=text], input[type=email], input[type=password], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; min-height: 44px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
textarea { resize: vertical; }
.form-error { color: var(--danger); font-weight: 600; margin: 6px 0; }
.links { text-align: center; margin: 10px 0; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); margin: 10px 0; font-size: .9rem; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

.notice { background: var(--notice); border-radius: var(--radius); padding: 10px 12px; margin: 10px 0; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.notice.ok { background: var(--ok); }
.notice.err { background: var(--err); }
.invite-notice { flex-direction: column; align-items: flex-start; gap: 2px; }
.tag { display: inline-block; font-size: .75rem; border-radius: 999px; padding: 1px 8px; background: var(--surface-2); color: var(--muted); font-weight: 600; vertical-align: middle; }
.tag.win { background: var(--ok); color: var(--accept); }
.tag.loss { background: var(--err); color: var(--danger); }

/* početni */
.hello { font-size: 1.1rem; margin: 4px 0 10px; }
.friend { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin: 10px 0; box-shadow: var(--shadow); }
.friend summary { padding: 14px 16px; font-weight: 600; cursor: pointer; list-style: none; text-align: center; }
.friend summary::-webkit-details-marker { display: none; }
.friend-body { padding: 0 12px 12px; display: grid; gap: 10px; }
.code-row { display: flex; gap: 8px; }
.code-input { text-transform: uppercase; letter-spacing: .25em; font-weight: 700; text-align: center; }
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.menu a {
  display: flex; align-items: center; justify-content: center; text-align: center; min-height: 48px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); text-decoration: none; font-weight: 600; padding: 8px;
}

/* čekanje */
.waiting .center { text-align: center; padding-top: 12px; }
.invite-code { font-size: 2.6rem; font-weight: 800; letter-spacing: .2em; margin: 10px 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.invite-link { text-align: center; font-size: .85rem; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; margin: 16px auto; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* partija */
.play-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.timer {
  font-size: 1.8rem; font-weight: 800; min-width: 56px; height: 56px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; background: var(--surface); border: 3px solid var(--accent);
  font-variant-numeric: tabular-nums;
}
.timer.low { border-color: var(--danger); color: var(--danger); }
.status-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 64px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 14px; margin-bottom: 8px;
}
.status-bar.mine { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.status-text { font-weight: 700; font-size: 1.05rem; }
.current-letter {
  font-size: 2.2rem; font-weight: 800; width: 52px; height: 52px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; background: var(--accent); color: var(--accent-text);
}
.opp-placed { font-size: .85rem; text-align: right; margin-bottom: 6px; color: var(--muted); }
.opp-placed.yes { color: var(--accept); font-weight: 600; }
.opp-placed.yes::before { content: "✓ "; }

.board { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; margin: 0 auto; max-width: 400px; }
.cell {
  aspect-ratio: 1; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 8px; font: inherit; font-size: clamp(1.4rem, 7vw, 2rem); font-weight: 800; padding: 0;
  display: flex; align-items: center; justify-content: center; position: relative;
}
.cell:disabled { opacity: 1; cursor: default; }
.board.placing .cell.empty:not(:disabled) { cursor: pointer; background: var(--surface-2); border-style: dashed; }
.cell.selected { outline: 3px solid var(--select); outline-offset: -3px; background: var(--notice) !important; }
.cell.ghost { color: var(--muted); }
.cell.first::after, .rgrid .cell.first::after {
  content: ""; position: absolute; top: 4px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: var(--first);
}
.place-btn { margin-top: 10px; }
.hint { text-align: center; margin: 6px 0 0; }

.keyboard { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; margin: 14px 0 8px; }
.key {
  font: inherit; font-weight: 700; font-size: clamp(.95rem, 4.2vw, 1.2rem); padding: 0; height: 46px;
  border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.keyboard.active .key { background: var(--accent); color: var(--accent-text); border-color: var(--accent); cursor: pointer; }
.keyboard.active .key:active { transform: scale(.94); }
.key:disabled { opacity: .5; }
.keyboard.active .key:disabled { opacity: .7; }
.first-note { text-align: center; }
.play > .btn.ghost.danger { display: block; margin: 12px auto 0; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal-box { background: var(--surface); border-radius: 14px; padding: 18px; max-width: 360px; width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,.3); }

/* rezultat (§12.4) */
.result-head { text-align: center; margin-bottom: 8px; }
.result-head.w-me h2 { color: var(--accept); }
.final-score { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.small-h { font-size: 1rem; color: var(--muted); }
.boards { display: grid; gap: 16px; }
.rboard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.rname { font-weight: 700; margin-bottom: 6px; overflow-wrap: anywhere; }
.rgrid { display: grid; gap: 3px; }
.rgrid.with-pts { grid-template-columns: repeat(5, 1fr) .85fr; }
.rgrid.no-pts { grid-template-columns: repeat(5, 1fr); }
.rgrid > div { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; border-radius: 6px; position: relative; }
.rgrid .cell { border: 1px solid var(--line); font-size: clamp(1.1rem, 5.5vw, 1.6rem); font-weight: 800; background: var(--surface); }
.rgrid .cell.w1 { background: var(--word); }
.rgrid .cell.w2 { background: var(--word2); box-shadow: inset 0 0 0 2px rgba(0,0,0,.18); }
.rgrid .cell.focus { outline: 3px solid var(--accent); outline-offset: -3px; }
.rgrid .pt {
  font-weight: 700; color: var(--muted); cursor: pointer; font-variant-numeric: tabular-nums;
  border: 1px dashed transparent; user-select: none;
}
.rgrid .pt.shown { color: var(--accent); border-color: var(--accent); }
.rgrid .pt.pick { border: 1px solid var(--line); background: var(--surface-2); color: var(--text); }
.rgrid .pt.sel { background: var(--danger); color: var(--on-strong); border-color: var(--danger); }
.rgrid .pt.appealed::after { content: "!"; position: absolute; top: 0; right: 2px; font-size: .7rem; color: var(--danger); font-weight: 800; }
.rgrid .total { font-weight: 800; font-size: 1.25rem; background: var(--surface-2); color: var(--text); }
.shown-word { min-height: 1.5em; text-align: center; font-weight: 600; margin-top: 6px; font-size: .95rem; }
.legend-first { text-align: center; margin: 6px 0; }
.result-actions { display: grid; gap: 8px; margin: 14px 0 6px; }
.result-actions .btn { width: 100%; }
.btn.rematch.accept { background: var(--accept); border-color: var(--accept); color: var(--on-strong); }
.btn.rematch.sent { border-style: dashed; opacity: .8; }
.appeal-form { background: var(--surface); border: 2px solid var(--danger); border-radius: var(--radius); padding: 12px; margin-top: 14px; }
.appeal-form h3 { margin-top: 0; }
.appeals { margin-top: 10px; }
.appeal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; }
.appeal ul { margin: 6px 0; padding-left: 20px; }
.appeal .comment { margin: 6px 0; overflow-wrap: anywhere; border-left: 3px solid var(--line); padding-left: 8px; }
.appeal.st-accepted .tag { background: var(--ok); color: var(--accept); }
.appeal.st-rejected .tag { background: var(--err); color: var(--danger); }
.appeal-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; flex-wrap: wrap; }

/* liste */
.list { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 6px; }
.list-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); text-decoration: none;
}
.li-main { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.li-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex-shrink: 0; }
.score { font-weight: 800; font-variant-numeric: tabular-nums; }
.notif.unread { border-left: 4px solid var(--accent); font-weight: 600; }
.pager { display: flex; justify-content: space-between; align-items: center; margin: 12px 0; }
.table-wrap { overflow-x: auto; }
table.lb { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
table.lb th, table.lb td { padding: 7px 5px; text-align: right; border-bottom: 1px solid var(--line); }
table.lb th:nth-child(2), table.lb td.name { text-align: left; overflow-wrap: anywhere; }
table.lb tr.me td { background: var(--notice); font-weight: 700; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.stats div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.stats dt { color: var(--muted); font-size: .8rem; }
.stats dd { margin: 0; font-size: 1.4rem; font-weight: 800; }
.profile-name { font-size: 1.2rem; }

/* pravila */
.rules table { border-collapse: collapse; margin: 8px 0; font-size: .9rem; }
.rules th, .rules td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.rules-board { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; line-height: 1.2; background: var(--surface); padding: 10px; border-radius: var(--radius); overflow-x: auto; }
.rules li { margin: 4px 0; }

/* poruke */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 60; padding: 0 16px; }
.toast { pointer-events: auto; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius); max-width: 520px; box-shadow: 0 4px 16px rgba(0,0,0,.2); font-size: .95rem; }
.toast.error { background: var(--danger); color: var(--on-strong); }

.dead-tab { max-width: 420px; margin: 20vh auto 0; padding: 0 16px; text-align: center; }

/* širi ekran: table rezultata jedna pored druge */
@media (min-width: 760px) {
  .shell { max-width: 900px; }
  .screen:not(.result) { max-width: 520px; margin: 0 auto; }
  .boards { grid-template-columns: 1fr 1fr; }
  .result-actions { grid-template-columns: repeat(3, 1fr); max-width: 680px; margin-left: auto; margin-right: auto; }
  .appeal-form, .appeals { max-width: 680px; margin-left: auto; margin-right: auto; }
}
