/* Leveler: game styles. Colors and fonts come from ../shared/eg-theme.css.
   Rule for this game: a tile never changes color when you hover over it or press it. It only changes when its level changes.
   (On a phone, a hover color can stay stuck after a tap and make a tile look like it is at the wrong level.)
   So there are no :hover rules anywhere in this file. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 20px;
  line-height: 1.45;
}
[hidden] { display: none !important; }

.noscript { margin: 16px; padding: 16px; border: 2px solid var(--ink); border-radius: 12px; background: #FBF6EA; color: #1F3246; }

:focus-visible { outline: 4px solid var(--mid); outline-offset: 2px; }
[tabindex="-1"]:focus, [tabindex="-1"]:focus-visible { outline: none; }

/* ---------- extra colors used only by this game ---------- */
:root {
  --tile-top: #FBF6EA;
  --tile-mid: #DDBE86;
  --tile-floor: #8A7A5A;
  --tile-edge: #1F3246;
  --bar-fill: #E0792B;
}
:root[data-contrast="high"] {
  --tile-top: #FFFFFF;
  --tile-mid: #BDBDBD;
  --tile-floor: #000000;
  --tile-edge: #000000;
  --bar-fill: #C25400;
}

/* ---------- header and settings ---------- */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px 4px;
}
.name-block { min-width: 0; display: flex; align-items: baseline; flex-wrap: wrap; column-gap: 12px; }
.name { margin: 0; font-family: var(--font-head); font-weight: 800; font-size: 30px; line-height: 1.15; }
.kind { margin: 0; white-space: nowrap; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.kind::before { content: ""; width: 14px; height: 14px; border-radius: 50%; background: var(--dot); border: 2px solid var(--ink); flex: none; }

.textlink {
  color: var(--ink); font: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 4px;
  min-height: 44px; display: inline-flex; align-items: center; padding: 0 4px; white-space: nowrap;
}

.settings {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 4px 16px 10px; border-bottom: 2px solid var(--rule);
}
.settings-label { font-size: 18px; margin-right: 2px; }

/* ---------- buttons ---------- */
.btn {
  min-height: 52px; padding: 8px 16px;
  font: inherit; font-weight: 700; font-size: 20px; line-height: 1.2;
  color: var(--ink); background: var(--card);
  border: 2px solid var(--ink); border-radius: 12px; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.btn.small { min-height: 46px; font-size: 18px; padding: 6px 14px; }
.btn.primary { background: var(--ink); color: var(--card); }
.btn[aria-disabled="true"] { opacity: 0.5; border-style: dashed; cursor: default; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--card); }

/* ---------- layout ---------- */
main { padding: 12px 6px 40px; max-width: 900px; margin: 0 auto; }
.h2 { margin: 8px 0 4px; font-family: var(--font-head); font-weight: 800; font-size: 28px; line-height: 1.15; }
.h3 { margin: 0 0 8px; font-family: var(--font-head); font-weight: 800; font-size: 24px; line-height: 1.15; }
.panel { background: var(--card); border: 2px solid var(--rule); border-radius: 20px; padding: 4px 18px; margin: 0 0 12px; max-width: 760px; }
.howto { margin: 14px 0; font-size: 20px; }
.titlerow { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.count { margin: 0 0 8px; font-size: 18px; min-height: 26px; }

details.howto-panel { padding: 0 18px; }
details.howto-panel summary {
  min-height: 52px; display: flex; align-items: center; cursor: pointer;
  font-family: var(--font-head); font-weight: 800; font-size: 24px;
}
details.howto-panel[open] summary { border-bottom: 2px solid var(--rule); margin-bottom: 4px; }

.msg {
  margin: 0 0 8px; padding: 8px 12px;
  font-size: 19px; line-height: 1.35;
  background: var(--card); border: 2px solid var(--rule); border-radius: 12px;
}
.msg:empty { display: none; }

/* ---------- choosing a puzzle ---------- */
.picker { margin: 0 0 14px; padding: 0 4px; }
.sizes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 520px; }
.sizes .btn { min-height: 56px; }
.nums { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; max-width: 520px; margin-top: 8px; }
.nums .btn {
  min-height: 62px; padding: 4px 2px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  line-height: 1.1;
}
.nums .btn .num { font-size: 22px; }
.nums .btn .state { font-size: 15px; font-weight: 400; min-height: 17px; }
.nums .btn[aria-pressed="true"] .state { font-weight: 700; }

/* ---------- the board ---------- */
.board-wrap {
  background: var(--iconbg); border: 2px solid var(--ink); border-radius: 16px;
  padding: 18px 10px 12px; overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch; touch-action: manipulation;
}
.grid { display: grid; justify-content: center; gap: var(--gap, 10px); margin: 0 auto; }

.tile {
  position: relative; width: var(--ts, 80px); height: var(--ts, 80px); margin: 0; padding: 0;
  border: 2px solid var(--tile-edge); border-radius: 10px;
  font: inherit; color: var(--ink); cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
/* Raised tiles have a hard edge underneath; the floor tile looks pressed in. */
.tile[data-l="2"] { background: var(--tile-top);   transform: translateY(-6px); box-shadow: 0 6px 0 var(--tile-edge); }
.tile[data-l="1"] { background: var(--tile-mid);   transform: translateY(-3px); box-shadow: 0 3px 0 var(--tile-edge); }
.tile[data-l="0"] { background: var(--tile-floor); transform: none;             box-shadow: inset 0 6px 0 rgba(0, 0, 0, 0.35); }
:root[data-contrast="high"] .tile[data-l="0"] { box-shadow: none; }

.pips, .sw { display: flex; justify-content: center; gap: 4px; }
.pips { position: absolute; left: 0; right: 0; bottom: 9%; pointer-events: none; }
.pips i, .sw i {
  display: block; width: calc(var(--ts, 80px) * 0.2); height: calc(var(--ts, 80px) * 0.1); min-width: 10px; min-height: 6px;
  border: 2px solid var(--tile-edge); border-radius: 2px; background: transparent;
}
.pips i.on, .sw i.on { background: var(--bar-fill); }
.tile[data-l="0"] .pips i { border-color: var(--tile-top); }
:root[data-contrast="high"] .tile[data-l="0"] .pips i.on { background: #FFFFFF; }

.tile.hint { outline: 6px solid var(--dot); outline-offset: 3px; }
.tile.pop { animation: pop 0.3s ease-in-out; }
@keyframes pop { 0%, 100% { scale: 1; } 50% { scale: 1.08; } }

/* ---------- the key ---------- */
.key { list-style: none; margin: 14px 0 6px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 22px; justify-content: center; font-size: 18px; }
.key li { display: flex; align-items: center; gap: 8px; }
.sw {
  --ts: 40px; width: 52px; height: 36px; align-items: flex-end; padding-bottom: 5px; gap: 3px;
  border: 2px solid var(--tile-edge); border-radius: 7px;
}
.sw i { min-width: 8px; width: 10px; height: 6px; border-width: 1.5px; }
.sw[data-l="2"] { background: var(--tile-top); }
.sw[data-l="1"] { background: var(--tile-mid); }
.sw[data-l="0"] { background: var(--tile-floor); }
.sw[data-l="0"] i { border-color: var(--tile-top); }
:root[data-contrast="high"] .sw[data-l="0"] i.on { background: #FFFFFF; }

/* ---------- buttons under the board ---------- */
.dock {
  position: sticky; bottom: 0; z-index: 50;
  margin-top: 10px; padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  background: var(--bg); border-top: 2px solid var(--rule);
}
.dock.static { position: static; }
.controls { display: grid; gap: 8px; }
.controls.three-up { grid-template-columns: repeat(3, 1fr); }
.controls.two-up { grid-template-columns: 1fr 1fr; }
.controls .btn { min-height: 56px; font-size: 19px; padding: 6px 4px; }
.confirm-text { margin: 0 0 8px; font-size: 19px; }
@media (max-height: 480px) { .dock { position: static; } }

/* ---------- finished ---------- */
.clear { margin-top: 16px; padding: 18px; }
.clear-title { margin: 0 0 6px; font-family: var(--font-head); font-weight: 800; font-size: 30px; line-height: 1.15; }
.clear p { margin: 0 0 14px; }
.clear-buttons { display: grid; gap: 8px; }
.clear-buttons .btn { min-height: 56px; }

@media (prefers-reduced-motion: reduce) {
  .tile.pop { animation: none; }
}
