/* ======================================================================
   Шляпа PWA — стили. Тёплая «пергаментная» айдентика оригинала.
   ====================================================================== */
@font-face {
  font-family: "Bookman";
  src: url("../assets/fonts/bookmanold.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --bg:      #efe7d6;
  --bg-2:    #e7dcc4;
  --card:    #fbf7ec;
  --ink:     #2e2419;
  --muted:   #7a6c58;
  --line:    #e0d5bd;
  --hat:     #5c4a3a;
  --hat-dark:#3a2c22;
  --accent:  #b5643a;
  --accent-d:#9c5230;
  --good:    #3f8f5f;
  --good-d:  #347a50;
  --bad:     #c0524a;
  --bad-d:   #a8443d;
  --gold:    #d9a441;
  --shadow:  0 6px 20px -8px rgba(58,44,34,.45);
  --radius:  16px;
  --serif:   "Bookman", "Bookman Old Style", Georgia, "Times New Roman", serif;
  --sans:    -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, sans-serif;
  --maxw:    560px;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  background-image: radial-gradient(120% 80% at 50% -10%, #f6efdf 0%, var(--bg) 55%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
h1, h2, h3, .serif, button.btn, .logo-word { font-family: var(--serif); }

#app {
  min-height: 100%;
  min-height: 100dvh;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 18px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

/* ---------- typography ---------- */
h1 { font-size: 30px; margin: 0; letter-spacing: .01em; text-wrap: balance; }
h2 { font-size: 22px; margin: 0 0 4px; text-wrap: balance; }
h3 { font-size: 17px; margin: 0; }
p  { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.center { text-align: center; }

/* ---------- screen scaffold ---------- */
.screen { display: flex; flex-direction: column; gap: 16px; flex: 1; animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .screen, .hat-spin { animation: none !important; } }

.topbar { display: flex; align-items: center; gap: 12px; min-height: 40px; }
.topbar .back {
  font-family: var(--sans); font-size: 15px; background: none; border: none; color: var(--hat);
  padding: 8px; margin: -8px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
}
.topbar h2 { flex: 1; font-size: 19px; }
.step { font-family: var(--sans); font-size: 12px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }

/* ---------- cards & lists ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.tile {
  width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px 16px; cursor: pointer; display: flex; gap: 13px;
  align-items: center; box-shadow: var(--shadow); transition: transform .08s ease, border-color .15s ease;
  font: inherit; color: inherit;
}
.tile:active { transform: scale(.985); }
.tile .ic { font-size: 24px; width: 30px; text-align: center; flex: none; }
.tile .t-main { font-family: var(--serif); font-size: 17px; }
.tile .t-sub { font-size: 13px; color: var(--muted); margin-top: 1px; }
.tile .chev { margin-left: auto; color: var(--muted); font-size: 20px; }
.tile[disabled] { opacity: .5; cursor: default; }

/* ---------- buttons ---------- */
button.btn, a.btn {
  appearance: none; border: none; border-radius: 14px; padding: 15px 20px; font-size: 18px;
  font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  gap: 9px; text-decoration: none; transition: transform .08s ease, filter .15s ease;
  box-shadow: 0 4px 0 var(--accent-d); background: var(--accent); color: #fff; width: 100%;
}
button.btn:active, a.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--accent-d); }
.btn.brown { background: var(--hat); box-shadow: 0 4px 0 var(--hat-dark); }
.btn.good  { background: var(--good); box-shadow: 0 4px 0 var(--good-d); }
.btn.bad   { background: var(--bad);  box-shadow: 0 4px 0 var(--bad-d); }
.btn.ghost { background: transparent; color: var(--hat); box-shadow: none; border: 1.5px solid var(--line); }
.btn.sm    { font-size: 15px; padding: 10px 14px; width: auto; box-shadow: 0 3px 0 var(--accent-d); }
.btn:disabled { opacity: .45; }
.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { width: auto; flex: 1; }

.iconbtn {
  border: 1px solid var(--line); background: var(--card); border-radius: 12px; width: 42px; height: 42px;
  font-size: 20px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  color: var(--hat); flex: none;
}
.link { background: none; border: none; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; padding: 0; }

/* ---------- form controls ---------- */
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
input[type=text], input[type=number], textarea, select {
  font: inherit; color: var(--ink); background: #fffdf7; border: 1.5px solid var(--line);
  border-radius: 12px; padding: 12px 13px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 84px; line-height: 1.45; }

.stepper { display: inline-flex; align-items: center; border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; background: #fffdf7; }
.stepper button { width: 44px; height: 44px; border: none; background: none; font-size: 22px; color: var(--hat); cursor: pointer; }
.stepper .val { min-width: 46px; text-align: center; font-family: var(--serif); font-size: 19px; font-variant-numeric: tabular-nums; }

/* switch */
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .sl { position: absolute; inset: 0; background: #d8cbb0; border: 1px solid var(--line); border-radius: 30px; transition: .18s; }
.switch .sl::before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 2px; background: #fff; border-radius: 50%; transition: .18s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + .sl { background: var(--good); }
.switch input:checked + .sl::before { transform: translateX(20px); }

.seg { display: flex; gap: 6px; background: var(--bg-2); border-radius: 13px; padding: 4px; }
.seg button { flex: 1; border: none; background: none; padding: 10px 6px; border-radius: 10px; font: inherit; font-size: 14px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--ink); font-weight: 700; box-shadow: 0 1px 4px rgba(58,44,34,.12); }

.setting { display: flex; align-items: center; gap: 12px; padding: 13px 2px; border-top: 1px solid var(--line); }
.setting:first-child { border-top: none; }
.setting .s-txt { flex: 1; }
.setting .s-name { font-size: 15.5px; }
.setting .s-hint { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ---------- landing ---------- */
.landing { text-align: center; gap: 22px; padding-top: 8px; }
.landing .logo { width: 168px; max-width: 60%; height: auto; margin: 6px auto 0; filter: drop-shadow(0 8px 14px rgba(58,44,34,.25)); }
.logo-word { font-size: 40px; letter-spacing: .06em; margin: 0; }
.landing .tagline { color: var(--muted); max-width: 34ch; margin: 0 auto; }
.feat { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.feat .f { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; font-size: 13px; box-shadow: var(--shadow); }
.install { text-align: left; }
.install ol { margin: 6px 0 0; padding-left: 0; list-style: none; counter-reset: st; display: flex; flex-direction: column; gap: 12px; }
.install li { counter-increment: st; display: flex; gap: 13px; align-items: flex-start; }
.install li::before {
  content: counter(st); flex: none; width: 30px; height: 30px; border-radius: 50%;
  background: var(--hat); color: #fff; font-family: var(--serif); font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.install li .k { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 7px; background: var(--bg-2); border: 1px solid var(--line); font-size: 14px; white-space: nowrap; }
.platform-tabs { display: flex; gap: 8px; justify-content: center; }
.platform-tabs button { border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 16px; font: inherit; font-size: 14px; cursor: pointer; color: var(--muted); }
.platform-tabs button.on { border-color: var(--hat); color: var(--ink); font-weight: 700; }

/* ---------- gameplay ---------- */
.play { justify-content: space-between; gap: 0; }
.play-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 4px; }
.timer { font-family: var(--serif); font-size: 40px; font-variant-numeric: tabular-nums; line-height: 1; }
.timer.warn { color: var(--bad); }
.pill { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 13px; font-size: 13px; box-shadow: var(--shadow); }
.wordcard {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 20px; margin: 14px 0; background: var(--card);
  border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); min-height: 180px;
}
.wordcard .w { font-family: var(--serif); font-size: clamp(30px, 9vw, 46px); font-weight: 700; line-height: 1.12; text-wrap: balance; }
.wordcard .tapc { color: var(--muted); font-size: 14px; margin-top: 14px; }
.play-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-bottom: 4px; }
.play-actions .btn { height: 68px; font-size: 20px; }
.bigstart { font-size: 22px; height: 76px; }
.progressbar { height: 6px; background: var(--bg-2); border-radius: 6px; overflow: hidden; }
.progressbar > i { display: block; height: 100%; background: var(--good); transition: width .3s linear; }

/* scoreboard */
.score-list { display: flex; flex-direction: column; gap: 8px; }
.score-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); }
.score-row .rank { font-family: var(--serif); font-size: 18px; color: var(--muted); width: 22px; }
.score-row .nm { flex: 1; font-size: 16px; }
.score-row .pts { font-family: var(--serif); font-size: 22px; font-variant-numeric: tabular-nums; }
.score-row.lead { border-color: var(--gold); background: #fdf6e3; }

.round-badge { display: inline-flex; align-items: center; gap: 8px; align-self: center; background: var(--hat); color: #fff; padding: 8px 16px; border-radius: 999px; font-family: var(--serif); }

/* team chips in setup */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 14px; display: inline-flex; gap: 5px; align-items: center; }
.chip button { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 0; }
button.chip { font: inherit; font-size: 14px; cursor: pointer; }
button.chip.on { background: var(--good); border-color: var(--good-d); color: #fff; }
button.chip.off { opacity: .55; text-decoration: line-through; }

.wordrow { display: flex; align-items: center; gap: 10px; padding: 11px 4px; border-top: 1px solid var(--line); }
.wordrow:first-child { border-top: none; }
.wordrow .grow { font-size: 16px; }

/* ---------- toast & modal ---------- */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 60; }
.toast { background: var(--hat-dark); color: #fbf7ec; padding: 11px 18px; border-radius: 999px; font-size: 14px; box-shadow: 0 8px 24px -8px rgba(0,0,0,.5); animation: fade .2s ease; max-width: 90vw; }
.modal-back { position: fixed; inset: 0; background: rgba(46,36,25,.5); display: flex; align-items: center; justify-content: center; padding: 22px; z-index: 50; animation: fade .18s ease; }
.modal { background: var(--card); border-radius: 20px; padding: 22px; max-width: 380px; width: 100%; box-shadow: 0 20px 50px -12px rgba(0,0,0,.5); }
.modal h3 { font-size: 20px; margin-bottom: 8px; }
.modal .modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal .modal-actions .btn { flex: 1; }
.modal .modal-actions.stack { flex-direction: column; }
.modal .modal-actions.stack .btn { width: 100%; flex: none; }
.modal { max-height: 86vh; overflow-y: auto; }

.hat-spin { width: 120px; height: auto; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }

.footnote { margin-top: auto; padding-top: 18px; text-align: center; color: var(--muted); font-size: 12px; }
.hidden { display: none !important; }
.divider { height: 1px; background: var(--line); margin: 4px 0; }
