:root {
  --bg: #0d131e;
  --bg2: #121a28;
  --panel: #182234;
  --panel2: #1f2b40;
  --line: #2a3a55;
  --text: #e9eef6;
  --muted: #8c9ab0;
  --hit: #3ccf8e;
  --hit-ink: #06281a;
  --near: #f0b43c;
  --near-ink: #2b1d02;
  --miss: #222e44;
  --miss-ink: #b9c4d6;
  --arrow: #7cc4ff;
  --danger: #ff7b7b;
  --radius: 12px;
  --namecol: 190px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 50% -200px, #1a2840 0%, transparent 70%),
    repeating-linear-gradient(0deg, transparent 0 39px, rgba(124,196,255,.035) 39px 40px),
    repeating-linear-gradient(90deg, transparent 0 39px, rgba(124,196,255,.035) 39px 40px),
    var(--bg);
  color: var(--text);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button { font: inherit; color: inherit; cursor: pointer; }
.flag { font-family: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif; }

/* ---------- header ---------- */
.top {
  max-width: 760px; margin: 0 auto; padding: 18px 16px 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.mark { width: 36px; height: 36px; flex: none; }
.mark path { fill: var(--hit); }
.mark .cut { fill: none; stroke: var(--bg); stroke-width: 2; stroke-linecap: round; }
.mark .ground { fill: none; stroke: var(--near); stroke-width: 2.5; stroke-linecap: round; }
h1 { margin: 0; font-size: 22px; letter-spacing: .14em; text-transform: uppercase; font-weight: 800; line-height: 1.1; }
#sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
nav { display: flex; gap: 6px; align-items: center; }
.pill {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 7px 13px; font-size: 13px; font-weight: 600;
}
.pill:hover, .round:hover { background: var(--panel2); }
.round {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); font-weight: 700; display: grid; place-items: center; padding: 0;
}
.link { background: none; border: 0; padding: 0; color: var(--arrow); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.link.danger { color: var(--danger); }

/* ---------- main ---------- */
main { max-width: 760px; margin: 0 auto; padding: 4px 16px 60px; }
.who { color: var(--muted); font-size: 13px; margin: 2px 0 10px; min-height: 19px; }
.who b { color: var(--text); }

.search { position: relative; }
#q {
  width: 100%; font-size: 17px; padding: 14px 16px 14px 44px;
  border-radius: var(--radius); border: 1px solid var(--line); outline: none;
  background: var(--bg2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238c9ab0' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M3 12h18M12 3c3 3.2 3 14.8 0 18M12 3c-3 3.2-3 14.8 0 18'/%3E%3C/svg%3E") no-repeat 14px 50% / 20px;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
#q:focus { border-color: var(--arrow); box-shadow: 0 0 0 3px rgba(124,196,255,.18); }
#q:disabled { opacity: .5; }
#sugg {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 6px);
  list-style: none; margin: 0; padding: 6px; max-height: 320px; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 18px 40px rgba(0,0,0,.45);
}
#sugg li { padding: 9px 10px; border-radius: 8px; display: flex; gap: 10px; align-items: center; cursor: pointer; }
#sugg li.on, #sugg li:hover { background: var(--panel2); }
#sugg .flag { font-size: 20px; width: 26px; text-align: center; }
#sugg .alt { color: var(--muted); font-size: 12px; margin-left: auto; }

.bar { display: flex; justify-content: space-between; align-items: center; margin: 10px 2px 14px; min-height: 20px; color: var(--muted); font-size: 13px; }

/* ---------- rows ---------- */
.heads, .row { display: grid; grid-template-columns: var(--namecol) 1fr; gap: 10px; align-items: center; }
.cells { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.heads {
  position: sticky; top: 0; z-index: 5; padding: 8px 0 6px;
  background: linear-gradient(var(--bg) 70%, transparent);
  color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
}
.heads .cells div { text-align: center; line-height: 1.15; hyphens: manual; }
#rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.row { background: rgba(24,34,52,.6); border: 1px solid var(--line); border-radius: 14px; padding: 8px; }
.row.won { border-color: var(--hit); box-shadow: 0 0 0 1px var(--hit) inset; }
.name { display: flex; align-items: center; gap: 8px; min-width: 0; padding-left: 2px; }
.name .flag { font-size: 24px; line-height: 1; }
.name .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name .no { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.cell {
  height: 52px; border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; font-weight: 700; font-size: 13px; line-height: 1.1; padding: 0 2px;
  font-variant-numeric: tabular-nums; position: relative;
}
.cell .arr { font-size: 12px; color: var(--arrow); margin-top: 3px; }
.s-hit { background: var(--hit); color: var(--hit-ink); }
.s-near { background: var(--near); color: var(--near-ink); }
.s-miss, .s-up, .s-down { background: var(--miss); color: var(--miss-ink); }
.s-up, .s-down { box-shadow: inset 0 0 0 1px rgba(124,196,255,.25); }

.row.fresh .cell { animation: flip .42s cubic-bezier(.2,.8,.3,1.2) both; animation-delay: calc(var(--i) * 85ms); }
.row.fresh .name { animation: rise .3s ease both; }
@keyframes flip { from { transform: perspective(300px) rotateX(-90deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rise { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .row.fresh .cell, .row.fresh .name { animation: none; } }

#empty { text-align: center; color: var(--muted); font-size: 14px; margin: 26px 0; }

/* ---------- end panel ---------- */
#end {
  border-radius: 16px; padding: 18px; margin: 0 0 16px; text-align: center;
  background: linear-gradient(135deg, rgba(60,207,142,.18), rgba(124,196,255,.10));
  border: 1px solid rgba(60,207,142,.5);
}
#end.lost { background: linear-gradient(135deg, rgba(255,123,123,.14), rgba(240,180,60,.08)); border-color: rgba(255,123,123,.45); }
#end .big { font-size: 20px; font-weight: 800; }
#end .ans { font-size: 17px; margin-top: 6px; display: flex; gap: 8px; justify-content: center; align-items: center; }
#end .ans .flag { font-size: 30px; }
#end .next { color: var(--muted); font-size: 13px; margin-top: 8px; }
.btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.primary, .ghost {
  border-radius: 10px; padding: 10px 16px; font-weight: 700; font-size: 14px; border: 1px solid var(--line);
}
.primary { background: var(--hit); color: var(--hit-ink); border-color: var(--hit); }
.ghost { background: var(--panel); }

/* ---------- dialogs ---------- */
dialog {
  width: min(480px, calc(100vw - 24px)); max-height: calc(100vh - 40px);
  background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 18px;
  padding: 20px; box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
dialog::backdrop { background: rgba(5,8,14,.7); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 8px; font-size: 19px; }
dialog h3 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
dialog p { margin: 8px 0; }
.fine { color: var(--muted); font-size: 12.5px; }
.legend { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 10px; }
.legend li { display: grid; grid-template-columns: 74px 1fr; gap: 10px; align-items: center; font-size: 14px; }
.chip { display: inline-flex; gap: 4px; align-items: center; justify-content: center; height: 34px; border-radius: 8px; font-weight: 700; font-size: 13px; }
.chip i { font-style: normal; color: var(--arrow); font-size: 11px; }
dialog .primary { width: 100%; margin-top: 8px; }
#name-in { width: 100%; font-size: 17px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); margin-top: 6px; }
#name-form .btns { justify-content: stretch; }
#name-form .btns button { flex: 1; margin: 0; }

.board-head { display: grid; grid-template-columns: 34px 1fr 34px 34px; gap: 8px; align-items: center; text-align: center; }
.board-head h2 { margin: 0; }
.board-head p { margin: 0; color: var(--muted); font-size: 12.5px; }
.board-head .close { margin-left: 6px; }
.round:disabled { opacity: .3; cursor: default; }
.res { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; }
.res li { display: grid; grid-template-columns: 26px 1fr auto; gap: 4px 10px; align-items: start; background: var(--panel); border-radius: 12px; padding: 10px 12px; }
.res .rk { font-weight: 800; color: var(--muted); }
.res .pl { font-weight: 700; overflow-wrap: anywhere; }
.res .sc { font-weight: 700; color: var(--hit); white-space: nowrap; }
.res .sc.gave { color: var(--danger); }
.res pre { grid-column: 2 / 4; margin: 2px 0 0; font: 11px/1.15 "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif; max-height: 96px; overflow: auto; white-space: pre; }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th { text-align: left; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; padding: 6px 6px; border-bottom: 1px solid var(--line); }
td { padding: 8px 6px; border-bottom: 1px solid rgba(42,58,85,.5); }
td:first-child { font-weight: 700; overflow-wrap: anywhere; }
th:not(:first-child), td:not(:first-child) { text-align: right; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); z-index: 50; max-width: calc(100vw - 32px); text-align: center;
}

/* ---------- phones ---------- */
@media (max-width: 600px) {
  .top { padding: 14px 12px 6px; }
  main { padding: 4px 12px 50px; }
  h1 { font-size: 19px; }
  .pill { padding: 6px 10px; font-size: 12.5px; }
  .heads, .row { grid-template-columns: 1fr; gap: 6px; }
  .heads .name { display: none; }
  .heads { font-size: 9.5px; letter-spacing: .03em; }
  .cells { gap: 4px; }
  .cell { height: 48px; font-size: 11.5px; border-radius: 8px; }
  .cell .arr { font-size: 10px; margin-top: 2px; }
  .name .flag { font-size: 20px; }
  .row { padding: 7px; }
}
@media (max-width: 360px) {
  .cell { font-size: 10.5px; }
  .brand .mark { display: none; }
}
