:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #294b45;
  background: #f8f7f2;
  font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; }
button {
  font: inherit; color: inherit; cursor: pointer;
  border: 0; background: none; -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button:disabled { opacity: .3; cursor: default; }
button:focus-visible, canvas:focus-visible { outline: 3px solid #c47b46; outline-offset: 1px; }
.app {
  width: 100%; max-width: 600px; margin: auto;
  padding: max(4px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
}
.board-wrap { width: 100%; }
#viewport { width: 100%; aspect-ratio: 1; overflow: hidden; border-radius: 3px; background: #f9f9f4; touch-action: none; cursor: pointer; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.tray { padding: 8px 4px 0; }
#shelf {
  display: grid; grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-auto-rows: 34px; gap: 2px; padding: 7px 4px 4px;
  max-height: 119px; overflow-y: auto; overscroll-behavior-y: contain;
  scrollbar-width: thin; align-content: start;
  background: #f5edda; border: 1px solid #e8ddc3; border-radius: 10px;
  box-shadow: 0 2px 0 #ddcfb1;
}
.shelf-slot { display: grid; place-items: center; padding: 0; min-width: 0; min-height: 34px; border-radius: 5px; position: relative; }
.socket { width: 24px; height: 24px; border-radius: 28%; background: #e2d2b6; box-shadow: inset 0 3px 3px #876b3833, inset 0 -2px 1px #fff7e0; }
.shelf-jewel, .flying-jewel {
  clip-path: polygon(24% 0,76% 0,100% 24%,100% 76%,76% 100%,24% 100%,0 76%,0 24%);
  box-shadow: inset 0 3px 0 #ffffff55,inset 3px 0 0 #ffffff20,inset -3px 0 0 #00000018,inset 0 -4px 0 #00000035;
}
.shelf-jewel { position: relative; width: 24px; height: 24px; background: var(--color); filter: drop-shadow(0 2px 1px #17372b44); transition: transform .15s; }
.shelf-slot.selected .shelf-jewel { transform: translateY(-4px); filter: drop-shadow(0 5px 2px #17372b55); }
.shelf-jewel::before { content: ""; position: absolute; inset: 0; background: conic-gradient(from -45deg,#ffffff55 0deg 90deg,#00000012 90deg 180deg,#00000035 180deg 270deg,#ffffff20 270deg 360deg); }
.shelf-jewel::after { content: ""; position: absolute; inset: 19%; background: var(--color); clip-path: inherit; }
.flying-jewel { position: fixed; pointer-events: none; z-index: 10; }
.add-shelf { display: block; min-height: 44px; width: 100%; font-size: 12px; color: #3c614f; }
.shelf-scroll-note { margin: -4px 0 8px; text-align: center; font-size: 10px; color: #748478; }
dialog { border: 1px solid #e3e6da; background: #f8f7f2; color: #294b45; width: min(370px,calc(100% - 36px)); border-radius: 24px; padding: 32px; box-shadow: 0 20px 70px #193a4430; }
dialog::backdrop { background: #233e3b66; backdrop-filter: blur(5px); }
.close { position: absolute; right: 10px; top: 10px; width: 44px; height: 44px; font-size: 24px; }
dialog h2 { font: 30px Georgia,serif; margin-top: 14px; }
dialog p { font-size: 14px; line-height: 1.7; color: #748478; }
dialog .eyebrow { font-size: 9px; letter-spacing: 2px; }
dialog img { display: block; width: 100%; image-rendering: pixelated; border-radius: 10px; margin-top: 30px; }
.primary { background: #3f6d59; color: #fff; padding: 14px 22px; border-radius: 30px; margin-top: 12px; width: 100%; font-size: 13px; }
.puzzle-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 18px 0 6px; }
.puzzle-card { position: relative; }
.puzzle-pick { display: grid; gap: 4px; width: 100%; padding: 8px; border-radius: 14px; background: #fff; border: 1px solid #e3e6da; text-align: left; }
.puzzle-card.current .puzzle-pick { border-color: #3f6d59; box-shadow: 0 0 0 1px #3f6d59; }
dialog .puzzle-pick img, dialog .candidate img { margin: 0; border-radius: 6px; aspect-ratio: 1; }
.puzzle-title { font-size: 12px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.puzzle-progress { font-size: 10px; color: #748478; }
.puzzle-remove { position: absolute; top: 2px; right: 2px; width: 32px; height: 32px; border-radius: 50%; background: #f8f7f2e6; font-size: 18px; line-height: 1; }
.unlock input, .create input {
  font: inherit; font-size: 16px; color: inherit; width: 100%; min-height: 44px; padding: 10px 14px;
  border: 1px solid #d9ddcf; border-radius: 22px; background: #fff;
}
.unlock input:focus-visible, .create input:focus-visible { outline: 3px solid #c47b46; outline-offset: 1px; }
.candidates { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 14px 0 4px; }
.candidate { display: grid; gap: 4px; padding: 8px; border-radius: 14px; background: #fff; border: 1px solid #e3e6da; font-size: 10px; color: #748478; }
.create {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; margin: 0 auto; max-width: 600px;
  padding: 10px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: #f8f7f2f2; border-top: 1px solid #e3e6da; box-shadow: 0 -8px 30px #193a4418; backdrop-filter: blur(8px);
}
.create[hidden] { display: none; }
.create-row { display: flex; gap: 6px; align-items: center; }
#createGo { min-height: 44px; padding: 0 18px; border-radius: 22px; background: #3f6d59; color: #fff; font-size: 13px; flex: none; }
#createClose { width: 44px; height: 44px; font-size: 22px; flex: none; }
#createStatus { margin: 6px 6px 0; min-height: 1.4em; font-size: 12px; color: #748478; }
body.creating .app { padding-bottom: 120px; }
@media (min-width: 650px) { .app { padding-top: 12px; } }
@media (orientation: landscape) and (max-height: 600px) {
  .app { max-width: none; display: grid; grid-template-columns: minmax(0,1fr) minmax(160px,240px); align-items: center; gap: 8px; }
  .board-wrap { width: min(100%,calc(100svh - 16px)); justify-self: center; }
  .tray { align-self: center; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
