@font-face { font-family: Fraunces; src: url(fonts/fraunces.woff2) format('woff2'); font-weight: 600; font-display: swap; }
:root {
  --night: #1b2e29; --leaf: #2c4a40; --paper: #f1e6cc; --paper-2: #e4d3ae; --ink: #2b2a22;
  --gold: #e9a93a; --moon: #46507f; --coral: #cf5b43; --moss: #6f9a4e;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--paper);
  background: radial-gradient(120% 90% at 50% 20%, #3a5e4f 0%, var(--leaf) 40%, var(--night) 100%);
  -webkit-user-select: none; user-select: none; touch-action: none;
}
h1, h2, .logo, #level-name, button.primary { font-family: Fraunces, Georgia, serif; font-weight: 600; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible, canvas:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
button:disabled { opacity: .45; cursor: default; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
header { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 1100px; margin: 0 auto; }
#level-title { flex: 1; display: flex; align-items: baseline; gap: 10px; min-width: 0; }
#level-name { font-size: 22px; white-space: nowrap; }
#chapter-name { color: var(--paper-2); opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toggles { display: flex; gap: 6px; }
button.icon { width: 40px; height: 40px; border-radius: 12px; background: rgba(241,230,204,.1); display: grid; place-items: center; }
button.icon:hover { background: rgba(241,230,204,.2); }
button.icon svg { width: 22px; height: 22px; fill: none; stroke: var(--paper); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
button.icon[aria-pressed="false"] svg { opacity: .55; }

main { flex: 1; min-height: 0; display: flex; align-items: stretch; justify-content: center; gap: 18px; width: 100%; max-width: 1100px; margin: 6px auto 0; }
#board-wrap { flex: 1; min-width: 0; min-height: 0; position: relative; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; border-radius: 14px; }
#panel { width: clamp(240px, 30vw, 330px); display: flex; flex-direction: column; justify-content: center; gap: 12px; min-height: 0; }
#tip { background: var(--paper); color: var(--ink); border-radius: 14px; padding: 10px 14px; min-height: 3.4em; display: flex; align-items: center; box-shadow: 0 4px 0 rgba(0,0,0,.2); }
h2 { font-size: 14px; color: var(--paper-2); margin-bottom: 5px; }
#suns, #tray { display: flex; gap: 8px; flex-wrap: wrap; }
.sunbtn { flex: 1 1 0; min-width: 54px; padding: 6px 2px 5px; border-radius: 12px; background: rgba(241,230,204,.1); display: flex; flex-direction: column; align-items: center; font-size: 12px; }
.sunbtn svg { width: 38px; height: 26px; }
.sunbtn[aria-pressed="true"] { background: var(--paper); color: var(--ink); box-shadow: 0 4px 0 var(--gold); }
.stonebtn { width: 56px; height: 66px; border-radius: 12px; background: rgba(241,230,204,.1); display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px; }
.stonebtn canvas { width: 44px; height: 56px; }
.stonebtn[aria-pressed="true"] { background: var(--paper); box-shadow: 0 4px 0 var(--gold); }
.stonebtn.used { opacity: .25; }
#actions { display: flex; gap: 8px; }
.tool { flex: 1; padding: 10px 4px; border-radius: 12px; background: rgba(241,230,204,.14); white-space: nowrap; }
.tool:hover:not(:disabled) { background: rgba(241,230,204,.26); }
.tool em { font-style: normal; background: var(--gold); color: var(--ink); border-radius: 9px; padding: 0 7px; font-size: 12px; font-weight: 700; margin-left: 2px; }

.sheet { position: fixed; inset: 0; background: rgba(14,26,23,.62); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 5; }
.sheet.title { background: radial-gradient(110% 90% at 50% 30%, #416a57, #182a25 80%); }
#win { background: rgba(14,26,23,.28); align-items: flex-end; }
.card { background: var(--paper); color: var(--ink); border-radius: 22px; padding: 18px 26px 20px; text-align: center; width: min(360px, 100%); max-height: 100%; overflow: auto; box-shadow: 0 18px 50px rgba(0,0,0,.4); display: flex; flex-direction: column; align-items: center; gap: 10px; animation: rise .35s ease-out; }
.card.wide { width: min(560px, 100%); }
.title .card { background: none; color: var(--paper); box-shadow: none; }
.title small { opacity: .65; font-size: 12px; }
@keyframes rise { from { transform: translateY(18px); opacity: 0; } }
.logo { font-size: clamp(44px, 12vmin, 68px); line-height: 1; letter-spacing: .01em; }
#emblem { width: min(280px, 60vw, 42vh); height: auto; }
button.primary { background: var(--gold); color: var(--ink); font-size: 20px; border-radius: 999px; padding: 10px 36px; box-shadow: 0 5px 0 #a9741f; flex: none; }
button.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 #a9741f; }
button.link { text-decoration: underline; opacity: .75; padding: 4px; }

#chapters { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.chapter h2 { color: var(--leaf); text-align: left; }
.grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.lvl { aspect-ratio: 1; border-radius: 10px; background: var(--paper-2); font-weight: 700; min-width: 0; }
.lvl.done { background: var(--moss); color: #fff; }
.lvl.here { box-shadow: 0 0 0 3px var(--gold); }
.rules { list-style: none; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.rules li { display: flex; gap: 12px; align-items: center; }
.key { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--moon); position: relative; }
.key.moss::after { content: ""; position: absolute; width: 13px; height: 13px; border-radius: 50%; left: 6px; top: 7px; box-shadow: 5px -2px 0 0 #f4efd8 inset; transform: rotate(15deg); }
.key.sun { background: var(--gold); }
.key.sun::after { content: ""; position: absolute; inset: 8px; border-radius: 50%; background: #fff6d6; }
.key.stone { border-radius: 12px 12px 5px 5px; width: 20px; margin: 0 4px; background: repeating-linear-gradient(#9a9a8c 0 6px, #4d4f49 6px 8px); }
.key.tick { background: #2f6b2c; }
.key.tick::after { content: ""; position: absolute; left: 10px; top: 6px; width: 7px; height: 13px; border: solid #fff; border-width: 0 3px 3px 0; transform: rotate(42deg); }
.keys { font-size: 13px; opacity: .8; }

#ad-shield { position: fixed; inset: 0; z-index: 9; background: rgba(10,18,16,.7); display: grid; place-items: center; }

/* portrait and narrow screens: board on top, controls below */
@media (max-aspect-ratio: 1/1) {
  main { flex-direction: column; gap: 8px; }
  #panel { width: 100%; max-width: 620px; margin: 0 auto; justify-content: flex-start; gap: 8px; flex: none; }
  #tip { min-height: 3.2em; padding: 7px 12px; font-size: 14px; }
  .group { display: flex; align-items: center; gap: 10px; }
  .group h2 { display: none; }
  #suns, #tray { flex: 1; justify-content: center; }
}
@media (min-aspect-ratio: 1/1) {
  /* keep the finished garden visible beside the card */
  #win { align-items: center; justify-content: flex-end; padding-right: max(16px, calc((100vw - 1100px) / 2 + 10px)); }
  #win .card { width: clamp(240px, 30vw, 330px); }
}
/* short landscape (phones, small portal frames) */
@media (min-aspect-ratio: 1/1) and (max-height: 520px) {
  #app { padding-top: 5px; padding-bottom: 5px; }
  button.icon { width: 32px; height: 32px; border-radius: 9px; }
  #level-name { font-size: 18px; }
  main { margin-top: 3px; gap: 12px; }
  #panel { gap: 6px; width: clamp(250px, 36vw, 340px); }
  #panel h2 { display: none; }
  #tip { font-size: 12.5px; min-height: 3em; padding: 5px 10px; border-radius: 10px; }
  .sunbtn { padding: 3px 2px; min-width: 46px; font-size: 11px; }
  .sunbtn svg { width: 30px; height: 20px; }
  .stonebtn { width: 44px; height: 52px; padding-bottom: 4px; }
  .stonebtn canvas { width: 34px; height: 44px; }
  .tool { padding: 6px 4px; }
  .card { padding: 10px 18px 14px; gap: 6px; }
  .card h1 { font-size: 22px; }
  .logo.logo { font-size: 42px; }
  #emblem { height: 34vh; width: auto; }
  .rules { font-size: 13px; gap: 4px; }
  .keys { font-size: 12px; }
  .lvl { aspect-ratio: auto; height: 30px; }
  .chapter h2 { margin-bottom: 2px; }
  #chapters { gap: 4px; }
}
@media (max-width: 460px) { .grid { grid-template-columns: repeat(5, 1fr); } #chapter-name { display: none; } .lvl { aspect-ratio: auto; height: 36px; } }
@media (prefers-reduced-motion: reduce) { .card { animation: none; } }
