:root { font-family: system-ui, -apple-system, sans-serif; color: #f4f7ff; background: #0a1431; font-size: 16px; color-scheme: dark; }
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
body { margin: 0; background: #0a1431 url('../assets/coastal-workshop-v2.svg') center / cover no-repeat; }
button, input { font: inherit; }
button, .icon-control { color: #17264c; cursor: pointer; border: 1px solid #a4c4d2; background: #fff; min-height: 44px; min-width: 44px; font-weight: 750; touch-action: manipulation; box-shadow: 0 3px 0 #a9c5cf; }
button { border-radius: 14px; padding: .55rem .75rem; }
button:active, .icon-control:active { transform: translateY(2px); box-shadow: 0 1px 0 #a9c5cf; }
button:disabled { cursor: default; opacity: .48; }
button:focus-visible, input:focus-visible, summary:focus-visible, .icon-control:focus-within { outline: 3px solid #ffe06d; outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

.workshop {
  width: min(100%, 540px); height: 100svh; margin: auto;
  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));
  display: grid; grid-template-rows: auto minmax(0, 1fr); gap: clamp(5px, 1svh, 9px);
  position: relative; overflow: hidden; background: linear-gradient(160deg, #151e47f5, #0c3554f3 65%, #17193cf5);
}
.topbar, .brand, .header-actions, .scene-bar, .hud, .rail-heading, .tools, .help-top, .mentor-help { display: flex; align-items: center; }
.topbar { justify-content: space-between; gap: 8px; }
.brand { justify-content: center; gap: 5px; min-width: 0; }
.brand-mark { font-size: 1.65rem; color: #68ffe4; text-shadow: 0 2px 14px #20c5ba90; }
h1 { margin: 0; font-size: clamp(1.05rem, 5vw, 1.4rem); }
h2 { margin: 0; font-size: clamp(1.05rem, 4.8vw, 1.55rem); line-height: 1.2; }
h3 { margin: 0; font-size: .72rem; line-height: 1.1; }
p { line-height: 1.4; }
.header-actions { gap: 5px; }
.icon-control, .locale-control {
  width: 44px; height: 44px; padding: 0; border-radius: 50%; display: inline-grid; place-items: center;
  flex: 0 0 44px; font-size: 1.22rem;
}
.locale-control { font-size: .72rem; }
.settings { display: contents; }
.settings .icon-control { position: relative; background: #d9fff6; }
.settings .icon-control.is-active { background: #ffe58a; border-color: #fff0aa; }
.controls-toggle { display: none; }

.scene-bar {
  min-height: 54px; justify-content: space-between; gap: 8px; padding: 5px 8px;
  border: 1px solid #5e8bb8; border-radius: 17px; background: #182d58d9;
}
.scene-bar > img { width: 48px; height: 48px; flex: 0 0 48px; border-radius: 50%; background: #2d4774; }
.scene-copy { min-width: 0; flex: 1; }
.eyebrow { color: #8ff4e2; font-size: .68rem; font-weight: 800; margin: 0 0 2px; }
.hud { flex-direction: column; align-items: flex-end; gap: 1px; color: #ffe78c; font-size: .7rem; font-weight: 800; white-space: nowrap; }
.start-control { justify-self: center; min-height: 44px; padding-inline: 1.15rem; }
.primary { color: #10244e; background: linear-gradient(#a7ffec, #2bd5c7); border-color: #c6fff3; box-shadow: 0 3px 0 #057d87; }

.play-layout { min-height: 0; display: grid; grid-template-rows: auto auto auto auto auto; gap: 6px; direction: rtl; align-content: start; }
.board-zone { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto auto auto; place-items: center; direction: rtl; }
.stage {
  position: relative; align-self: center; width: min(100%, calc(100svh - 295px)); aspect-ratio: 1;
  background: radial-gradient(circle at 15% 5%, #9259e84a 0, transparent 45%), linear-gradient(145deg, #263673, #0d2146);
  border: 2px solid #60eeda; border-radius: clamp(18px, 6vw, 28px);
  box-shadow: 0 10px 24px #0007, 0 4px 0 #0d102d, 0 0 20px #20c5ba35; overflow: hidden; direction: ltr;
}
.workshop[data-phase='working'] .stage { animation: touch-pop .14s ease-out; }
.stage .postcard { position: absolute; left: 13.809524%; top: 13.809524%; width: 71.428571%; height: 71.428571%; pointer-events: none; visibility: hidden; }
html[data-surface-ready='true'] .stage .postcard { visibility: visible; }
.stage canvas { position: relative; width: 100% !important; height: 100% !important; display: block; }
#status { width: 100%; min-height: 1.4em; max-height: 2.8em; overflow: hidden; margin: 5px 0 1px; font-size: clamp(.72rem, 2.8vw, .86rem); text-align: center; }
.traveller-info { width: 100%; margin: 3px 0 0; font-size: .72rem; color: #b4fff0; font-weight: 700; text-align: center; }
.preview-strip { width: 100%; min-height: 1.3em; display: flex; gap: 5px; justify-content: center; overflow: hidden; }
.preview-info { margin: 0; font-size: .68rem; color: #c8f9ef; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.artisan-rail {
  height: clamp(92px, 14svh, 120px); direction: rtl; display: grid; grid-template-columns: 2fr 3fr; gap: 7px;
  padding: 6px; border: 1px solid #57dcc7; border-radius: 22px; background: linear-gradient(#164c63, #12344f);
  box-shadow: inset 0 -5px 0 #0a293d, inset 0 1px 0 #98ffea55;
}
.rail-group { min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 4px; }
.rail-heading { min-height: 18px; justify-content: space-between; gap: 3px; color: #dffff8; }
.rail-heading span { font-size: .62rem; color: #ffe78c; }
.queues, .bench { min-height: 0; display: grid; gap: 5px; }
.queues { grid-template-columns: repeat(2, minmax(44px, 1fr)); }
.bench { grid-template-columns: repeat(3, minmax(44px, 1fr)); }
.artisan {
  width: 100%; min-width: 44px; min-height: 44px; padding: 3px; display: grid; place-items: center; gap: 1px;
  border-radius: 16px; position: relative; overflow: hidden;
}
.artisan.blue { background: linear-gradient(145deg, #5d7dff, #3555cb); color: #fff; border-color: #2948b8; box-shadow: 0 3px 0 #233b96, inset 0 2px 0 #b6c6ff; }
.artisan.coral { background: linear-gradient(145deg, #ff98b4, #f45383); color: #18284d; border-color: #b43068; box-shadow: 0 3px 0 #a52855, inset 0 2px 0 #ffd0de; }
.artisan.empty { color: #bcece4; background: #143244; border: 1px dashed #7ac5b8; box-shadow: none; }
.artisan .pattern { display: grid; place-items: center; width: 1.65rem; height: 1.65rem; border-radius: 50%; background: #ffffff2c; border: 1px solid #ffffff85; font-size: 1.1rem; }
.artisan .ammo { min-width: 1.15rem; padding: 0 4px; border-radius: 999px; background: #081530b8; color: #fff; font-size: .68rem; font-variant-numeric: tabular-nums; }
.artisan .name { display: none; }
.workshop[data-started='true'] .scene-bar,
.workshop[data-started='true'] .start-control,
.workshop[data-started='true'] .preview-strip { display: none; }
.workshop[data-started='true'] { grid-template-rows: minmax(0, 1fr); gap: 0; }
.workshop[data-started='true'] .topbar { display: none; }
.workshop[data-started='true'][data-controls-open='true'] .topbar {
  display: flex; position: absolute; z-index: 8; inset: max(4px, env(safe-area-inset-top)) 4px auto; padding: 4px; border-radius: 18px;
  background: #10284cf2; box-shadow: 0 10px 30px #0009;
}
.workshop[data-started='true'] .controls-toggle {
  display: inline-grid; position: absolute; z-index: 9; left: max(5px, env(safe-area-inset-left)); right: auto; bottom: max(5px, env(safe-area-inset-bottom));
  background: linear-gradient(#fff6bd, #ffe16c);
}
.workshop[data-started='true'][data-controls-open='true'] .controls-toggle { bottom: auto; top: max(56px, calc(env(safe-area-inset-top) + 50px)); }
.workshop[data-started='true'] .play-layout { grid-template-rows: min(100%, calc(100vw - 20px)) 330px; gap: 4px; }
.workshop[data-started='true'] .board-zone { display: grid; grid-template-rows: minmax(0, 1fr); }
.workshop[data-started='true'] .stage { width: 100%; }
.workshop[data-started='true'] #status,
.workshop[data-started='true'] .traveller-info { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
.workshop[data-started='true'] .artisan-rail {
  height: 330px; grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 44px; gap: 6px; padding: 0;
}
.workshop[data-started='true'] .rail-group { display: block; min-height: 0; }
.workshop[data-started='true'] .rail-heading { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
.workshop[data-started='true'] .queues,
.workshop[data-started='true'] .bench { width: 100%; height: 100%; gap: 6px; }
.workshop[data-started='true'] .artisan { height: 100%; padding: 8px; border-radius: 20px; grid-template-columns: auto 1fr auto; align-content: center; }
.workshop[data-started='true'] .artisan .name { display: block; font-size: clamp(.68rem, 3vw, .92rem); font-weight: 850; }
.workshop[data-started='true'] .artisan .pattern { width: clamp(2rem, 8vw, 2.8rem); height: clamp(2rem, 8vw, 2.8rem); font-size: clamp(1.2rem, 5vw, 1.8rem); }
.workshop[data-started='true'] .artisan .ammo { font-size: clamp(.78rem, 3.4vw, 1rem); padding: 3px 7px; }
.workshop[data-started='true'] .play-layout {
  grid-template-rows: min(calc(100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 56px), calc((100vw - 20px) * 1.835)) 48px;
}
.workshop[data-started='true'] .stage { width: 100%; height: 100%; aspect-ratio: auto; }
.workshop[data-started='true'] .artisan-rail {
  height: 48px; grid-template-columns: 2fr 3fr; grid-template-rows: 1fr; gap: 4px; padding: 0; border-radius: 16px;
}
.workshop[data-started='true'] .rail-group { display: block; }
.workshop[data-started='true'] .queues,
.workshop[data-started='true'] .bench { height: 100%; gap: 3px; }
.workshop[data-started='true'] .artisan { height: 100%; min-height: 44px; padding: 2px; border-radius: 12px; grid-template-columns: 1fr; }
.workshop[data-started='true'] .artisan .name { display: none; }
.workshop[data-started='true'] .artisan .pattern { width: 1.5rem; height: 1.5rem; font-size: 1rem; }
.workshop[data-started='true'] .artisan .ammo { position: absolute; inset-inline-end: 3px; bottom: 2px; font-size: .66rem; padding: 0 4px; }
.workshop[data-started='true'] .tools {
  position: absolute; z-index: 8; inset-inline: 8px; bottom: max(56px, calc(env(safe-area-inset-bottom) + 50px)); padding: 8px; border-radius: 18px;
  background: #10284cf2; box-shadow: 0 10px 30px #0009; opacity: 0; visibility: hidden; pointer-events: none;
}
.workshop[data-started='true'][data-controls-open='true'] .tools { opacity: 1; visibility: visible; pointer-events: auto; }
.coach-note { flex: 1 1 100%; margin: 0; color: #fff; font-size: .78rem; font-weight: 750; text-align: center; }
.workshop[data-celebrating='true'] .scene-bar img { animation: brush .7s ease-out; }
@media (hover: hover) { .artisan:not(:disabled):hover { filter: brightness(1.08); } }

.tools { direction: ltr; justify-content: center; gap: 9px; padding-block: 1px; }
.tools .icon-control { background: linear-gradient(#fff, #dceafa); }
.tools .hint-control { background: linear-gradient(#fff6bd, #ffe16c); }
.compact-warning { position: absolute; inset-inline: 10px; bottom: 58px; z-index: 3; margin: 0; padding: 5px 8px; border-radius: 10px; background: #622f36; font-size: .72rem; text-align: center; }

.help-sheet, .sheet {
  position: fixed; inset: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  z-index: 10; width: min(calc(100% - 24px), 510px); max-height: calc(100svh - 24px); margin: auto;
  padding: 18px; border-radius: 24px; color: #f4f7ff; background: linear-gradient(145deg, #253774, #102c4c);
  border: 2px solid #65efd3; box-shadow: 0 16px 44px #0009; overflow-y: auto;
}
.help-sheet::backdrop { background: #050b22c9; backdrop-filter: blur(3px); }
.help-sheet:not([open]) { display: none; }
.help-top { justify-content: space-between; gap: 12px; }
.mentor-help { gap: 10px; margin-block: 12px; padding: 9px; border-radius: 18px; background: #1c3059; }
.mentor-help img { border-radius: 50%; }
.mentor-help p { margin: 0; font-size: .9rem; }
.board-description { font-size: .82rem; }
.board-description summary { cursor: pointer; min-height: 44px; padding-block: 12px; }
.board-description p { margin: 0 0 10px; }
.queue-overview { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-block: 8px; }
.queue-column { min-width: 0; padding: 9px; border: 1px solid #5576b1; border-radius: 14px; background: #192d55; }
.queue-column strong, .queue-item { font-size: .76rem; overflow-wrap: anywhere; }
.queue-item { margin-block: 7px 0; border-inline-start: 4px solid #617dff; padding-inline-start: 7px; }
.queue-item.coral { border-color: #f56b95; }
.sheet { text-align: center; }
.sheet.celebrate { animation: glaze .7s ease-out; }
.collected-postcard { width: min(100%, 260px); height: auto; margin-block: 12px; border: 10px solid #356a91; border-radius: 18px; box-shadow: 0 5px 0 #09112b, 0 0 18px #20c5ba35; }
.stars { color: #ffe78c; font-size: 2rem; letter-spacing: .12rem; margin-block: 6px; text-shadow: 0 2px 12px #ffd35a55; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.result-actions button { flex: 1 1 110px; }
#result {
  inset: auto max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  height: auto; max-height: calc(100svh - max(12px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom)));
  display: grid; gap: 6px; padding: 12px;
}
#result .eyebrow, #result h2, #result #score { margin: 0; }
#result .eyebrow { font-size: .75rem; line-height: 1.25; }
#result .stars { margin: 0; font-size: 1.75rem; line-height: 1.1; }
#result #score { font-size: .85rem; line-height: 1.3; overflow-wrap: anywhere; }
#result .result-postcard {
  display: block; width: min(180px, 100%, max(96px, calc(100svh - 420px - env(safe-area-inset-top) - env(safe-area-inset-bottom))));
  height: auto; margin: 0 auto; object-fit: contain;
  border: 6px solid #356a91; border-radius: 18px; box-shadow: 0 5px 0 #09112b, 0 0 18px #20c5ba35;
}
#result .result-actions button { flex-basis: 100px; min-width: 44px; min-height: 44px; }
#save-warning { inset: auto 12px max(12px, env(safe-area-inset-bottom)); height: auto; }

.result-sparkles { position: absolute; inset: 0; pointer-events: none; }
.result-sparkles i { position: absolute; left: 50%; top: 30%; width: 7px; height: 7px; background: #ffe78c; opacity: 0; border-radius: 2px; --x: 0px; --y: 0px; }
.sheet.celebrate .result-sparkles i { animation: celebration-chip .8s ease-out both; }
.result-sparkles i:nth-child(3n) { background: #8affef; }
.result-sparkles i:nth-child(3n + 1) { background: #ffa6cd; }
.result-sparkles i:nth-child(1) { --x:-110px; --y:-35px; }.result-sparkles i:nth-child(2) { --x:-70px; --y:-68px; }
.result-sparkles i:nth-child(3) { --x:-25px; --y:-72px; }.result-sparkles i:nth-child(4) { --x:25px; --y:-72px; }
.result-sparkles i:nth-child(5) { --x:70px; --y:-68px; }.result-sparkles i:nth-child(6) { --x:110px; --y:-35px; }
.result-sparkles i:nth-child(7) { --x:100px; --y:30px; }.result-sparkles i:nth-child(8) { --x:65px; --y:70px; }
.result-sparkles i:nth-child(9) { --x:25px; --y:80px; }.result-sparkles i:nth-child(10) { --x:-25px; --y:80px; }
.result-sparkles i:nth-child(11) { --x:-65px; --y:70px; }.result-sparkles i:nth-child(12) { --x:-100px; --y:30px; }

@keyframes brush { 0% { transform: rotate(-4deg); } 40% { transform: rotate(5deg) translateY(-2px); } 100% { transform: none; } }
@keyframes glaze { from { box-shadow: 0 0 0 8px #62cec275; } to { box-shadow: 0 16px 44px #0009; } }
@keyframes touch-pop { 0% { transform: scale(.985); } 60% { transform: scale(1.006); } 100% { transform: none; } }
@keyframes celebration-chip { 0% { opacity:0; transform:translate(0,0) scale(.4); } 15% { opacity:1; } 100% { opacity:0; transform:translate(var(--x),var(--y)) rotate(180deg) scale(.5); } }
@media (max-height: 620px) {
  .workshop { gap: 4px; padding-block: 5px; }
  .scene-bar { display: none; }
  .start-control { min-height: 44px; height: 44px; }
  .stage { width: min(100%, calc(100svh - 295px)); }
  .artisan-rail { height: 80px; padding: 4px; }
  .rail-heading { min-height: 14px; }
  .artisan { border-radius: 12px; }
  .artisan .pattern { width: 1.35rem; height: 1.35rem; font-size: .9rem; }
  .preview-strip { display: none; }
  #status { max-height: 2.4em; margin-block: 2px 0; }
  .play-layout { gap: 4px; }
  .workshop[data-started='true'] { padding-block: 1px; }
  .workshop[data-started='true'][data-controls-open='true'] .topbar {
    display: flex; position: absolute; z-index: 8; inset: 4px 4px auto; padding: 4px; border-radius: 18px;
    background: #10284cf2; box-shadow: 0 10px 30px #0009;
  }
  .workshop[data-started='true'] .topbar .brand { display: none; }
  .workshop[data-started='true'] .controls-toggle { left: 5px; right: auto; bottom: 5px; }
  .workshop[data-started='true'][data-controls-open='true'] .controls-toggle { bottom: auto; top: 56px; }
  .workshop[data-started='true'] .play-layout { grid-template-rows: 465px 48px; gap: 2px; }
  .workshop[data-started='true'] .board-zone { grid-template-rows: 465px; }
  .workshop[data-started='true'] .stage { width: 300px; height: 465px; }
  .workshop[data-started='true'] .artisan-rail { height: 48px; grid-template-columns: 2fr 3fr; grid-template-rows: 1fr; }
  .workshop[data-started='true'] .artisan { padding: 5px; }
  .workshop[data-started='true'] .tools { bottom: 56px; }
}
@media (min-width: 700px) {
  .workshop { padding-inline: 18px; }
  .stage { width: min(100%, calc(100svh - 295px)); }
}
@media (prefers-reduced-motion: reduce) { html:not([data-reduced-motion='false']) *, html:not([data-reduced-motion='false']) *::before, html:not([data-reduced-motion='false']) *::after { animation: none !important; transition: none !important; } }
html[data-reduced-motion='true'] *, html[data-reduced-motion='true'] *::before, html[data-reduced-motion='true'] *::after { animation: none !important; transition: none !important; }
