/* Shape Quest: Puzzle Picnic - styles.
   Palette: teal #278b87, cream #fff4da, honey #f6a63a, wood brown #b97b45. */

@font-face {
  font-family: Fredoka;
  src: url("../assets/fonts/fredoka.ttf");
  font-display: swap;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; overflow: hidden;
  font-family: Fredoka, system-ui, sans-serif; color: #3f414a; background: #b97b45;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 4px solid #f34f86; outline-offset: 2px; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
img { -webkit-user-drag: none; user-select: none; }
main { height: 100dvh; background: url("../assets/images/ui/workshop.jpg") center/cover; }

/* ---------- loader ---------- */
#loading {
  position: fixed; inset: 0; z-index: 100; background: #3e9f9b; padding: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; color: #fff; text-align: center;
}
#loading img { width: 100px; animation: spin 3s linear infinite; }
#loading b { font-size: clamp(25px, 5vw, 38px); line-height: 1; color: #fff3c9; text-shadow: 0 4px #257572; }
#loading > div { width: 190px; height: 12px; background: #226f70; border-radius: 20px; overflow: hidden; }
#loading i { display: block; height: 100%; width: 0; background: #ffcf5d; transition: width 0.2s; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- shared buttons ---------- */
.big, .menu-grid button, .menu-icons button, .dialog button:not(#close), header button, .tray button, .tray-tools button, #peek {
  border: 2px solid #fff1ca; color: #fff; background: #41a7a2; border-radius: 13px;
  box-shadow: 0 4px #297d7a; font-weight: 700;
}
.big:active, .menu-grid button:active, .menu-icons button:active, .dialog button:not(#close):active, header button:active, .tray-tools button:active {
  transform: translateY(3px); box-shadow: 0 1px #297d7a;
}
.orange { background: #f6a63a !important; box-shadow: 0 4px #bd6f27 !important; }
button:disabled { opacity: 0.5; }

/* ---------- menu ---------- */
#menu {
  height: 100dvh; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 3% 5%;
  position: relative; isolation: isolate; overflow: hidden;
}
/* The full menu picture, unfiltered: no overlay, no zoom, no blur. */
#menu::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: url("../assets/images/ui/menu.jpg") center center / cover no-repeat;
}
.hero { max-width: 650px; text-shadow: 0 3px 5px #51361c; }
.tag { font-size: 13px; letter-spacing: 2px; color: #fff3cf; font-weight: 700; text-shadow: 0 2px #825537; }
h1 {
  font-size: clamp(42px, 6.8vw, 96px); line-height: 0.9; margin: 14px 0; color: #fff6d5; letter-spacing: -3px;
  text-shadow: 0 5px #a85733, 0 8px #593c34;
}
h1 em { font-style: normal; color: #ffca42; font-size: 0.76em; letter-spacing: -2px; white-space: nowrap; }
.hero p { color: #fff; font-size: clamp(16px, 2vw, 23px); font-weight: 700; margin: 0; }
.hero-plates { display: flex; align-items: center; margin-left: -20px; }
.hero-plates img { width: clamp(90px, 13vw, 170px); filter: drop-shadow(0 8px 5px #45240c77); }
.hero-plates img:nth-child(1) { transform: rotate(-15deg); }
.hero-plates img:nth-child(2) { transform: rotate(7deg); }
.hero-plates img:nth-child(3) { transform: rotate(15deg); }

.menu-card {
  width: min(430px, 100%); flex: none; padding: 22px 24px; text-align: center;
  background: linear-gradient(150deg, #fff8e8, #ffe3ae); border: 5px solid #fff9e9; border-radius: 25px;
  box-shadow: 0 8px #9c5e3e, 0 16px 40px #392716aa;
}
.menu-card small, .prompt small { color: #b17352; font-weight: 700; letter-spacing: 1.5px; font-size: 10px; }
.menu-card h2 { margin: 3px 0 12px; color: #396e70; }
.menu-card img { width: 24px; height: 24px; object-fit: contain; vertical-align: middle; margin-right: 5px; }
.big { width: 100%; min-height: 60px; font-size: 19px; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; margin-top: 13px; }
.menu-grid button { min-height: 54px; font-size: 13px; }
.menu-icons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-top: 9px; }
.menu-icons button { min-height: 58px; font-size: 10px; padding: 4px 2px; background: #5aa9a7; box-shadow: 0 4px #3b7f7d; }
.menu-icons img { display: block; margin: 0 auto 1px; }
.menu-icons button.off { background: #a9b8b8; box-shadow: 0 4px #7c8a8a; }
.menu-card p { margin: 10px 0 0; color: #997355; font-size: 11px; font-weight: 700; line-height: 1.2; }
.menu-card .tiny { font-size: 10px; }

/* ---------- game ---------- */
#game { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
header {
  display: flex; align-items: center; gap: 10px; flex: none; min-height: 60px; padding: 6px 14px;
  background: #278b87; color: #fff; border-bottom: 4px solid #ffdb8c;
}
header .icon { width: 44px; height: 44px; flex: none; padding: 5px; }
header .icon img { width: 24px; height: 24px; object-fit: contain; }
.titles { display: flex; flex-direction: column; min-width: 0; }
header small { font-size: 10px; letter-spacing: 1px; color: #ffe2a2; white-space: nowrap; }
header b { font-size: 17px; white-space: nowrap; }
.top-progress { margin-left: auto; width: min(240px, 28vw); font-size: 11px; white-space: nowrap; }
.top-progress div { height: 9px; background: #176967; border-radius: 10px; overflow: hidden; }
.top-progress i { display: block; height: 100%; width: 0; background: #ffcf5a; transition: width 0.3s; }
.pill { display: flex; align-items: center; gap: 4px; flex: none; background: #176967; border-radius: 20px; padding: 3px 10px 3px 4px; font-size: 14px; }
.pill img { width: 22px; height: 22px; }

.game-layout { display: flex; gap: 14px; flex: 1; min-height: 0; width: 100%; max-width: 1600px; margin: 0 auto; padding: 12px 4%; }
.workspace {
  display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; overflow: hidden;
  background: #fff4da; border: 4px solid #fff0ce; border-radius: 20px; box-shadow: 0 5px #9d673f;
}
.prompt { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 18px; background: #ffedca; }
.prompt > div:first-child { display: flex; flex-direction: column; min-width: 0; }
.prompt b { font-size: clamp(15px, 1.6vw, 21px); color: #456569; }
.prompt span { font-size: 12px; color: #947d65; }
.reference-box { width: 68px; height: 68px; display: grid; place-items: center; flex: none; }
.reference-box img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 2px 2px #8559); }
#peek { min-width: 57px; min-height: 45px; background: #efa044; box-shadow: 0 3px #ae692a; }

.assembly {
  flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: url("../assets/images/ui/table.jpg") center/cover;
}
.plate-slots {
  position: relative; height: min(85%, 285px); aspect-ratio: 1; overflow: hidden; border-radius: 50%;
  border: 4px dashed #fff8e8; filter: drop-shadow(0 8px 7px #542e1a66);
  background: repeating-linear-gradient(45deg, #fff3dcbb, #fff3dcbb 10px, #ffe4babb 10px, #ffe4babb 20px);
}
.plate-slots::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0.75; background: center / 100% 100% no-repeat;
}
.plate-slots[data-cuts="2"]::after { background-image: url("../assets/images/shapes/guide-2.png"); }
.plate-slots[data-cuts="3"]::after { background-image: url("../assets/images/shapes/guide-3.png"); }
.plate-slots[data-cuts="4"]::after { background-image: url("../assets/images/shapes/guide-4.png"); }
.plate-slots.shake { animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-7px); } 75% { transform: translateX(7px); } }
.puzzle-slot { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; background: transparent; color: #8d6b4d; }
.puzzle-slot:not(.filled):hover { background: #ffd65e88; }
.puzzle-slot.hinted { background: #ffd742cc; animation: pulse 0.45s infinite alternate; }
.puzzle-slot:focus-visible { background: #68d4bc99; outline: none; }
.puzzle-slot img { width: 100%; height: 100%; display: block; object-fit: fill; animation: pop 0.25s; }
@keyframes pulse { to { background: #ffffffbb; } }
@keyframes pop { from { transform: scale(1.12); } }
.puzzle-slot span {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 27px; height: 27px;
  line-height: 23px; font-size: 14px; font-weight: 700; color: #80573a; background: #fff3d9ed;
  border: 2px solid #d7a47b; border-radius: 50%; pointer-events: none;
}
.plate-slots[data-cuts="2"] [data-slot="0"] span { left: 25%; }
.plate-slots[data-cuts="2"] [data-slot="1"] span { left: 75%; }
.plate-slots[data-cuts="3"] [data-slot="0"] span { left: 50%; top: 17%; }
.plate-slots[data-cuts="3"] [data-slot="1"] span { left: 83%; top: 50%; }
.plate-slots[data-cuts="3"] [data-slot="2"] span { left: 25%; top: 70%; }
.plate-slots[data-cuts="4"] [data-slot="0"] span { left: 25%; top: 25%; }
.plate-slots[data-cuts="4"] [data-slot="1"] span { left: 75%; top: 25%; }
.plate-slots[data-cuts="4"] [data-slot="2"] span { left: 25%; top: 75%; }
.plate-slots[data-cuts="4"] [data-slot="3"] span { left: 75%; top: 75%; }
#feedback { background: #fff3db; border-radius: 20px; padding: 4px 15px; margin: 6px; color: #84644f; font-size: 13px; font-weight: 700; text-align: center; }

.tray { flex: none; background: #ffedca; padding: 5px 12px 9px; }
.tray-label { display: flex; justify-content: space-between; color: #9b6e4e; font-size: 11px; }
.tray-label span { font-weight: 400; }
#pieces { display: flex; justify-content: center; align-items: center; gap: 6px; height: clamp(82px, 13vh, 125px); }
#pieces button {
  flex: 0 1 auto; height: min(100%, 100px); aspect-ratio: 1; max-width: calc((100% - 45px) / 8); padding: 4px;
  background: #fff9e9aa; border: 2px solid #e4c596; border-radius: 12px; box-shadow: 0 3px #ce9e70; touch-action: none;
}
#pieces button.selected { outline: 3px solid #ff9f28; background: #fff4b0; }
#pieces button.used { visibility: hidden; }
#pieces button img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; transition: transform 0.15s; }
.tray-tools { display: flex; gap: 8px; justify-content: center; }
.tray-tools button { min-height: 32px; padding: 3px 14px; font-size: 11px; background: #e69350; box-shadow: 0 3px #ae692a; }

aside {
  width: 210px; flex: none; align-self: center; padding: 14px; text-align: center;
  background: #fff0d1; border: 4px solid #fff3d7; border-radius: 20px; box-shadow: 0 5px #9d673f;
}
.sidebar-title { font-size: 22px; font-weight: 700; color: #e07f35; line-height: 1; }
.sidebar-title em { font-style: normal; color: #319e9b; }
aside p { font-size: 12px; margin: 8px 0; color: #7a5f4a; }
#collection { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
#collection img { width: 100%; border-radius: 50%; background: #fff7e4; }
#collection img.locked { opacity: 0.22; }
#collection img.gold { box-shadow: 0 0 0 3px #ffd45c, 0 0 10px #ffd45c; }
#stats { font-size: 12px; margin-top: 8px; }
.badges { display: flex; gap: 4px; justify-content: center; margin: 6px 0; }
.badges span { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: #f5a33e; color: #fff; font-size: 12px; font-weight: 700; }
.badges span.locked { background: #e8d8c0; color: #b8a58c; }
.charms { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; }
.charms img { width: 26px; height: 26px; }
.charms img.locked { filter: grayscale(1); opacity: 0.3; }
aside .note { margin-top: 10px; background: #41a7a2; color: #fff; border-radius: 10px; padding: 8px; font-size: 10px; font-weight: 700; letter-spacing: 1px; }

#note {
  position: fixed; left: 50%; top: 72px; transform: translateX(-50%); z-index: 8; max-width: min(92vw, 540px);
  background: #f6a63a; color: #fff; font-weight: 700; padding: 8px 16px; border-radius: 16px; box-shadow: 0 4px #bd6f27;
  text-align: center; font-size: 14px; animation: drop 0.35s ease-out;
}
@keyframes drop { from { transform: translate(-50%, -20px); opacity: 0; } }

/* ---------- dialogs ---------- */
#overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 12px; background: #3a281c99; }
.dialog {
  position: relative; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; padding: 20px; text-align: center;
  background: linear-gradient(150deg, #fff8e8, #ffe3ae); border: 5px solid #fff9e9; border-radius: 26px; box-shadow: 0 8px #9c5e3e;
}
.dialog h2 { margin: 0 0 6px; font-size: 24px; color: #396e70; }
.dialog p { margin: 6px 0; font-size: 14px; }
#dialog-content > button { display: block; margin: 9px auto 0; min-width: 190px; min-height: 44px; padding: 6px 18px; }
.dialog .quiet, #repeat { display: block; margin: 9px auto 0; min-width: 190px; min-height: 36px; padding: 4px 18px; font-size: 12px; background: #8ab6b4; box-shadow: 0 4px #5f8a88; }
#close { position: absolute; right: 10px; top: 8px; width: 38px; height: 38px; border: 0; border-radius: 50%; background: #f6a63a; color: #fff; font-size: 24px; line-height: 1; box-shadow: none; }
.result-image { width: 110px; height: 110px; object-fit: contain; }
.dialog .stars { font-size: 38px; margin: 4px 0; color: #efa32d; letter-spacing: 4px; }
.gate { background: #fff0d0; border-radius: 12px; padding: 6px 10px; color: #a8642a; }
.tabs { display: flex; gap: 6px; justify-content: center; margin: 8px 0; }
.dialog .tabs button { flex: 1; min-width: 0; min-height: 52px; padding: 4px 2px; font-size: 10px; background: #8ab6b4; box-shadow: 0 3px #5f8a88; }
.dialog .tabs button.on { background: #41a7a2; border-color: #f6a63a; }
.tabs img { display: block; margin: 0 auto; width: 24px; height: 24px; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin-top: 8px; }
.dialog .level-grid button { min-width: 0; min-height: 56px; padding: 4px 2px; font-size: 15px; }
.level-grid button small { display: block; font-size: 10px; color: #ffe9a3; }
.dialog .level-grid button.boss { background: #e8893b; box-shadow: 0 4px #a85f23; }
.shop { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 8px; text-align: left; }
.charm { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; padding: 6px 8px; background: #fff; border: 3px solid #f5d3a7; border-radius: 14px; }
.charm img { width: 34px; height: 34px; }
.charm b { display: block; font-size: 13px; }
.charm small { display: block; font-size: 10px; line-height: 1.1; color: #7a6a58; }
.charm span { font-size: 10px; font-weight: 700; color: #319e9b; }
.dialog .charm button { min-width: 0; min-height: 30px; padding: 2px 10px; margin: 0; font-size: 11px; }
.charm.own { border-color: #9bd0ce; }
.confetti { position: fixed; top: -12px; width: 10px; height: 14px; border-radius: 3px; z-index: 40; pointer-events: none; animation: fall 2s linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(540deg); } }

/* ---------- responsive ---------- */
@media (max-width: 900px) { aside { display: none; } }
@media (max-width: 900px) {
  #menu { flex-direction: column; justify-content: center; gap: 10px; padding: 12px; }
  .hero { text-align: center; max-width: none; }
  .hero h1 { margin: 6px 0; font-size: clamp(34px, 11vw, 60px); }
  .hero p, .hero-plates { display: none; }
  .menu-card { padding: 14px 16px; width: min(440px, 100%); }
  .menu-card h2 { font-size: 19px; margin-bottom: 9px; }
  .big { min-height: 54px; font-size: 17px; }
  .menu-grid button { min-height: 48px; }
  .menu-icons button { min-height: 52px; }
  #menu::before { background-position: 30% center; }
}
@media (max-width: 760px) {
  header { gap: 6px; padding: 5px 8px; min-height: 52px; }
  header .icon { width: 38px; height: 38px; }
  header b { font-size: 14px; }
  .game-layout { padding: 6px 8px; }
  .prompt { padding: 5px 12px; }
  .reference-box { width: 48px; height: 48px; }
  #peek { font-size: 10px; min-width: 45px; min-height: 40px; }
  .plate-slots { height: min(80%, 240px); }
}
@media (max-width: 480px) {
  .titles small { display: none; }
  .top-progress { flex: 1; width: auto; margin-left: 4px; min-width: 0; }
  .top-progress span { overflow: hidden; text-overflow: ellipsis; display: block; font-size: 10px; }
}
@media (max-width: 480px) {
  .shop { grid-template-columns: 1fr; gap: 5px; }
  .charm { flex-direction: row; text-align: left; gap: 8px; padding: 4px 8px; }
  .charm img { width: 28px; height: 28px; flex: none; }
  .charm > div { flex: 1; }
  .dialog .charm button { flex: none; }
}
@media (max-width: 400px) {
  .pill { display: none; }
  .dialog { padding: 14px; }
  .dialog h2 { font-size: 20px; }
}
@media (max-width: 700px) and (orientation: portrait) {
  #pieces { display: grid; grid-template-columns: repeat(4, minmax(0, 64px)); grid-auto-rows: 58px; height: auto; min-height: 58px; gap: 4px; justify-content: center; }
  #pieces button { width: 100%; max-width: none; height: 58px; aspect-ratio: auto; padding: 2px; }
  .plate-slots { height: min(80%, 225px); }
  .assembly { min-height: 90px; }
}
@media (max-height: 460px) and (orientation: landscape) {
  #menu::before { background-position: center center; }
  #pieces { height: 65px; padding-right: 135px; }
  .tray { position: relative; padding: 2px 8px 5px; }
  .tray-tools { position: absolute; right: 12px; bottom: 8px; }
  .tray-tools button { font-size: 10px; }
  .plate-slots { height: 85%; }
  #feedback { position: absolute; bottom: 6px; right: 10px; margin: 0; font-size: 10px; }
  header { min-height: 44px; padding: 3px 10px; }
  header .icon { width: 34px; height: 34px; }
  .game-layout { padding: 5px 8px; }
  .prompt { padding: 3px 12px; }
  .prompt span, .prompt small { display: none; }
  .reference-box { width: 40px; height: 40px; }
  .tray-label { display: none; }
  .dialog { padding: 10px 16px; }
  .dialog h2 { font-size: 18px; margin-bottom: 2px; }
  .dialog p { margin: 3px 0; font-size: 12px; }
  #dialog-content > button { min-height: 34px; margin-top: 5px; }
  .result-image { width: 54px; height: 54px; }
  .dialog .stars { font-size: 26px; margin: 0; }
  .dialog .level-grid button { min-height: 40px; }
  .shop { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .charm { flex-direction: row; flex-wrap: wrap; justify-content: center; padding: 2px 5px; gap: 3px; }
  .charm img { width: 22px; height: 22px; }
  .charm small, .dialog p.gate { display: none; }
  .charm b { font-size: 11px; }
  .menu-card small, .menu-card .tiny, .menu-card h2 { display: none; }
  .menu-card { padding: 8px 14px; border-width: 4px; }
  .big { min-height: 38px; font-size: 15px; }
  .menu-grid { margin-top: 6px; gap: 6px; }
  .menu-grid button { min-height: 32px; }
  .menu-icons { margin-top: 6px; gap: 5px; }
  .menu-icons button { min-height: 34px; }
  .menu-icons span { display: none; }
}
@media (max-height: 360px) and (orientation: landscape) {
  #menu { padding: 4px 4%; }
  .hero h1 { font-size: 28px; margin: 2px 0; }
  .tag { display: none; }
  #menu-progress { display: none; }
  .dialog .tabs img, .level-grid button img { display: none; }
  .dialog .tabs button { min-height: 34px; }
  .dialog .level-grid button { min-height: 34px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
