@font-face { font-family: Brandon; src: url('../../assets/fonts/Brandon_med.otf') format('opentype'); font-weight: 400 500; font-display: swap; }
@font-face { font-family: Brandon; src: url('../../assets/fonts/Brandon_bld.otf') format('opentype'); font-weight: 600 900; font-display: swap; }

:root {
  font-family: Brandon, 'Trebuchet MS', sans-serif;
  font-synthesis: none;
  --primary: #e36b42;
  --secondary: #5e210d;
  --background: #e6bcae;
  color: var(--secondary);
  background: var(--background);
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
body { background: var(--background); }
button, a { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--secondary); outline-offset: 5px; }
h1:focus { outline: none; }
h1, h2, p { margin: 0; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
#app { height: 100%; }
.app-shell {
  width: min(100%, 1080px); height: 100dvh; margin: auto;
  padding: max(24px, env(safe-area-inset-top)) max(28px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(28px, env(safe-area-inset-left));
  display: flex; flex-direction: column;
}
/* The frame stays small, even on a wide screen. The game gets the breathing room. */
.header { width: min(100%, 760px); margin-inline: auto; min-height: 60px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; flex-shrink: 0; }
.brand { position: relative; color: white; font-size: 30px; font-weight: 700; line-height: 1.2; padding-bottom: 8px; }
.brand span { position: absolute; bottom: 0; left: 2px; width: 17px; height: 2px; background: var(--primary); }
.back-link { display: inline-flex; gap: 7px; align-items: center; justify-self: start; font-size: 17px; min-height: 44px; opacity: .65; }
.back-link svg { width: 19px; }
.utilities { display: flex; justify-self: end; gap: 5px; }
.icon-button { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 11px; border-radius: 50%; color: var(--secondary); opacity: .65; }
.icon-button:disabled { opacity: .2; background: none; }
.icon-button.language { font-size: 13px; letter-spacing: .08em; }
.pill { display: inline-flex; justify-content: center; align-items: center; gap: 12px; min-height: 56px; border-radius: 100px; padding: 12px 30px; background: var(--primary); color: white; font-size: 23px; line-height: 1.2; }
.pill.light { color: var(--primary); background: white; }
.pill svg { width: 18px; height: 18px; }

/* A pocket-sized title screen, not a landing page. */
.home-view { flex: 1; min-height: 0; display: grid; place-items: center; padding-bottom: 48px; }
.home-composition { position: relative; width: 244px; }
.wordmark { position: relative; margin: 0 0 45px; }
.wordmark h1 { color: white; font-size: 104px; line-height: 1.05; font-weight: 700; letter-spacing: -3px; }
.wordmark h1::after { content: ''; display: block; background: var(--primary); width: 40px; height: 3px; margin: 18px 0 0 7px; }
.home-choices { display: grid; gap: 16px; }
.home-help { display: block; text-align: center; font-size: 18px; padding: 12px 0; margin-top: 28px; opacity: .7; }

/* Context, board and controls form a single centered composition at every width. */
.game-view { flex: 1; min-height: 0; display: grid; place-items: center; }
.play-space { width: min(100%, 640px); height: min(100%, 560px); display: grid; grid-template-rows: 82px minmax(0, 1fr) 100px; }
.game-heading { display: flex; flex-direction: column; justify-content: end; align-items: center; padding-bottom: 4px; gap: 9px; text-align: center; }
.level-title { color: white; font-size: 36px; line-height: 1; font-weight: 500; font-variant-numeric: tabular-nums; }
.level-title small { color: var(--secondary); opacity: .4; font-size: 17px; }
.zen-title { color: white; font-size: 32px; font-weight: 500; }
.move-budget { font-size: 16px; opacity: .65; }
.board-stage { min-width: 0; min-height: 0; display: flex; justify-content: center; align-items: center; }
.board { --tile-size: 50px; display: grid; grid-template-columns: var(--tile-size) calc(var(--columns) * var(--tile-size)) var(--tile-size); grid-template-rows: var(--tile-size) calc(var(--rows) * var(--tile-size)) var(--tile-size); user-select: none; -webkit-user-select: none; }
.tiles { position: relative; grid-column: 2; grid-row: 2; display: grid; grid-template-columns: repeat(var(--columns), var(--tile-size)); grid-template-rows: repeat(var(--rows), var(--tile-size)); touch-action: none; }
.tile { width: var(--tile-size); height: var(--tile-size); padding: 0; position: relative; touch-action: none; border-radius: 10%; }
.tile-art { position: absolute; inset: 0; mask: var(--shape) center / contain no-repeat; -webkit-mask: var(--shape) center / contain no-repeat; pointer-events: none; }
.tile:focus-visible { outline-offset: -2px; z-index: 1; }
.edge { display: flex; }
.edge.top { grid-column: 2; grid-row: 1; }
.edge.bottom { grid-column: 2; grid-row: 3; }
.edge.left { grid-column: 1; grid-row: 2; flex-direction: column; }
.edge.right { grid-column: 3; grid-row: 2; flex-direction: column; }
.arrow { width: var(--tile-size); height: var(--tile-size); display: grid; place-items: center; padding: 0; opacity: .45; }
.arrow svg { width: min(19px, 48%); height: min(19px, 48%); }
.board .arrow:disabled { opacity: .15; }
.board .arrow.guided { opacity: .9; }
.board.solved .arrow { opacity: 0; pointer-events: none; }
.game-actions { display: flex; flex-direction: column; align-items: center; justify-content: start; padding-top: 6px; }
.move-actions { display: grid; grid-template-columns: auto auto; column-gap: 22px; justify-content: center; }
.move-action { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 5px; font-size: 16px; }
.move-action svg { width: 22px; height: 22px; }
.move-action:disabled { opacity: .3; }
.new-puzzle { grid-column: 1 / -1; justify-self: center; min-height: 36px; padding: 4px 8px; font-size: 15px; opacity: .65; }
.limit-message { min-height: 22px; font-size: 16px; margin-top: 9px; text-align: center; }
.completion { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.completion > p { color: var(--secondary); font-size: 24px; line-height: 1.2; }
.completion .pill { min-height: 44px; padding: 10px 24px; font-size: 19px; }
.tutorial-title { color: white; font-size: 29px; font-weight: 500; }
.tutorial-message { font-size: 19px; max-width: 350px; line-height: 1.3; }

/* Three small collections of the original tile shapes. All levels stay visible. */
.levels-view { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: clamp(12px, 5vh, 48px) 0 12px; }
.selection-heading { width: min(100%, 800px); margin-inline: auto; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.title { color: white; font-size: 38px; line-height: 1.25; font-weight: 500; }
.title::after { content: ''; display: block; width: 30px; height: 3px; background: var(--primary); margin: 12px 0 0 2px; }
.selection-progress { font-size: 20px; opacity: .6; font-variant-numeric: tabular-nums; }
.selection-progress span { opacity: .55; }
.level-groups { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--group-gap); }
.level-groups.horizontal { flex-direction: row; }
.level-group { flex-shrink: 0; }
.level-group h2 { font-weight: 400; font-size: 17px; height: 32px; line-height: 24px; padding-left: 4px; opacity: .6; }
.horizontal .level-group h2 { height: 40px; }
.level-grid { display: grid; grid-template-columns: repeat(var(--level-columns), var(--level-size)); }
.level { width: var(--level-size); height: var(--level-size); position: relative; display: grid; place-items: center; isolation: isolate; font-size: clamp(12px, calc(var(--level-size) * .33), 22px); padding: 0; color: var(--primary); }
.level::before { content: ''; position: absolute; z-index: -1; inset: 2px; background: white; mask: var(--level-shape) center / contain no-repeat; -webkit-mask: var(--level-shape) center / contain no-repeat; }
.level.completed { color: white; }
.level.completed::before { background: var(--primary); }
.level.locked { opacity: .27; }
.reset-progress { align-self: center; flex-shrink: 0; min-height: 44px; margin-top: 8px; padding: 8px 12px; font-size: .875rem; opacity: .45; }
.reset-progress:focus-visible { opacity: 1; }

/* Help is available on demand. Nothing competes with the pieces while playing. */
.dialog { max-width: 430px; width: calc(100% - 32px); max-height: calc(100dvh - 32px); overflow: auto; margin: auto; background: var(--background); color: var(--secondary); border: 0; border-radius: 24px; padding: 30px; box-shadow: 0 20px 100px #0001; }
.dialog::backdrop { background: #30203822; backdrop-filter: blur(8px); }
.dialog h2 { font-size: 30px; font-weight: 500; line-height: 1.2; color: white; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
.dialog-heading .icon-button { margin-right: -10px; }
.help-goal { font-size: 22px; margin-bottom: 22px; }
.help-rule { display: flex; align-items: center; gap: 18px; margin: 16px 0; font-size: 19px; }
.help-arrow { width: 32px; text-align: center; flex-shrink: 0; font-size: 30px; color: var(--primary); }
.help-detail { font-size: 16px; line-height: 1.5; opacity: .7; margin-top: 18px; }
.dialog > .pill { margin-top: 26px; }
.reset-description { margin-top: 16px; font-size: 1rem; line-height: 1.5; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }
.dialog-actions button { min-height: 44px; padding: 8px 18px; font-size: 1rem; }
.toast { position: fixed; left: 50%; top: max(90px, env(safe-area-inset-top)); transform: translate(-50%, -8px); pointer-events: none; opacity: 0; background: var(--secondary); color: white; padding: 10px 20px; border-radius: 50px; text-align: center; width: max-content; max-width: calc(100vw - 32px); font-size: 16px; z-index: 3; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.loading, .load-error { height: 100dvh; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 24px; }
.loading, .load-error h1 { color: white; font-size: 76px; font-weight: 700; }
.load-error p { font-size: 22px; }

@media (max-width: 600px) {
  .app-shell { padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .header { min-height: 48px; }
  .back-link { font-size: 15px; gap: 3px; }
  .utilities { gap: 0; }
  .utilities .icon-button { width: 38px; height: 44px; padding: 10px; }
  .brand { font-size: 28px; }
  .home-composition { width: 220px; }
  .wordmark h1 { font-size: 94px; }
  .home-view { padding-bottom: 38px; }
  .play-space { grid-template-rows: 76px minmax(0,1fr) 98px; }
  .levels-view { padding-top: 18px; }
  .title { font-size: 30px; }
  .selection-progress { font-size: 18px; }
  .tutorial-message { font-size: 17px; }
  .dialog { padding: 24px; }
}
@media (max-height: 650px) {
  .app-shell { padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .header { min-height: 44px; }
  .home-view { padding-bottom: 20px; }
  .wordmark { margin-bottom: 28px; }
  .wordmark h1 { font-size: 84px; }
  .wordmark h1::after { margin-top: 12px; }
  .home-help { margin-top: 18px; }
  .home-choices { gap: 12px; }
  .home-choices .pill { min-height: 50px; font-size: 21px; }
  .play-space { grid-template-rows: 64px minmax(0,1fr) 88px; }
  .game-heading { gap: 6px; }
  .level-title { font-size: 30px; }
  .completion { gap: 8px; }
  .completion > p { font-size: 21px; }
  .levels-view { padding-top: 12px; padding-bottom: 4px; }
  .title { font-size: 28px; }
}
@media (max-height: 450px) and (min-width: 500px) {
  .app-shell { padding: 8px 24px; }
  .header { min-height: 40px; }
  .brand { font-size: 24px; }
  .home-view { padding-bottom: 0; }
  .home-composition { width: 480px; display: grid; grid-template-columns: 210px 210px; gap: 0 50px; align-items: center; }
  .wordmark { margin: 0; grid-row: 1 / 3; }
  .wordmark h1 { font-size: 88px; }
  .home-help { grid-column: 2; font-size: 16px; margin-top: 8px; padding: 4px 0; }
  .play-space { grid-template-rows: 40px minmax(0,1fr) 48px; }
  .game-heading { flex-direction: row; gap: 16px; align-items: center; justify-content: center; padding: 0; }
  .level-title, .zen-title { font-size: 25px; }
  .move-budget { font-size: 13px; }
  .game-actions { padding: 0; }
  .move-actions { display: flex; gap: 16px; }
  .move-action { font-size: 15px; }
  .new-puzzle { min-height: 44px; }
  .limit-message { position: absolute; bottom: 18px; right: 30px; width: 130px; font-size: 13px; }
  .completion { flex-direction: row; gap: 16px; }
  .completion > p { font-size: 18px; }
  .completion .pill { min-height: 36px; font-size: 16px; padding: 8px 18px; }
  .tutorial-title { font-size: 21px; }
  .tutorial-message { font-size: 16px; }
  .levels-view { padding-top: 4px; }
  .title { font-size: 24px; }
  .title::after { margin-top: 6px; }
}

@media (pointer: coarse) { .keyboard-help { display: none; } }

/* Only pieces move. Their overlay leaves the actual controls and focus intact. */
.tile-motion-layer { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.tile-motion-art { position: absolute; width: var(--tile-size); height: var(--tile-size); transform-origin: 0 0; mask: var(--shape) center / contain no-repeat; -webkit-mask: var(--shape) center / contain no-repeat; will-change: transform, opacity; }

/* Brief entrances: a small diagonal ripple, with no wait before the first tile. */
@media (prefers-reduced-motion: no-preference) {
  .scene-enter .wordmark h1::after, .scene-enter .title::after {
    transform-origin: left center;
    animation: separator-enter 300ms cubic-bezier(.2,.7,.2,1) backwards;
  }
  .scene-enter .level-groups { animation: levels-enter 220ms cubic-bezier(.2,.7,.2,1) backwards; }
  .scene-enter .tile-art { animation: tile-enter 220ms cubic-bezier(.2,.7,.2,1) var(--entrance-delay) backwards; }
  .scene-enter .game-heading { animation: heading-enter 180ms ease-out backwards; }
}
@keyframes separator-enter { from { opacity: 0; transform: scaleX(.8); } to { opacity: 1; transform: scaleX(1); } }
@keyframes levels-enter { from { opacity: 0; transform: translateX(-4px); } to { opacity: 1; transform: translateX(0); } }
@keyframes tile-enter { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: scale(1); } }
@keyframes heading-enter { from { opacity: 0; } to { opacity: 1; } }
