:root {
  --page: #f5faf9;
  --outside: #ddecee;
  --surface: #fcfefd;
  --raised: #e8f4f5;
  --subtle: #e4efeb;
  --ink: #173a3c;
  --deep: #214c49;
  --muted: #4e6667;
  --line: #cedede;
  --control-line: #a7c1c0;
  --green: #24684b;
  --action: #286b51;
  --on-action: #fff;
  --danger: #8e352c;
  --danger-surface: #fae7e3;
  --warm: #75501d;
  --warm-surface: #fbefda;
  --season-ink: #164d71;
  --season-surface: #dbeefa;
  --shadow: 0 6px 24px rgba(23, 58, 60, .1);
  --app-width: 520px;
  --gutter: 14px;
  --radius: 8px;
  --header-size: 64px;
  --nav-size: 64px;
  --shell-inset: 0px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --answer-bottom: max(var(--shell-inset), var(--answer-inset, 0px));
  --serif: Georgia, "Times New Roman", serif;
}

:root[data-theme="dark"] {
  --page: #142322;
  --outside: #0e1919;
  --surface: #1b302e;
  --raised: #213735;
  --subtle: #25423b;
  --ink: #f1f8f4;
  --deep: #d5efe5;
  --muted: #b1cac3;
  --line: #39544e;
  --control-line: #64847a;
  --green: #a1dfb6;
  --action: #a1dfb6;
  --on-action: #11372b;
  --danger: #ffc2b7;
  --danger-surface: #4c2c2c;
  --warm: #ffdb98;
  --warm-surface: #473c29;
  --season-ink: #b9e4fb;
  --season-surface: #203f50;
  --shadow: 0 8px 26px rgba(0, 0, 0, .25);
}

html.telegram-fullscreen {
  --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px), var(--tg-content-safe-area-inset-bottom, 0px));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px), var(--tg-content-safe-area-inset-left, 0px));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px), var(--tg-content-safe-area-inset-right, 0px));
}

html,
body,
html[data-theme] body {
  background: var(--outside);
  color: var(--ink);
  font-size: 16px;
}

.app-shell, html[data-theme] .app-shell {
  width: min(100%, var(--app-width));
  height: calc(100dvh - 2 * var(--shell-inset));
  min-height: 0;
  max-height: none;
  border-radius: var(--radius);
  background: var(--page);
  box-shadow: var(--shadow);
}

.app-view {
  height: 100%;
  min-height: 0;
  padding: calc(var(--header-size) + var(--safe-top)) var(--safe-right) calc(var(--nav-size) + var(--safe-bottom) + 8px) var(--safe-left);
}

html[data-theme] :is(.app-header, .bottom-nav) {
  width: min(100%, var(--app-width));
  border-radius: 0;
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.app-header {
  top: var(--shell-inset);
  height: calc(var(--header-size) + var(--safe-top));
  padding: var(--safe-top) max(var(--gutter), var(--safe-right)) 0 max(var(--gutter), var(--safe-left));
  gap: 8px;
}

.header-title h1 {
  font: 700 23px/1.1 var(--serif);
  overflow-wrap: anywhere;
}

.header-title p { margin-top: 3px; font-size: 12px; line-height: 1.15; }
.header-subpage .header-title h1 {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 20px;
}
.header-actions { gap: 5px; }

.ui-icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

html[data-theme] :is(.header-action, .header-back, .icon-button, .sheet-close, .race-close, .race-icon) {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  padding: 0;
  border: 1px solid var(--control-line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

html.telegram-fullscreen .fullscreen-button { display: none; }
html[data-theme] .icon-button.active { background: var(--subtle); }
html[data-theme] .balance-pill {
  min-height: 44px;
  align-content: center;
  background: var(--subtle);
  color: var(--deep);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.bottom-nav {
  bottom: var(--shell-inset);
  height: calc(var(--nav-size) + var(--safe-bottom));
  gap: 0;
  padding: 0 max(4px, var(--safe-right)) var(--safe-bottom) max(4px, var(--safe-left));
}

html[data-theme] .nav-button {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  position: relative;
  min-width: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.nav-button .ui-icon { width: 22px; height: 22px; }
.nav-button span { margin: 0; font-size: 12px; font-weight: 650; }
html[data-theme] .nav-button.active { background: transparent; color: var(--green); }
.nav-button.active::after {
  content: "";
  position: absolute;
  inset: auto 17% 2px;
  height: 3px;
  border-radius: 2px;
  background: var(--green);
}

button { touch-action: manipulation; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

@media (hover: hover) {
  :is(.pier-link, .pier-mode, .pier-frog, .market-row, .menu-row):hover { background-color: var(--raised); }
}

/* Home and game selection */
.pier-home { background: var(--page); }
.pier-scene {
  height: 158px;
  padding: 19px max(20px, var(--gutter));
  background-color: var(--raised);
  background-image: url("pier/day.webp?v=2");
  background-position: center 43%;
  background-size: cover;
  background-repeat: no-repeat;
}
:root[data-theme="dark"] .pier-scene { background-image: url("pier/night.webp?v=2"); }
.pier-scene h2 { margin: 0; font: 700 30px/1.1 var(--serif); }
.pier-content { padding: 12px var(--gutter) 18px; }
.pier-section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 8px; }
.pier-section-title h2, .pier-group-heading { margin: 0; font: 700 23px/1.15 var(--serif); }
.pier-all-games {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-height: 44px;
  padding: 0 2px;
  border: 0;
  background: transparent;
  color: var(--green);
  font-size: 14px;
  font-weight: 700;
}
.pier-all-games .ui-icon { width: 16px; height: 16px; }
.pier-mode-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.pier-mode {
  display: grid;
  min-width: 0;
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  text-align: center;
}
.pier-mode-art { display: block; aspect-ratio: 1.65; background: var(--subtle) center / cover no-repeat; }
.pier-art-fishing { background-image: url("pier/fishing.webp"); }
.pier-art-alchemy { background-image: url("pier/alchemy.webp"); }
:root[data-theme="dark"] .pier-mode-art { filter: brightness(.82) saturate(.9); }
.pier-mode-copy { display: grid; gap: 4px; padding: 9px 4px; }
.pier-mode-copy b { font: 700 20px/1.2 var(--serif); overflow-wrap: anywhere; }
.pier-mode-status { display: flex; justify-content: center; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; }
.pier-mode-status .ui-icon { width: 14px; height: 14px; }
.pier-mode-status[data-ready="true"] { color: var(--green); }
.pier-mode-status[data-ready="true"] .ui-icon { display: none; }
.pier-mode-status[data-ready="true"]::before { content: ""; width: 7px; height: 7px; flex: none; border-radius: 50%; background: currentColor; }
.pier-races, .pier-cabinet-guild { margin: 12px 0; border-radius: var(--radius); background: var(--raised); }
.pier-cabinet-guild { margin-inline: var(--gutter); }
.pier-races .pier-link, .pier-cabinet-guild .pier-link { border: 0; border-radius: var(--radius); padding-inline: 12px; }
.pier-link, .pier-frog, .pier-continue {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  width: 100%;
  padding: 6px 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-weight: 650;
}
.pier-link > span, .pier-frog > span:not(.pier-frog-photo), .pier-continue > span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.pier-link small { color: var(--green); font-size: 12px; white-space: nowrap; }
:is(.pier-link, .pier-frog, .pier-continue) > .ui-icon:last-child { width: 16px; height: 16px; color: var(--muted); }
.pier-frog { min-height: 72px; }
.pier-frog-photo { display: grid; place-items: center; flex: 0 0 56px; width: 56px; height: 56px; border-radius: 50%; object-fit: cover; }
.pier-frog b { display: block; font: 700 19px/1.2 var(--serif); }
.pier-frog small { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; font-weight: 400; }
.pier-links { border-bottom: 1px solid var(--line); }
.pier-links .pier-link:last-child { border-bottom: 0; }
.pier-continue {
  margin-bottom: 12px;
  padding-inline: 10px;
  border: 1px solid var(--control-line);
  border-radius: var(--radius);
  background: var(--subtle);
}
.pier-group-heading { margin: 19px 0 4px; }
.pier-extra-games { margin-top: 14px; border-top: 1px solid var(--line); }

/* Shared controls, cards, and reading surfaces */
html[data-theme] :is(.primary-button, .race-primary, .race-chat-form button, .race-answer-form button) {
  background: var(--action);
  color: var(--on-action);
}
html[data-theme] :is(.secondary-button, .race-secondary, .letter-grid button) {
  border-color: var(--line);
  background: var(--raised);
  color: var(--ink);
}
html[data-theme] :is(.danger-button, .race-danger, .race-game-tools button.danger) { background: var(--danger-surface); color: var(--danger); }
:is(.primary-button, .secondary-button, .danger-button, .race-primary, .race-secondary, .race-danger) {
  min-height: 44px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
button:disabled { cursor: default; }
html[data-theme] :is(.toolbar, .segmented) { background: transparent; border-color: var(--line); }
:is(.toolbar, .segmented) { padding-inline: var(--gutter); }
html[data-theme] :is(.segment, .race-tabs button) {
  min-height: 44px;
  min-width: 0;
  border: 0;
  border-radius: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}
html[data-theme] :is(.segment.active, .race-tabs button.active) {
  border-bottom-color: var(--green);
  background: transparent;
  color: var(--ink);
}
html[data-theme] input:not([type="checkbox"]):not([type="radio"]),
html[data-theme] select,
html[data-theme] textarea {
  min-width: 0;
  min-height: 44px;
  border-color: var(--control-line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
}
html[data-theme] :is(input, textarea)::placeholder { color: var(--muted); opacity: .9; }
html[data-theme] :is(.image-placeholder, .jabyakovka-option-image) { background: var(--raised); color: var(--muted); }
.image-placeholder .ui-icon { width: 32px; height: 32px; }
html[data-theme] :is(.meter, .bar, .jar-meter) { background: var(--subtle); }
.meter { height: 7px; }

html[data-theme] :is(.card-stack, .recipe-area, .settings-page) { background: var(--page); }
html[data-theme] :is(.settings-group, .summary-box, .rating-bars, .stat-box, .profile-head, .menu-row,
  .offer-item, .game-history-row, .race-panel, .race-room-card, .race-rules, .race-settings span,
  .race-leaderboard-row, .race-leaderboard, .race-join-card, .race-drawer, .race-modal form,
  .race-round-detail, .jabyakovka-option, .hint-target, .puzzle-row, .book-page, .guild-hero,
  .daily-quest-summary, .daily-quest-card, .daily-guild-entry, .order-card, .jar-panel,
  .collection-tile, .recipe-tile, .detail-cell, .confirm-box, .history-hint, .history-preview,
  .history-tree, .history-node, .history-cycle, .listing-sheet-action, .game-result-paper, .social-card) {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
  box-shadow: none;
}
html[data-theme] :is(.daily-quest-card.done, .order-card.done, .history-node.root, .history-node.selected,
  .race-prize, .hint-target.primary-target, .alchemy-select-grid label input:checked + span,
  .daily-guild-entry, .formula, .game-transfer, .book-label) {
  background: var(--subtle);
  border-color: var(--line);
  color: var(--ink);
}
html[data-theme] :is(.game-activity-entry.near, .game-activity-entry.hint, .game-activity-entry.letters, .race-attempt-result, .race-form-note, .race-podium > div) {
  background: var(--warm-surface);
  border-color: var(--line);
  color: var(--warm);
}
html[data-theme] :is(.warning, .daily-quest-difficulty, .game-activity-entry.near .game-activity-icon) { color: var(--warm); }
html[data-theme] :is(.game-activity-entry.success, .daily-quest-card.done .daily-quest-mark) { background: var(--subtle); color: var(--green); }
html[data-theme] :is(.order-icon, .daily-quest-mark, .theme-choice, .history-node-toggle, .recipe-emoji, .book-image > span:not(.image-placeholder)) {
  background: var(--raised);
  border-color: var(--line);
  color: var(--deep);
}
html[data-theme] :is(.book-meta, .guild-hero p, .order-card p, .history-node small, .history-cycle,
  .race-room-owner, .race-muted, .race-title p, .race-room-state, .race-empty, .game-category,
  .game-activity-entry small, .market-origin, .market-row p) {
  color: var(--muted) !important;
}
html[data-theme] :is(.market-price b, .price-display b, .race-podium strong, .history-node.expanded .history-node-toggle) {
  color: var(--green) !important;
}
html[data-theme] :is(.market-price span, .recipe-listed) { background: var(--warm-surface); color: var(--warm); }
html[data-theme] :is(.sheet, .overlay-root .seasonal-sheet) {
  width: min(100%, var(--app-width));
  border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--surface);
  color: var(--ink);
}
.sheet-head h2 { font: 700 22px/1.15 var(--serif); overflow-wrap: anywhere; }
.sheet-image, .book-image { border-color: var(--line); border-radius: var(--radius); }
.detail-cell, .stat-box { min-width: 0; overflow-wrap: anywhere; }
.book-page::before { content: none; }

:is(.section-title h2, .book-page h2, .guild-hero h2, .profile-head h2, .race-title h2,
  .race-panel h3, .seasonal-heading h2, .game-activity-title b) { font: 700 22px/1.15 var(--serif); }
:is(.menu-row b, .offer-item h4, .puzzle-row h3, .market-row h3, .order-card b, .daily-quest-copy h3,
  .discovery-row b, .game-history-copy b, .race-room-card-top) { font-size: 15px; }
:is(.section-title p, .section-link, .market-result, .market-row p, .market-price small,
  .profile-head p, .menu-row small, .setting-row small, .daily-quest-summary footer,
  .daily-quest-summary > div:first-child, .daily-quest-reward, .daily-quest-progress b, .daily-quest-difficulty,
  .daily-guild-entry small, .offer-item p, .order-card p, .sheet-subtitle, .detail-text,
  .book-label, .book-meta, .formula, .warning, .discovery-row small, .game-history-copy small,
  .game-result-meta, .game-transfer code, .hint-target small, .race-room-owner, .race-room-state,
  .race-room-facts i, .race-title p, .race-player-list small, .race-form-note,
  .race-create-form label, .race-empty p) { font-size: 13px; line-height: 1.4; }
.market-row h3 { overflow-wrap: anywhere; white-space: normal; }
.market-row img, .market-row > .image-placeholder { border-color: var(--line); border-radius: var(--radius); }
.market-price b { font-size: 15px; }
.market-price span { font-size: 11px; }
.menu-row, .profile-head { padding-inline: var(--gutter); }
.menu-row { grid-template-columns: 26px minmax(0, 1fr) auto; }
.menu-row b, .menu-row small, .frog-gallery-details b, .settings-group { overflow-wrap: anywhere; }
.summary-box span, .stat-box small, .puzzle-row p, .jar-header small,
.theme-choice button, .frog-gallery-details span, .frog-main-note { font-size: 12px; line-height: 1.4; }
.stat-box b, .jar-header h3, .setting-row b, .settings-group h2, .frog-gallery-details b { font-size: 14px; }
.settings-group h2 { text-transform: none; }
.theme-choice button { min-height: 44px; }
.theme-choice button.active,
html[data-theme] .theme-choice button.active { background: var(--surface); color: var(--green); box-shadow: none; }
html[data-theme] .toggle.on { background: var(--action); }
:root[data-theme="dark"] .toggle.on i { background: var(--on-action); }
html[data-theme] :is(.frog-portrait, .frog-gallery-stage, .frog-photo-thumb, .avatar, .social-photo) {
  border-color: var(--line);
  background: var(--raised);
  box-shadow: none;
}
html[data-theme] .frog-placeholder {
  background: var(--raised) url("pier/frog.webp") center / contain no-repeat;
}
html[data-theme] .pier-frog-photo.frog-placeholder {
  background-color: transparent;
}
html[data-theme] .frog-photo-thumb.selected { border-color: var(--green); }
html[data-theme] :is(.frog-nameplate, .frog-gallery-details strong, .frog-gallery-arrow) {
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius);
}
.frog-nameplate b { color: var(--ink); }
.frog-nameplate span { font-size: 12px; }
html[data-theme] :is(.frog-main-note, .frog-main-badge) { background: var(--subtle); border-color: var(--line); color: var(--ink); }
html[data-theme] .social-tabs { border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; }
html[data-theme] .social-tabs button {
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}
html[data-theme] .social-tabs button[aria-selected="true"] { border-color: var(--green); background: transparent; color: var(--ink); }
html[data-theme] .social-date { color: var(--muted); }
html[data-theme] .social-error { color: var(--danger); }
html[data-theme] :is(.social-result, .kiss-reward) { border-color: var(--line); }
.game-history-row b { font-size: 15px; }
.game-history-row small { color: var(--muted); font-size: 13px; }
.game-result-paper { border-radius: var(--radius); }
.game-result-details { display: grid; gap: 9px; min-width: 0; }
@media (min-width: 768px) {
  .game-result .game-picture {
    width: min(100%, 360px); height: min(42dvh, 360px);
    justify-self: center; aspect-ratio: auto; border-radius: var(--radius);
  }
  .game-result .game-picture :is(img, video) { display: block; object-fit: contain; }
}
.toast { background: var(--ink); color: var(--surface); font-size: 14px; }
.guild-hero, .daily-quest-summary, .daily-guild-entry { border-width: 1px; }
.order-card h3 { font-size: 15px; }
.guild-hero p { font-size: 13px; line-height: 1.5; }

/* Collection */
html[data-theme] .cabinet-summary { padding: 12px var(--gutter); border: 0; background: transparent; }
.capacity-line { font-size: 14px; font-weight: 700; }
.pier-search {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}
.pier-search .ui-icon { position: absolute; left: 10px; color: var(--muted); pointer-events: none; }
.pier-search .search-field { width: 100%; padding-left: 36px; }
.cabinet-toolbar .season-filter { border: 1px solid var(--control-line); min-height: 44px; }
.cabinet-shell { height: auto; min-height: 0; margin: 12px var(--gutter); padding: 0; border: 0; background: transparent; box-shadow: none; }
.cabinet-scroll { height: auto; overflow: visible; }
:is(.cabinet-grid, .recipe-grid) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
:is(.collection-tile, .recipe-tile) { overflow: hidden; border-radius: var(--radius); padding-bottom: 8px; }
:is(button.collection-tile, .recipe-tile) {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: repeat(3, max-content);
  align-content: start;
}
button.collection-tile { grid-template-rows: repeat(3, max-content) 22px; }
:is(button.collection-tile, .recipe-tile) > :is(img, .image-placeholder) {
  grid-area: 1 / 1;
  align-self: start;
}
:is(button.collection-tile, .recipe-tile) > b {
  grid-area: 2 / 1;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  block-size: 2.4em;
  margin: 8px 8px 4px;
  padding: 0;
  font: 700 16px/1.2 var(--serif);
  white-space: normal;
  overflow-wrap: anywhere;
}
html[data-theme] :is(button.collection-tile, .recipe-tile) > small {
  grid-area: 3 / 1;
  padding: 0 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
  overflow: hidden;
}
.recipe-tile > small {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  block-size: 2.5em;
  overflow-wrap: anywhere;
}
button.collection-tile > small {
  block-size: 1.25em;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.cabinet-art { object-position: center; }
.cabinet-art.image-placeholder { font-size: 42px; }
html[data-theme] .cabinet-cell.empty { min-height: 96px; aspect-ratio: auto; border: 1px dashed var(--control-line); background: transparent; color: var(--muted); }
.cabinet-cell.empty b { font-size: 22px; }
.cabinet-cell.empty span { font-size: 12px; }
.book-page :is(h2, .formula) { overflow-wrap: anywhere; }
.recipe-listed, .item-lock-badge {
  position: absolute;
  left: 6px;
  top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px 5px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
}
.item-lock-badge .ui-icon { width: 12px; height: 12px; }
html[data-theme] .collection-tile > .seasonal-badge {
  grid-area: 4 / 1;
  place-self: start;
  max-width: calc(100% - 16px);
  margin: 2px 8px 0;
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--season-ink);
  background: var(--season-surface);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Puzzle play keeps the input in reach without covering the scrollable history. */
.personal-riddle-active .bottom-nav { display: none; }
.personal-riddle-active .app-view {
  padding-bottom: calc(var(--answer-dock-size, 80px) + var(--answer-bottom) - var(--shell-inset) + 12px);
}
.personal-riddle-active .header-title p { white-space: normal; }
.private-game { padding: 12px var(--gutter) 18px; }
.private-game .game-picture { aspect-ratio: auto; min-height: 0; height: auto; max-height: 320px; border-radius: var(--radius); box-shadow: none; }
.private-game .game-picture :is(img, video) { display: block; width: 100%; max-height: 320px; height: min(44dvh, 320px); object-fit: contain; background: var(--raised); }
html[data-theme] .game-copy { padding: 12px; border-color: var(--line); border-radius: var(--radius); background: var(--surface); }
.game-category { font-size: 14px; line-height: 1.5; }
.game-mask { font-size: 19px; line-height: 1.35; white-space: pre-line; }
html[data-theme] .game-answer-format { padding: 5px 0 0; border: 0; background: transparent; color: var(--muted); font-size: 13px; }
.game-progress, .game-letter-state p { font-size: 12px; line-height: 1.5; }
.game-tools { gap: 6px; }
.game-tools button { display: grid; justify-items: center; align-content: center; gap: 5px; min-height: 54px; font-size: 12px; }
.game-tool-price { white-space: nowrap; }
.game-tools .ui-icon { width: 18px; height: 18px; }
.letter-builder-switch { display: block; min-height: 44px; margin: 0 0 5px auto; padding: 2px 5px; }
.game-answer-builder {
  display: grid; gap: 12px; min-width: 0; margin: 10px 0; padding: 12px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
.letter-builder-bar, .letter-builder-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.letter-builder-bar .section-link { min-height: 40px; }
.letter-builder-scopes { display: flex; flex-wrap: wrap; gap: 6px; }
.letter-builder-scopes button { padding-inline: 10px; }
.letter-builder-scopes button[aria-pressed=true] { border-color: var(--green); }
.letter-builder-words, .letter-builder-word { display: flex; flex-wrap: wrap; min-width: 0; align-items: center; }
.letter-builder-words { gap: 12px 14px; }
.letter-builder-word { gap: 4px; max-width: 100%; }
.letter-builder-cell, .letter-builder-key {
  display: grid; place-content: center; text-align: center;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--raised); color: var(--ink);
  font: 700 15px/1.1 system-ui, sans-serif;
}
.letter-builder-cell { width: 32px; height: 39px; padding: 0; }
.has-picked-letter .letter-builder-cell:not(.is-fixed) { border-color: var(--green); }
.letter-builder-cell.is-drop-target, .letter-builder-key[aria-pressed=true] {
  border-color: var(--green); outline: 2px solid var(--green); outline-offset: -2px;
  background: var(--subtle);
}
.letter-builder-cell.is-fixed { background: var(--subtle); color: var(--green); }
.letter-builder-keys { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.letter-builder-key { min-height: 46px; gap: 2px; padding: 4px; }
.letter-builder-key small { color: var(--muted); font: 600 11px/1.1 system-ui, sans-serif; }
.letter-builder-key:disabled { opacity: 0.55; }
.letter-builder-cell, .letter-builder-key { user-select: none; }
.letter-builder-cell[data-letter]:not(:disabled), .letter-builder-key:not(:disabled) { touch-action: none; cursor: grab; }
.letter-builder-ghost {
  position: fixed; inset: 0 auto auto 0; z-index: 1000; pointer-events: none;
  display: grid; place-content: center; width: 42px; height: 42px;
  border: 1px solid var(--green); border-radius: var(--radius); background: var(--surface);
  color: var(--ink); box-shadow: var(--shadow); font: 700 18px/1 system-ui, sans-serif;
}
.letter-builder-footer .primary-button { flex: 1; }
html[data-theme] .game-activity { border: 0; background: transparent; }
.game-activity-title { padding-inline: 0; }
html[data-theme] .game-activity-title span { background: var(--raised); color: var(--muted); font-size: 12px; }
.game-activity-list { max-height: none; gap: 0; }
html[data-theme] .game-activity-entry { padding-inline: 4px; border-bottom: 1px solid var(--line); background: transparent; }
.game-activity-entry b, .game-activity-entry small, .game-activity-entry time, .game-activity-empty { font-size: 13px; }
.game-finish-button { margin-top: 10px; }
.game-answer-dock {
  position: fixed;
  z-index: 41;
  inset: auto auto var(--answer-bottom) 50%;
  transform: translateX(-50%);
  width: min(100%, var(--app-width));
  padding: 9px max(var(--gutter), var(--safe-right)) max(9px, var(--safe-bottom)) max(var(--gutter), var(--safe-left));
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.game-answer-dock .guess-form { grid-template-columns: minmax(0, 1fr) auto; margin: 0; }
.game-answer-dock :is(input, button) { min-height: 48px; }
.game-answer-preview { display: none; max-height: 96px; overflow-y: auto; padding-bottom: 8px; }
.game-answer-dock.answer-focused .game-answer-preview { display: block; }
.game-answer-preview .game-mask { font-size: 16px; }
.game-answer-preview .game-answer-format { margin: 0; }
.personal-riddle-active .toast { bottom: calc(var(--answer-bottom) + var(--answer-dock-size, 80px) + 8px); }

/* Race views keep their own scrolling and keyboard handling. */
html[data-theme] .races-shell { background: var(--page); color: var(--ink); }
html.races-active.races-list-active .races-shell { padding-bottom: calc(var(--nav-size) + var(--safe-bottom) + 14px); }
html[data-theme] .race-tabs { padding-block: 0; background: transparent; border-color: var(--line); }
html[data-theme] .race-room-card { border-left: 3px solid var(--green); }
html[data-theme] :is(.race-room-facts i, .race-player-list li, .race-result-users button,
  .race-game-tools button, .race-replay-controls select, .race-replay-controls option) {
  background: var(--raised);
  border-color: var(--line);
  color: var(--ink);
}
html[data-theme] :is(.race-answer-dock, .race-room-actions) { background: var(--surface); border-color: var(--line); box-shadow: none; }
html[data-theme] .race-mask { color: var(--ink); }
html[data-theme] .race-chat-messages p { background: var(--raised); color: var(--ink); font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
html[data-theme] .race-chat-messages p.mine { background: var(--subtle); color: var(--ink); }
html[data-theme] .race-chat-messages p.system { background: transparent; color: var(--muted); }
html[data-theme] .race-chat-messages :is(p b, em) { color: var(--green); font-size: 12px; }
html[data-theme] .race-leaderboard-row.me { background: var(--warm-surface); border-color: var(--warm); color: var(--ink); }
html[data-theme] .race-title h2 { color: var(--ink); overflow-wrap: anywhere; }
.race-answer-form button, .race-game-tools button { min-height: 44px; font-size: 13px; }
html[data-theme] :is(.race-game-head, .race-round-detail > button) { color: var(--ink); }
html[data-theme] .race-live-strip span { background: var(--raised); border-color: var(--line); color: var(--ink); }
.race-live-strip b, .race-settings b { font-size: 15px; }
.race-live-strip small, .race-settings small { color: var(--muted); font-size: 11px; opacity: 1; }
.race-panel-title small, .race-join-card p, .race-player-list small, .race-row-info > small,
.race-room-actions span, .race-modal p { color: var(--muted); }
.race-panel-title small { font-size: 11px; text-align: right; }
.race-panel-title button { min-height: 44px; color: var(--green); font-size: 13px; }
.race-player-list b { font-size: 14px; }
.race-row-info > :is(b, span, strong) { font-size: 12px; }
.race-row-info > small { font-size: 10px; }
.race-mask { font-size: 19px; }
.race-puzzle { border-width: 1px; border-color: var(--line); box-shadow: none; }
.race-room-actions { bottom: calc(8px + var(--safe-bottom)); }
html[data-theme] .race-notice { background: var(--subtle); color: var(--ink); font-size: 13px; }
html[data-theme] .race-error { background: var(--danger-surface); color: var(--danger); font-size: 13px; }
.seasonal-collector { padding-inline: var(--gutter); }
.seasonal-tabs button { min-height: 44px; font-size: 13px; }
html[data-theme] .seasonal-notice.is-error { color: var(--danger); }

@media (max-width: 719px) {
  .race-answer-dock { bottom: calc(8px + var(--safe-bottom) + var(--race-keyboard-inset, 0px)); }
}

@media (min-width: 760px) {
  :root { --shell-inset: 16px; --gutter: 18px; }
  body { padding: var(--shell-inset) 0; }
  .pier-scene { height: 178px; }
  html[data-theme] .app-header { border-radius: var(--radius) var(--radius) 0 0; }
  html[data-theme] .bottom-nav { border-radius: 0 0 var(--radius) var(--radius); }
  .cabinet-grid, .recipe-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  html:not(.telegram-fullscreen) .header-subpage .balance-pill { display: none; }
}

@media (max-width: 360px) {
  :root { --gutter: 10px; }
  .header-title h1 { font-size: 19px; }
  .header-subpage .header-title h1 { font-size: 17px; }
  .header-title p { font-size: 11px; }
  .pier-scene { height: 133px; }
  .pier-scene h2 { font-size: 27px; }
  .pier-mode-copy b { font-size: 18px; }
  .pier-link { gap: 7px; }
  .nav-button span { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
.generation-ad {
  min-width: 0;
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  overflow-wrap: anywhere;
}
.generation-ad small { display: grid; gap: 2px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.generation-ad p { margin: 0; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.generation-ad a { color: var(--green); text-decoration: underline; }
html:has(.photo-composer) .photo-generation-controls .generation-ad { display: none; }

.parade-feed-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.parade-feed-tabs button {
  min-height: 44px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
}
.parade-feed-tabs button[aria-pressed="true"] { border-color: var(--green); color: var(--ink); font-weight: 700; }
.parade-search { position: relative; }
.parade-search > .ui-icon { position: absolute; top: 12px; left: 12px; width: 20px; height: 20px; color: var(--muted); pointer-events: none; }
.parade-search .search-field { padding-left: 40px; }
html[data-theme] .parade-card {
  min-width: 0;
  padding: 0 0 10px;
  border-width: 0 0 1px;
  border-radius: 0;
  background: transparent;
}
.parade-card h2 { margin: 0; }
.parade-card .parade-author, .parade-card .parade-photo, .parade-card .parade-icon-button {
  margin: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
}
.parade-card .parade-author {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 4px 8px;
  text-align: left;
  overflow-wrap: anywhere;
  font: 700 17px/1.25 var(--serif);
}
.parade-author > span { min-width: 0; }
.parade-author small, .parade-profile-byline { color: var(--muted); font: 400 13px/1.3 system-ui, sans-serif; }
.parade-card .parade-author small { margin: 2px 0 0; }
.parade-avatar, .parade-profile-avatar {
  display: block;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  object-fit: cover;
}
.parade-card .parade-photo {
  display: block;
  width: 100%;
  padding: 0;
  border-radius: var(--radius);
  overflow: hidden;
}
.parade-post .social-photo { border-radius: var(--radius); }
.parade-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 76px)) minmax(34px, 1fr);
  align-items: center;
  padding-top: 3px;
}
.parade-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 44px;
  min-width: 34px;
  padding: 0 3px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.parade-icon-button .ui-icon { width: 21px; height: 21px; flex: 0 0 21px; }
.parade-actions .parade-icon-button { justify-content: flex-start; }
.parade-actions .parade-icon-button span { min-width: 0; overflow-wrap: anywhere; line-height: 1; }
.parade-actions [data-action="kiss-result"] { justify-self: end; justify-content: center; grid-column: 4; }
.parade-actions [aria-pressed="true"] .ui-icon { fill: currentColor; color: #b42f56; }
html[data-theme="dark"] .parade-actions [aria-pressed="true"] .ui-icon { color: #ff839f; }
.parade-actions button:disabled { opacity: .65; }
.parade-card .social-description { margin: 2px 4px; color: var(--ink); font-size: 15px; }
.parade-card .social-date { margin: 4px; }
.parade-post, .parade-profile { width: min(100%, 640px); margin-inline: auto; padding: var(--gutter); }
.parade-profile { container-type: inline-size; }
.parade-profile-intro { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 12px; align-items: center; }
.parade-profile-avatar { width: 74px; height: 74px; }
.parade-profile-byline { margin: 0 0 6px; overflow-wrap: anywhere; }
.parade-profile-intro button { min-width: min(100%, 136px); }
.parade-profile-intro dl {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px 0;
  margin: 0 0 8px;
  padding: 6px 0;
}
.parade-profile-intro dl div { display: grid; align-content: start; grid-column: span 2; text-align: center; padding: 0 4px; }
.parade-profile-intro dl div:nth-child(n+4) { grid-column: span 3; }
.parade-profile-intro dl div:is(:nth-child(2), :nth-child(3), :nth-child(5)) { border-left: 1px solid var(--line); }
.parade-profile-intro dd { grid-row: 1; margin: 0; font: 700 23px/1.2 var(--serif); overflow-wrap: anywhere; }
.parade-profile-intro dt { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
@container (min-width: 530px) {
  .parade-profile-intro dl { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .parade-profile-intro dl div:nth-child(n) { grid-column: auto; }
  .parade-profile-intro dl div + div { border-left: 1px solid var(--line); }
}
.parade-profile-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; margin-bottom: 12px; }
.parade-profile-grid button { min-width: 0; width: 100%; aspect-ratio: 1; padding: 0; border: 0; background: var(--subtle); overflow: hidden; }
.parade-tile-image { display: block; width: 100%; height: 100%; aspect-ratio: 1; object-fit: cover; }
.parade-profile-kisses, .parade-comments-scroll ul { margin: 0; padding: 0; list-style: none; }
.parade-initials {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--subtle);
  color: var(--deep);
  font: 700 15px/1 var(--serif);
}
.parade-profile-kisses li {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.parade-profile-kisses strong { color: var(--green); }
.parade-discussion { display: flex; min-width: 0; flex-direction: column; }
.overlay-root:has(> .parade-discussion-sheet) { bottom: var(--parade-keyboard-inset, 0px); }
html[data-theme] .overlay-root .parade-discussion-sheet {
  height: min(62dvh, 620px);
  max-height: min(90dvh, calc(100dvh - var(--parade-keyboard-inset, 0px) - 12px));
  overflow: hidden;
  padding: 12px var(--gutter) calc(12px + var(--safe-bottom));
}
.parade-discussion-head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 6px; border-bottom: 1px solid var(--line); }
.parade-discussion-head h2 { margin: 0; font: 700 23px/1.15 var(--serif); }
.parade-discussion-head button, .parade-comments-scroll li button { min-width: 44px; }
.parade-comments-scroll { min-height: 0; flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; }
.parade-comments-scroll li {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: start;
  gap: 9px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.parade-comment-copy > div { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 9px; }
.parade-comments-scroll li button { color: var(--danger); }
.parade-comments-scroll li time { color: var(--muted); font-size: 12px; }
.parade-comments-scroll li p { margin: 5px 0 0; white-space: pre-wrap; line-height: 1.4; }
.parade-comments-scroll > button { margin-top: 10px; }
.parade-comment-form {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 7ch 44px;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  padding: 4px;
  border: 1px solid var(--control-line);
  border-radius: var(--radius);
}
.parade-comment-form textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 6px 5px;
  resize: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
}
.parade-comment-counter { text-align: center; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.parade-comment-form button { background: var(--action); color: var(--on-action); }
.parade-comment-form button:disabled { background: var(--subtle); color: var(--muted); }
.parade-comment-form p { grid-column: 1 / -1; margin: 0 6px 5px; }
.parade-card [hidden], .parade-profile [hidden], .parade-discussion [hidden] { display: none; }
@media (hover: hover) {
  .parade-card .parade-author:hover b, .parade-feed-tabs button:hover { color: var(--green); }
  .parade-card .parade-icon-button:not(:disabled):hover, .parade-discussion-head button:hover { background: var(--subtle); }
}
@media (min-width: 960px) {
  .parade-post--discussion {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(235px, 1fr);
    width: min(100%, 1200px);
    gap: 16px;
    align-items: start;
  }
  .parade-post .social-photo { max-height: min(60dvh, 610px); object-fit: contain; }
  .parade-post--discussion .parade-discussion { height: min(75dvh, 740px); padding-left: 16px; border-left: 1px solid var(--line); }
}
@media (max-width: 359px) {
  .app-header:has([data-action="frog-photos"]) { gap: 4px; }
  .app-header:has([data-action="frog-photos"]) .header-actions { gap: 3px; }
  .parade-comment-form textarea { font-size: 14px; }
}
