/* Design studio */
.studio-body { background: #f4efe8; min-height: 100vh; }
.studio-top { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 20px; padding: 12px 22px; background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.studio-title { flex: 1; display: flex; flex-direction: column; line-height: 1.2; padding-left: 18px; border-left: 1px solid var(--line); }
.studio-title h1 { font-weight: 900; font-size: 18px; margin: 0; }
.studio-title small { color: var(--muted); font-size: 12px; font-weight: 600; }
.studio-actions { display: flex; gap: 8px; align-items: center; }
.studio-actions .btn { padding: 11px 20px; font-size: 15px; box-shadow: inset 0 0 0 2px var(--ink); }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: 22px; cursor: pointer; color: var(--ink); }
.icon-btn:hover { background: var(--paper-2); }
.icon-btn:disabled, .pbtn:disabled { opacity: .38; cursor: default; }
.studio-body :focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.studio-body [hidden] { display: none; }

.studio { display: grid; grid-template-columns: clamp(280px, 25vw, 350px) minmax(0, 1fr); min-height: calc(100svh - 69px); }
.tools { display: grid; grid-template-rows: auto auto minmax(0, 1fr); min-width: 0; background: #fff; border-right: 1px solid var(--line); position: sticky; top: 69px; height: calc(100dvh - 69px); }
.tool-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 15px; }
.tool-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; padding: 10px; background: var(--ink); }
.tool-tabs button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 48px; font: 700 12px var(--body); color: #f4edf8; background: transparent; border: 0; border-radius: 9px; padding: 5px 0; cursor: pointer; transition: background 0.2s, color 0.2s; }
.tool-tabs button span { font-size: 20px; line-height: 1; font-weight: 900; }
.tool-tabs button:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.tool-tabs button.on { background: var(--gold); color: var(--ink); }
.tool-panel { min-height: 0; overflow-y: auto; padding: 18px 16px; }
.tool-panel section { display: none; }
.tool-panel section.on { display: block; animation: fadeUp 0.25s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } }
.tool-panel h3 { font-size: 19px; font-weight: 900; margin: 0 0 6px; letter-spacing: -0.01em; }
.tool-panel h4 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin: 22px 0 10px; font-weight: 800; }
.hint { font-size: 13px; color: var(--muted); margin: 0 0 14px; line-height: 1.45; }

.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tpl-grid button { border: 0; background: none; padding: 0; cursor: pointer; text-align: left; font: 700 13px var(--body); color: var(--ink); }
.tpl-grid canvas { width: 100%; height: auto; border-radius: 10px; display: block; box-shadow: 0 1px 0 var(--line), 0 8px 18px -10px rgba(0, 0, 0, 0.35); transition: transform 0.2s, box-shadow 0.2s; margin-bottom: 6px; }
.tpl-grid button:hover canvas { transform: translateY(-3px) rotate(-1deg); box-shadow: 0 0 0 3px var(--gold), 0 14px 24px -12px rgba(0, 0, 0, 0.4); }

.drop { position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; border: 2px dashed #d8ccbd; border-radius: 18px; padding: 26px 16px; cursor: pointer; background: var(--paper); transition: border-color 0.2s, background 0.2s; }
.drop input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.drop:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--paper-2); }
.drop-ico { font-size: 34px; }
.drop b { font-size: 15px; }
.drop small { font-size: 12px; color: var(--muted); }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo-grid .hint { grid-column: 1 / -1; }
.photo-grid button { aspect-ratio: 1; border: 0; border-radius: 10px; background: center / cover no-repeat #eee; cursor: pointer; transition: transform 0.15s; }
.photo-grid button:hover { transform: scale(1.05); outline: 3px solid var(--gold); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { font: 700 13px var(--body); padding: 7px 12px; border-radius: 99px; border: 1.5px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.chips button:hover { border-color: var(--ink); }
.chips button.on { background: var(--ink); color: #fff; border-color: var(--ink); }

.txt-add { display: block; width: 100%; text-align: left; border: 1.5px solid var(--line); background: #fff; border-radius: 14px; padding: 14px 16px; margin-bottom: 8px; cursor: pointer; color: var(--ink); transition: border-color 0.15s, transform 0.15s; }
.txt-add:hover { border-color: var(--ink); transform: translateX(3px); }
.txt-add[data-text="title"] { font: 900 26px var(--display); letter-spacing: -0.02em; }
.txt-add[data-text="script"] { font: 28px "Mynerve", cursive; color: #e8452c; }
.txt-add[data-text="round"] { font: 700 20px "Comfortaa", sans-serif; color: #2b59c3; }
.txt-add[data-text="body"] { font: 15px "Literata", serif; }
.txt-add[data-text="label"] { font: 800 12px var(--body); letter-spacing: 0.2em; color: #7c3aed; }

.sticker-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.sticker-grid button { font-size: 26px; aspect-ratio: 1; border: 0; background: transparent; border-radius: 10px; cursor: pointer; transition: transform 0.15s, background 0.15s; }
.sticker-grid button:hover { background: var(--paper-2); transform: scale(1.2) rotate(-8deg); }
.shape-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.shape-grid button { border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 4px; cursor: pointer; }
.shape-grid button:hover { border-color: var(--ink); }
.shape-grid canvas { width: 100%; height: auto; display: block; }

.block-list { display: grid; gap: 8px; }
.block-list button { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1.5px solid var(--line); background: #fff; border-radius: 14px; cursor: pointer; font: 700 14px var(--body); color: var(--ink); text-align: left; transition: border-color 0.15s, transform 0.15s; }
.block-list button span { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--paper-2); font-size: 20px; }
.block-list button:hover { border-color: var(--ink); transform: translateX(3px); }

.draw-toggle { width: 100%; }
.draw-toggle.on { background: var(--accent); }
#brush-size { width: 100%; accent-color: var(--ink); }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatches button { width: 28px; height: 28px; border-radius: 50%; border: 1.5px solid rgba(0, 0, 0, 0.12); cursor: pointer; transition: transform 0.15s; }
.swatches button:hover { transform: scale(1.15); }
.swatches button.on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ink); }
.swatches.big button { width: 40px; height: 40px; border-radius: 12px; }
.swatches.small button { width: 22px; height: 22px; }
.swatches input[type="color"] { width: 30px; height: 30px; border: 0; padding: 0; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); border-radius: 50%; cursor: pointer; }
.swatches input[type="color"]::-webkit-color-swatch { border-radius: 50%; border: 0; opacity: 0; }

.stage-wrap { display: grid; grid-template-columns: minmax(0, 1fr) clamp(240px, 22vw, 292px); align-items: start; gap: 16px; padding: 20px; min-width: 0; background: radial-gradient(#dfd4c6 1px, transparent 1.2px) 0 0 / 20px 20px; }
.work-paper { display: grid; justify-items: center; gap: 12px; min-width: 0; }
.stage-heading { display: flex; justify-content: space-between; align-items: end; flex-wrap: wrap; gap: 8px; width: 100%; }
.studio-kicker { display: block; color: var(--muted); font-weight: 800; font-size: 10px; letter-spacing: .12em; }
.stage-heading h2 { font-family: var(--display); font-size: clamp(19px, 2vw, 26px); line-height: 1.18; margin: 2px 0 0; }
.object-picker { display: grid; gap: 2px; color: var(--muted); font-size: 12px; font-weight: 700; }
.object-picker select { width: clamp(132px, 24vw, 190px); min-height: 40px; border: 1px solid var(--line); border-radius: 8px; padding: 3px 6px; font: 600 14px var(--body); color: var(--ink); background: #fff; }
.stage-hint { margin: 0; min-height: 2.8em; color: var(--muted); font-size: 13px; text-align: center; line-height: 1.4; }
.inspector, .page-tray { background: #fff; border: 1px solid var(--line); border-radius: 14px; min-width: 0; }
.studio-rail { display: grid; gap: 12px; min-width: 0; position: sticky; top: 89px; }
.inspector { max-height: max(165px, calc(100dvh - 330px)); overflow: auto; }
.page-tray { padding: 0; }
.inspector-empty { margin: 0; padding: 16px; }
.props { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px; }
.props textarea, .props input:not([type]), .props input[type="number"], .props select { font: 600 14px var(--body); border: 1.5px solid var(--line); border-radius: 10px; padding: 7px 10px; background: #fff; color: var(--ink); }
.props textarea, .props input:not([type]) { width: 100%; }
.props textarea { resize: vertical; min-height: 44px; }
.props input[type="number"] { width: 62px; }
.props input[type="range"] { flex: 1; min-width: 0; height: 30px; accent-color: var(--ink); }
.pmini { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; color: var(--muted); }
.props .pmini:has(input[type="range"]), .props .swatches, .props .sep { width: 100%; }
.props .pmini:has(input[type="range"]) { justify-content: space-between; }
.tog, .pbtn { min-width: 36px; height: 36px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; cursor: pointer; font-size: 15px; color: var(--ink); }
.pbtn { padding: 0 12px; font: 700 13px var(--body); }
.tog:hover, .pbtn:hover { border-color: var(--ink); }
.tog.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.danger:hover:not(:disabled) { background: #fee2e2; border-color: #dc2626; }
.props .sep { height: 1px; background: var(--line); }

.stage { width: min(100%, 640px, max(250px, calc((100svh - 240px) * .707))); }
.stage canvas { width: 100%; height: auto; display: block; background: #fff; border-radius: 4px; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.04), 0 30px 60px -30px rgba(40, 25, 10, 0.55); touch-action: pinch-zoom; }
.stage.drawing canvas { box-shadow: 0 0 0 3px var(--accent), 0 30px 60px -30px rgba(40, 25, 10, 0.55); }

.pages-bar { display: flex; gap: 12px; align-items: center; padding: 12px 14px; }
.pages { display: flex; gap: 10px; min-width: 0; overflow-x: auto; padding: 5px; margin: -5px; scroll-padding-inline: 5px; }
.pg { display: grid; position: relative; flex: none; border: 1px solid var(--line); padding: 0; background: transparent; color: var(--ink); border-radius: 5px; cursor: pointer; }
.pg canvas { width: 54px; height: auto; display: block; border-radius: 4px; }
.pg.on { box-shadow: 0 0 0 2px var(--ink); }
.pg small { position: absolute; left: 4px; bottom: 3px; font-size: 11px; font-weight: 800; background: #fff; border-radius: 6px; padding: 0 4px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 12px; }
.add-page { flex: none; height: 79px; padding: 0 16px; border: 2px dashed #cfc3b4; border-radius: 8px; background: transparent; font: 800 13px var(--body); cursor: pointer; color: var(--ink); }
.add-page:hover { border-color: var(--ink); background: #fff; }

.export-card { background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 22px; padding: 24px; width: min(390px, calc(100% - 32px)); text-align: center; font-size: 17px; }
.export-card[open] { display: grid; justify-items: center; gap: 14px; }
.export-card::backdrop { background: rgba(29, 26, 38, 0.55); backdrop-filter: blur(4px); }
.export-card form:has(button[hidden]) { display: none; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--paper-2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.studio-dock, .sheet-close { display: none; }
@media (max-width: 1023px) {
  .studio-body { --dock-height: calc(66px + env(safe-area-inset-bottom)); }
  .studio { display: block; padding-bottom: var(--dock-height); }
  .studio-top { padding: 8px 10px; gap: 8px; }
  .studio-top .logo { font-size: 0; gap: 0; flex: none; }
  .studio-top .logo-mark { font-size: 16px; }
  .studio-title { min-width: 0; padding-left: 0; border: 0; }
  .studio-title h1 { font-size: clamp(13px, 3.6vw, 18px); }
  .studio-title small { font-size: 10px; }
  .studio-actions { gap: 3px; }
  .studio-actions .btn { min-height: 44px; padding: 6px 9px; white-space: nowrap; font-size: 13px; }
  .stage-wrap { display: block; padding: 12px 12px 18px; }
  .work-paper { max-width: 720px; margin: auto; gap: 9px; }
  .stage-heading { align-items: center; }
  .object-picker span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .object-picker select { width: clamp(146px, 40vw, 185px); }
  .stage { width: min(100%, 540px, max(220px, calc((100svh - 210px) * .707))); }
  .object-picker select, .props textarea, .props input:not([type]), .props input[type="number"], .props select { font-size: 16px; min-height: 44px; }
  .tools, .inspector, .page-tray { display: none; position: fixed; z-index: 40; inset: auto max(0px, calc((100vw - 620px) / 2)) var(--dock-height); height: auto; max-height: min(52dvh, calc(100dvh - var(--dock-height) - 74px)); border: 1px solid var(--line); border-radius: 18px 18px 0 0; box-shadow: 0 -10px 35px #31263826; }
  .studio[data-sheet="tools"] .tools { display: grid; }
  .studio[data-sheet="edit"] .inspector, .studio[data-sheet="pages"] .page-tray { display: block; overflow: auto; }
  .studio-rail { display: contents; }
  .tool-tabs { grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 5px; }
  .tool-tabs button { font-size: clamp(10px, 3vw, 12px); min-height: 44px; }
  .tool-tabs button span { font-size: 16px; }
  .tool-heading { min-height: 45px; padding: 0 10px 0 14px; }
  .sheet-close { display: block; width: 44px; height: 44px; border: 0; background: transparent; color: var(--ink); font-size: 17px; cursor: pointer; }
  .studio-dock { display: grid; position: fixed; inset: auto 0 0; z-index: 41; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; padding: 5px max(8px, calc((100vw - 620px) / 2)) calc(5px + env(safe-area-inset-bottom)); min-height: var(--dock-height); background: #fff; border-top: 1px solid var(--line); }
  .studio-dock button { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; color: var(--ink); cursor: pointer; font: 800 13px var(--body); display: grid; place-content: center; gap: 2px; }
  .studio-dock button span { line-height: 1; font-size: 19px; }
  .studio-dock button[aria-expanded="true"] { background: var(--ink); color: #fff; }
  .studio-dock button[data-ready="true"]:not([aria-expanded="true"]) { background: #fff0c7; border-color: #bf973b; }
  .chips button, .tog, .pbtn, .swatches button, .swatches input[type="color"] { min-height: 44px; }
  .tog, .swatches button, .swatches input[type="color"] { min-width: 44px; }
  .sticker-grid { grid-template-columns: repeat(auto-fit, minmax(44px, 1fr)); }
}
@media (max-width: 365px) {
  .studio-top { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 3px 8px; }
  .studio-title { display: contents; }
  .studio-title h1 { grid-area: 1 / 2; line-height: 1.1; }
  .studio-title small { grid-area: 2 / 2 / 3 / -1; }
  .studio-actions { grid-area: 1 / 3; }
  .studio-actions .btn { font-size: 12px; padding-inline: 8px; }
}
.tool-panel, .inspector, .page-tray { overscroll-behavior-y: contain; }
.tool-panel section { padding: 0; }
@media (prefers-reduced-motion: reduce) {
  .tool-panel section.on { animation: none; }
}

/* Page size picker */
.format-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0 4px; }
.format-pick button { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; text-align: left; padding: 10px; border: 1.5px solid var(--line); border-radius: 14px; background: #fff; color: var(--ink); cursor: pointer; font: 700 13px var(--body); transition: border-color .15s, background .15s; }
.format-pick button:hover { border-color: var(--ink); }
.format-pick button[aria-pressed="true"] { border-color: var(--ink); background: var(--paper-2); box-shadow: inset 0 0 0 1px var(--ink); }
.format-pick i { grid-row: 1 / 3; display: block; border: 2px solid currentColor; border-radius: 3px; background: #fff; }
.format-pick .fmt-a4 { width: 21px; height: 30px; }
.format-pick .fmt-story { width: 17px; height: 30px; border-radius: 5px; }
.format-pick b { font-size: 14px; line-height: 1.15; }
.format-pick small { font-size: 11px; color: var(--muted); font-weight: 600; line-height: 1.25; }
.tpl-title { margin-top: 22px !important; }
.tpl-grid[data-format="story"] { grid-template-columns: repeat(3, 1fr); }
.stage[data-format="story"] { width: min(100%, 420px, max(220px, calc((100svh - 240px) * .5625))); }
@media (max-width: 1023px) { .stage[data-format="story"] { width: min(100%, 400px, max(200px, calc((100svh - 210px) * .5625))); } }

/* Greek fonts */
.font-list { display: grid; gap: 6px; }
.font-list button { display: grid; gap: 2px; text-align: left; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); cursor: pointer; transition: border-color .15s, transform .15s; }
.font-list button:hover { border-color: var(--ink); transform: translateX(3px); }
.font-list span { font-size: 21px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.font-list button[data-font="pixel"] span { font-size: 13px; line-height: 1.8; }
.font-list small { font: 700 11px var(--body); color: var(--muted); }

/* Greek word stickers */
.word-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; align-items: center; }
.word-grid button { display: grid; place-items: center; min-height: 64px; padding: 4px; border: 0; border-radius: 12px; background: var(--paper); cursor: pointer; transition: transform .15s, background .15s; }
.word-grid button:hover { background: var(--paper-2); transform: scale(1.04) rotate(-2deg); }
.word-grid canvas { max-width: 100%; max-height: 86px; width: auto; height: auto; display: block; }
.props .ink-row { width: 100%; }

/* Saved designs */
.cloud-btn { font-size: 19px; }
.mine-login { display: flex; justify-content: center; margin: 4px 0 14px; }
.mine-name { display: grid; gap: 4px; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 10px; }
.mine-name input { font: 600 15px var(--body); border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 11px; color: var(--ink); }
.mine-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.mine-actions .btn { padding: 9px 16px; font-size: 14px; }
.mine-actions .pbtn { height: auto; min-height: 38px; }
.mine-status { min-height: 1.4em; margin: 10px 0 0; font-size: 13px; font-weight: 600; color: #1f6b43; line-height: 1.4; }
.mine-status[data-error] { color: #b42318; }
.mine-list { display: grid; gap: 8px; }
.mine-item { display: flex; gap: 6px; align-items: center; }
.mine-open { flex: 1; min-width: 0; display: flex; gap: 10px; align-items: center; text-align: left; padding: 6px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); cursor: pointer; }
.mine-open:hover { border-color: var(--ink); }
.mine-item.on .mine-open { border-color: var(--ink); background: var(--paper-2); }
.mine-open img { flex: none; width: 42px; height: 59px; object-fit: cover; border-radius: 4px; background: var(--paper-2); box-shadow: 0 0 0 1px var(--line); }
.mine-open img[data-format="story"] { width: 34px; height: 60px; }
.mine-open span { display: grid; min-width: 0; gap: 2px; }
.mine-open b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mine-open small { font-size: 11px; color: var(--muted); font-weight: 600; }

/* Export */
#export-preview { max-width: 150px; max-height: 260px; border-radius: 10px; box-shadow: 0 10px 25px -12px rgba(0,0,0,.45); }
.export-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.export-list a { display: inline-flex; align-items: center; text-decoration: none; }
