/* Огни бухты — оформление. Без внешних шрифтов и ресурсов. */
:root {
  --font-title: Georgia, "Times New Roman", "PT Serif", serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 12px;
}
:root[data-theme="night"] {
  --bg1: #14212d;
  --bg2: #0b121a;
  --panel: #182737;
  --panel-2: #203245;
  --line: rgba(255, 255, 255, 0.10);
  --text: #e8eef4;
  --muted: #9db0c0;
  --accent: #e8b65a;
  --accent-ink: #1b1409;
  --btn: #203245;
  --btn-hover: #2a4057;
  --star-on: #e8b65a;
  --star-off: rgba(255, 255, 255, 0.16);
  --overlay: rgba(5, 10, 15, 0.66);
  --sea: #1b2d3e;
  --white: #f0ece0;
  --red: #b6483c;
  --hull: #5c4a3b;
  --lamp: #f5ce74;
  --mirror: #dde7ef;
  --beam-o: rgba(232, 170, 70, 0.5);
  --beam-i: #ffe7a6;
}
:root[data-theme="day"] {
  --bg1: #efe8d8;
  --bg2: #e2d9c4;
  --panel: #f6f1e4;
  --panel-2: #e9e1cd;
  --line: rgba(20, 45, 65, 0.16);
  --text: #1d2b38;
  --muted: #566877;
  --accent: #2a4a63;
  --accent-ink: #ffffff;
  --btn: #e9e1cd;
  --btn-hover: #ddd3ba;
  --star-on: #c98a2b;
  --star-off: rgba(20, 45, 65, 0.16);
  --overlay: rgba(30, 40, 50, 0.45);
  --sea: #a7bfc8;
  --white: #f6f1e4;
  --red: #b14033;
  --hull: #6b533f;
  --lamp: #f0b84a;
  --mirror: #f3f7fa;
  --beam-o: rgba(230, 150, 30, 0.55);
  --beam-i: #fff1c2;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg2);
  background: linear-gradient(180deg, var(--bg1), var(--bg2));
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.4;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
#app {
  position: fixed; inset: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button { font-family: inherit; color: inherit; cursor: pointer; }
button:focus-visible, .tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { display: block; }

.screen { position: absolute; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; }

/* ----- меню ----- */
.menu-inner {
  margin: auto; width: min(360px, 100%); padding: 24px 20px;
  display: flex; flex-direction: column; align-items: center; text-align: center;
}
.emblem { width: min(240px, 70vw); height: auto; margin-bottom: 18px; }
.em-sea { fill: var(--panel); stroke: var(--line); stroke-width: 2; }
.em-beam-o { stroke: var(--beam-o); stroke-width: 12; fill: none; stroke-linecap: butt; stroke-linejoin: round; }
.em-beam-i { stroke: var(--beam-i); stroke-width: 4; fill: none; stroke-linejoin: round; }
.em-white { fill: var(--white); }
.em-red { fill: var(--red); }
.em-lamp { fill: var(--lamp); }
.em-mirror { fill: var(--mirror); stroke: rgba(0, 0, 0, 0.55); stroke-width: 1.5; }
.em-rock { fill: var(--panel-2); stroke: var(--line); stroke-width: 2; stroke-linejoin: round; }
.em-hull { fill: var(--hull); stroke: rgba(0, 0, 0, 0.5); stroke-width: 1.5; }
h1 {
  font-family: var(--font-title); font-weight: 700; font-size: 40px; letter-spacing: 0.01em;
  margin: 0 0 6px;
}
.subtitle { margin: 0 0 26px; color: var(--muted); font-size: 16px; }
.menu-buttons { display: flex; flex-direction: column; gap: 10px; width: 100%; }

.btn {
  background: var(--btn); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 20px; font-size: 17px; font-weight: 600; min-height: 48px;
  transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: #e07a6c; }
:root[data-theme="day"] .btn.danger { color: #a8352a; }

/* ----- верхняя панель ----- */
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; min-height: 56px;
}
.topbar h2 {
  flex: 1; margin: 0; text-align: center; font-family: var(--font-title); font-size: 20px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center; flex: none;
  background: transparent; border: 0; border-radius: 10px;
}
.icon-btn:hover { background: var(--btn); }
.icon-btn svg, .tool-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.stars-total { min-width: 44px; text-align: right; padding-right: 8px; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }

/* ----- список уровней ----- */
.levels-list { flex: 1; overflow-y: auto; padding: 4px 16px 28px; -webkit-overflow-scrolling: touch; }
.chapter { max-width: 620px; margin: 0 auto 22px; }
.chapter-head { display: flex; align-items: baseline; justify-content: space-between; margin: 10px 2px 10px; }
.chapter-head h3 { margin: 0; font-family: var(--font-title); font-size: 19px; }
.chapter-head span { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.tile {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  font-family: var(--font-title); font-size: 20px; font-weight: 700; padding: 0;
}
.tile:hover:not(:disabled) { background: var(--btn-hover); }
.tile:disabled { opacity: 0.45; cursor: default; }
.tile.next { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.tile .mini-stars { display: flex; gap: 1px; }
.tile .mini-stars svg { width: 11px; height: 11px; }
.tile .lock { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; }
.star { fill: var(--star-off); }
.star.on { fill: var(--star-on); }

/* ----- игра ----- */
.statusbar {
  display: flex; justify-content: center; gap: 22px; padding: 0 16px 6px; color: var(--muted);
  font-size: 15px; font-variant-numeric: tabular-nums;
}
.statusbar b { color: var(--text); font-weight: 600; }
.tip {
  margin: 0 auto 6px; padding: 8px 14px; max-width: min(560px, calc(100% - 24px)); text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); font-size: 15px;
}
#board-wrap { flex: 1; min-height: 0; position: relative; }
#board { position: absolute; inset: 0; display: block; touch-action: manipulation; }
.toolbar {
  display: flex; justify-content: center; gap: 10px; padding: 8px 12px 14px;
}
.tool-btn {
  flex: 1; max-width: 150px; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--btn); border: 1px solid var(--line); border-radius: var(--radius); font-size: 13px; font-weight: 600;
}
.tool-btn:hover:not(:disabled) { background: var(--btn-hover); }
.tool-btn:disabled { opacity: 0.4; cursor: default; }

/* ----- модальные окна ----- */
.modal {
  position: absolute; inset: 0; background: var(--overlay); display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 10; animation: fade 0.18s ease-out;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(420px, 100%); max-height: 100%; overflow-y: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 22px 20px 18px; animation: rise 0.2s ease-out;
}
.modal-card h3 { margin: 0 0 12px; font-family: var(--font-title); font-size: 24px; text-align: center; }
.modal-card p { margin: 0 0 12px; color: var(--muted); }
.modal-card .actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.modal-card .actions.row { flex-direction: row; }
.modal-card .actions.row .btn { flex: 1; }
.win-stars { display: flex; justify-content: center; gap: 8px; margin: 4px 0 12px; }
.win-stars svg { width: 44px; height: 44px; }
.win-stars svg.on { animation: pop 0.35s ease-out both; }
.win-stars svg.on:nth-child(2) { animation-delay: 0.12s; }
.win-stars svg.on:nth-child(3) { animation-delay: 0.24s; }
.win-info { text-align: center; color: var(--muted); margin: 0 0 4px; font-variant-numeric: tabular-nums; }
.win-note { text-align: center; color: var(--muted); font-size: 14px; margin: 6px 0 0; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.setting:last-of-type { border-bottom: 0; }
.setting > span { font-weight: 600; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 8px 14px; font-size: 15px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.help-list { margin: 0 0 4px; padding: 0; list-style: none; display: grid; gap: 10px; }
.help-list li { display: grid; grid-template-columns: 28px 1fr; gap: 10px; color: var(--text); font-size: 15px; }
.help-list .n {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: 14px;
}
.help-keys { font-size: 13px; color: var(--muted); margin-top: 10px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } 70% { transform: scale(1.12); } to { transform: scale(1); opacity: 1; } }

@media (max-width: 420px) {
  h1 { font-size: 34px; }
  .grid { gap: 8px; }
  .tile { font-size: 18px; }
}
@media (max-height: 560px) {
  .emblem { display: none; }
  .subtitle { margin-bottom: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .modal, .modal-card, .win-stars svg.on { animation: none; }
}

/* Телефон в альбомной ориентации: кнопки уходят вбок, чтобы поле занимало всю высоту */
@media (max-height: 520px) and (orientation: landscape) {
  #screen-game.active {
    display: grid; grid-template-columns: 1fr 96px; grid-template-rows: auto auto auto 1fr;
  }
  #screen-game .topbar { grid-column: 1; grid-row: 1; min-height: 40px; padding: 2px 8px; }
  #screen-game .icon-btn { width: 38px; height: 38px; }
  #screen-game .topbar h2 { font-size: 17px; }
  #screen-game .statusbar { grid-column: 1; grid-row: 2; padding-bottom: 2px; font-size: 13px; }
  #screen-game .tip { grid-column: 1; grid-row: 3; padding: 4px 10px; font-size: 13px; margin-bottom: 2px; }
  #screen-game #board-wrap { grid-column: 1; grid-row: 4; }
  #screen-game .toolbar {
    grid-column: 2; grid-row: 1 / span 4; flex-direction: column; justify-content: center;
    padding: 8px 12px 8px 0; gap: 8px;
  }
  #screen-game .tool-btn { flex: none; max-width: none; min-height: 56px; }
  .menu-inner { padding: 10px 20px; }
}
