/*
  Site chrome around the embedded Flutter game (header / description / footer).
  Web-only stylesheet — lives in web/, never bundled into the Android app.

  Colors reference the game's palette CSS variables (set by engine/themes.js).
  Fallback values match the default blueCustomColors palette so non-game pages
  also look correct before JavaScript boots.
*/

:root {
  --bg: var(--tone-0, #FFFFFF);                 /* scaffold background */
  --panel: var(--tone-1, #ECEFF6);              /* surface/panel */
  --border: var(--tone-2, #D0D8E3);             /* borders */
  --text: var(--puzzle-color, #000000);         /* main text */
  --text-muted: var(--tone-5, #8190A5);         /* secondary text */
  --accent: var(--unit-bubble-color, #265AC2);   /* accent/primary */
}

* {
  box-sizing: border-box;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  tap-highlight-color: transparent;
}

*::selection {
  background: transparent;
}

*::-moz-selection {
  background: transparent;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Outfit", "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.site {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
}

a {
  color: inherit;
  text-decoration: none;
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.site-header__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.site-header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  min-width: 0;
}

.site-header__start {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.site-header__burger-mount {
  display: none;
  flex-shrink: 0;
}

.site-header__portrait-new-game:not(:empty) {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  min-width: 0;
}

html[data-orientation='portrait'] .site-header__portrait-new-game:not(:empty) {
  display: flex !important;
}

html[data-orientation='landscape'] .site-header__portrait-new-game {
  display: none !important;
}

.site-header__logo {
  display: inline-flex;
  align-items: center;
  gap: 0.03em;
  height: 1em;
  font-size: 42px;
  white-space: nowrap;
  user-select: none;
  flex-shrink: 0;
}
.site-header__logo-text {
  font-size: 0.682em;        /* 30 / 44 */
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--puzzle-color);
  line-height: 1;
}
.site-header__logo-cell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.864em;             /* 38 / 44 */
  height: 0.818em;            /* 36 / 44 */
  background: #265AC2;
  border: 0.0284em solid #6B94DC;  /* 1.25 / 44 */
  border-radius: 0.125em;     /* 5.5 / 44 */
  flex-shrink: 0;
  box-sizing: border-box;
}
.site-header__logo-cell-digit {
  position: absolute;
  top: 0.045em;               /* ~2 / 44 */
  left: 0.091em;              /* ~4 / 44 */
  font-size: 0.227em;         /* 10 / 44 */
  font-weight: 500;
  color: #D0D8E3;
  line-height: 1;
}
.site-header__logo-cell-brand {
  font-size: 0.443em;         /* 19.5 / 44 */
  font-weight: 600;
  color: #FFFFFF;
  line-height: 1;
}
.site-header__logo-domain {
  font-size: 0.545em;         /* 24 / 44 */
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--puzzle-color);
  line-height: 1;
}

.site-header__badge {
  display: inline-flex;
  align-items: center;
  margin-left: 0;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 0;
}

.site-header__nav {
  display: flex;
  gap: 24px;
  font-size: 16.5px;
  color: var(--text-muted);
  flex-shrink: 0;
}
html[data-orientation='landscape'] .site-header__nav {
  font-size: 19.8px;
}

.site-header__nav a:hover {
  color: var(--accent);
}

.site-header__end {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-left: auto;
  min-width: 0;
  flex-shrink: 1;
}

.site-header__end.is-collapsed .site-header__nav {
  display: none;
}

.site-header__game-controls:not(:empty) {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.site-header-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
}

.site-header-controls-inline {
  display: flex;
  align-items: center;
  gap: 4px;
}

.site-header__end.is-collapsed .site-header-controls-inline {
  display: none;
}

.site-header-controls-burger-wrap {
  position: relative;
  display: none;
}

.site-header__end.is-collapsed .site-header-controls-burger-wrap {
  display: block;
}

.site-header-controls-burger-wrap[hidden] {
  display: none !important;
}

.site-header-controls-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: none;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
}

.site-header-controls-btn:hover {
  color: var(--accent);
  background: var(--panel);
}

.site-header-controls-btn svg {
  width: 20px;
  height: 20px;
}

.site-header-controls-lang {
  position: relative;
}

/* Portrait: компактная шапка — бургер слева, логотип меньше, «Новая игра» справа. */
html[data-orientation='portrait'] .site-header__end .site-header__nav {
  display: none !important;
}

html[data-orientation='portrait'] .site-header-controls-burger-wrap {
  display: block !important;
  position: relative;
}

html[data-orientation='portrait'] .site-header-controls-burger-wrap[hidden] {
  display: block !important;
}

html[data-orientation='portrait'] .site-header-controls-lang {
  display: none;
}

html[data-orientation='portrait'] .site-header-controls-theme {
  display: none;
}

html[data-orientation='portrait'] .site-header-controls-inline {
  display: none !important;
}

html[data-orientation='portrait'] .site-header__game-controls:not(:has(.site-header-controls-burger-wrap)) {
  display: none !important;
}

html[data-orientation='portrait'] .site-header__inner {
  padding: 8px 12px;
  gap: 8px;
}

html[data-orientation='portrait'] .site-header__start {
  flex: 1 1 auto;
  gap: 6px;
  min-width: 0;
}

html[data-orientation='portrait'] .site-header__burger-mount {
  display: flex;
  align-items: center;
}

html[data-orientation='portrait'] .site-header__brand {
  gap: 6px;
  flex-shrink: 1;
  min-width: 0;
}

html[data-orientation='portrait'] .site-header__logo {
  font-size: 28px;
}

html[data-orientation='portrait'] .site-header__badge {
  padding: 2px 6px;
  font-size: 9px;
  flex-shrink: 0;
  min-width: 0;
  max-width: 28%;
  overflow: hidden;
  text-overflow: ellipsis;
}

html[data-orientation='portrait'] .site-header__end {
  flex: 0 0 auto;
  gap: 6px;
  margin-left: 0;
}

html[data-orientation='portrait'] .site-header-controls-btn {
  width: 32px;
  height: 32px;
}

html[data-orientation='portrait'] .site-header-controls-btn svg {
  width: 18px;
  height: 18px;
}

html[data-orientation='portrait'] .landscape-new-game-mount {
  display: none !important;
}

html[data-orientation='portrait'] .site-header-controls-burger-menu {
  left: 0;
  right: auto;
}

/* На остальных страницах — компактная шапка при узком viewport (не game portrait). */
@media (max-width: 900px) {
  .site-header__end .site-header__nav {
    display: none !important;
  }

  .site-header-controls-burger-wrap {
    display: block !important;
    position: relative;
  }

  .site-header-controls-burger-wrap[hidden] {
    display: block !important;
  }

  .site-header-controls-lang {
    display: none;
  }

  .site-header-controls-inline {
    display: none !important;
  }

  .site-header__game-controls:not(:has(.site-header-controls-burger-wrap)) {
    display: none !important;
  }

  .site-header__inner {
    padding: 8px 12px;
    gap: 8px;
  }

  .site-header__start {
    flex: 1 1 auto;
    gap: 2px;
    min-width: 0;
  }

  .site-header__burger-mount {
    display: flex;
    align-items: center;
  }

  .site-header__brand {
    gap: 6px;
    flex-shrink: 1;
    min-width: 0;
  }

  .site-header__logo {
    font-size: 28px;
  }

  .site-header__badge {
    padding: 2px 6px;
    font-size: 9px;
    flex-shrink: 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .site-header__end {
    flex: 0 0 auto;
    gap: 6px;
    margin-left: 0;
  }

  .site-header-controls-btn {
    width: 32px;
    height: 32px;
  }

  .site-header-controls-btn svg {
    width: 18px;
    height: 18px;
  }
}

.site-header-portrait-new-game-wrap {
  position: relative;
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  min-width: 0;
}

.site-header-portrait-new-game-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 1;
  min-width: 0;
  max-width: 42vw;
  padding: 6px 12px;
  border: none;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition:
    filter 120ms ease,
    transform 80ms ease;
}

@media (hover: hover) {
  .site-header-portrait-new-game-btn:hover {
    filter: brightness(1.06);
  }
}

.site-header-portrait-new-game-btn:active {
  transform: scale(0.97);
}

.site-header-portrait-new-game-btn:focus-visible {
  outline: 2px solid var(--deep-color);
  outline-offset: 2px;
}

@media (max-width: 360px) {
  .site-header__badge {
    padding: 1px 5px;
    font-size: 8px;
  }

  .site-header__logo {
    font-size: 26px;
  }

  .site-header-portrait-new-game-btn {
    max-width: 36vw;
    padding: 6px 9px;
    font-size: 13px;
  }
}

.new-game-menu-wrap {
  position: relative;
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
}

.landscape-new-game-wrap.new-game-menu-wrap,
.landscape-new-game-wrap .new-game-menu-wrap {
  display: flex;
  width: 100%;
}

.landscape-new-game-wrap .new-game-menu-wrap {
  width: 100%;
}

.landscape-new-game-wrap .landscape-new-game-btn {
  width: 100%;
}

.new-game-menu-panel {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  width: 90%;
  padding: 6px;
  border-radius: 10px;
  background: var(--tone-minus-one, #fff);
  border: 1px solid var(--tone-1, #d0d8e3);
  box-shadow: 0 8px 24px rgba(43, 51, 63, 0.16);
  box-sizing: border-box;
}

html[data-orientation='portrait'] .site-header-portrait-new-game-wrap .new-game-menu-panel {
  width: min(calc(var(--grid-size) * 0.7), calc(100vw - 24px));
  left: auto;
  right: 0;
  transform: none;
}

html[data-orientation='portrait'] .site-header-portrait-new-game-wrap .new-game-menu-panel--below .new-game-menu-caret {
  left: auto;
  right: calc(var(--new-game-caret-center-x, 24px) - 6px);
  transform: rotate(225deg);
}

@media (max-width: 900px) {
  .site-header-portrait-new-game-wrap .new-game-menu-panel {
    width: min(calc(var(--grid-size) * 0.7), calc(100vw - 24px));
    left: auto;
    right: 0;
    transform: none;
  }

  .site-header-portrait-new-game-wrap .new-game-menu-panel--below .new-game-menu-caret {
    left: auto;
    /* Центр стрелки = центр кнопки (панель шире кнопки, правая грань совпадает). */
    right: calc(var(--new-game-caret-center-x, 24px) - 6px);
    transform: rotate(225deg);
  }
}

.new-game-menu-panel[hidden] {
  display: none;
}

.new-game-menu-panel--above {
  bottom: calc(100% + 10px);
}

.new-game-menu-panel--below {
  top: calc(100% + 10px);
}

.new-game-menu-panel-inner {
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  background: var(--tone-11, #f5f7fb);
  overflow: hidden;
}

.new-game-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: none;
  background: none;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
  color: var(--tone-5, #6b7d95);
  cursor: pointer;
  box-sizing: border-box;
}

.new-game-menu-item:hover,
.new-game-menu-item.is-current {
  background: rgba(139, 196, 232, 0.35);
  color: var(--tone-10, #325aaf);
}

.new-game-menu-item__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.new-game-menu-item__icon img {
  display: block;
  width: 24px;
  height: 24px;
}

.new-game-menu-item__icon--svg {
  color: var(--tone-5, #6b7d95);
}

.new-game-menu-item:hover .new-game-menu-item__icon--svg,
.new-game-menu-item.is-current .new-game-menu-item__icon--svg {
  color: var(--tone-10, #325aaf);
}

.new-game-menu-item__icon--svg svg {
  display: block;
  width: 20px;
  height: 20px;
}

.new-game-menu-divider {
  height: 1px;
  margin: 0;
  background: var(--tone-1, #d0d8e3);
}

.new-game-menu-caret {
  position: absolute;
  left: 50%;
  width: 12px;
  height: 12px;
  background: var(--tone-11, #f5f7fb);
  border-right: 1px solid var(--tone-1, #d0d8e3);
  border-bottom: 1px solid var(--tone-1, #d0d8e3);
  transform: translateX(-50%) rotate(45deg);
  box-sizing: border-box;
}

.new-game-menu-panel--above .new-game-menu-caret {
  bottom: -7px;
}

.new-game-menu-panel--below .new-game-menu-caret {
  top: -7px;
  transform: translateX(-50%) rotate(225deg);
}

.site-header-controls-lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  min-width: 120px;
  max-height: 280px;
  overflow-y: auto;
  padding: 4px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.site-header-controls-lang-menu[hidden] {
  display: none;
}

.site-header-controls-lang-option {
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  text-align: start;
  color: var(--text);
  background: none;
  cursor: pointer;
}

.site-header-controls-lang-option:hover {
  background: var(--bg);
}

.site-header-controls-lang-option.is-active {
  color: #fff;
  background: var(--accent);
}

.site-header-controls-burger-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  min-width: 200px;
  padding: 6px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.site-header-controls-burger-menu[hidden] {
  display: none;
}

.site-header-controls-burger-menu-inner {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
}

.site-header-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  color: var(--text);
  background: none;
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
}

.site-header-menu-item:hover {
  background: var(--bg);
  color: var(--accent);
}

.site-header-menu-item.is-active,
.site-header-menu-item[aria-current='page'] {
  color: var(--accent);
  background: var(--bg);
}

.site-header-menu-item__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.site-header-menu-item:hover .site-header-menu-item__icon,
.site-header-menu-item.is-active .site-header-menu-item__icon,
.site-header-menu-item[aria-current='page'] .site-header-menu-item__icon {
  color: var(--accent);
}

.site-header-menu-item__icon svg {
  width: 20px;
  height: 20px;
}

.site-header-menu-item__label {
  flex: 1;
  white-space: nowrap;
}

.site-header-controls-burger-divider {
  border: none;
  height: 1px;
  margin: 6px 0;
  background: var(--border);
}

.site-header-controls-burger-theme-row {
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 4px 0;
}

.site-header-controls-burger-theme-option {
  width: 32px;
  height: 32px;
  padding: 5px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.site-header-controls-burger-theme-option:hover {
  background: var(--bg);
}

.site-header-controls-burger-theme-option.is-active {
  background: var(--accent);
  color: #fff;
}

.site-header-controls-burger-theme-option svg {
  width: 16px;
  height: 16px;
}

/* ---------- Main / game ---------- */

.site-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 16px;
}

.game-viewport {
  position: relative;
  background: var(--bg);
  overflow: hidden;
}

/* Reserve viewport size before JS (early-layout.js) — prevents CLS from 0-height collapse. */
@media (orientation: portrait) {
  html:not([data-orientation]) .game-viewport {
    aspect-ratio: 9 / 16;
    width: min(98vw, calc(88vh * 9 / 16));
    max-height: 88vh;
    height: auto;
  }
}

@media (orientation: landscape) {
  html:not([data-orientation]) .game-viewport {
    aspect-ratio: 16 / 9;
    width: min(96vw, 1200px, calc(82vh * 16 / 9));
    height: auto;
  }
}

/* Форма viewport следует ориентации окна (data-orientation выставляет engine/layout.js). */
[data-orientation='landscape'] .game-viewport {
  aspect-ratio: 16 / 9;
  width: min(96vw, 1200px, calc(82vh * 16 / 9));
  height: auto;
}

[data-orientation='portrait'] .game-viewport {
  aspect-ratio: 9 / 16;
  width: min(98vw, calc(88vh * 9 / 16));
  max-height: 88vh;
  height: auto;
}

.game-viewport > #app {
  position: absolute;
  inset: 0;
}

/* Не показываем игровой UI, пока не загружены locale, уровень и слоты расставлены. */
html:not(.game-ready) #app {
  visibility: hidden;
}

.site-main--game {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 8px;
}

.game-viewport__loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}

body.flutter-loaded .game-viewport__loading {
  display: none;
}

.game-viewport__spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

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

/* ---------- Description ---------- */

.site-description {
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.site-description__inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 20px;
}

.site-description__inner h1,
.site-description__inner h2 {
  margin: 0 0 16px;
  font-weight: 700;
  color: var(--text);
}

.site-description__inner h1 {
  font-size: 28px;
}

.site-description__inner h2 {
  margin-top: 32px;
  font-size: 22px;
}

.site-description__inner h2:first-child {
  margin-top: 0;
}

.site-description__inner p {
  margin: 0 0 16px;
  line-height: 1.65;
  color: var(--text);
  font-size: 16px;
}

.site-description__inner .site-description__lead {
  font-size: 17px;
}

.site-description__inner p:last-child {
  margin-bottom: 0;
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.site-footer__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-muted);
  font-size: 14px;
}

.site-footer__brand {
  color: var(--text);
  font-weight: 600;
}

/* ---------- Theme selector (dropdown, like language) ---------- */
.site-header-controls-theme {
  position: relative;
}

.site-header-controls-theme-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  padding: 6px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  display: flex;
  gap: 2px;
}

.site-header-controls-theme-menu[hidden] {
  display: none;
}

.site-header-controls-theme-option {
  width: 36px;
  height: 36px;
  padding: 6px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.site-header-controls-theme-option:hover {
  background: var(--bg);
}

.site-header-controls-theme-option.is-active {
  background: var(--accent);
  color: #fff;
}

.site-header-controls-theme-option svg {
  width: 18px;
  height: 18px;
}

@media (max-width: 480px) {
  .site-header__nav {
    gap: 16px;
    font-size: 15.4px;
  }

  .site-main {
    padding: 8px;
  }
}
