/* ============================================================
   Paper Studio - application layout
   ============================================================ */

* { box-sizing: border-box; }

html, body {
  height: 100%; margin: 0;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-sys-typescale-plain-font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app {
  height: 100%;
  display: grid;
  grid-template-rows: 64px 1fr;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr) 340px;
  gap: 12px;
  padding: 12px;
  background: var(--md-sys-color-surface);
}

/* ---------- Panels ---------- */
.panel {
  min-height: 0;
  display: flex; flex-direction: column;
  border-radius: var(--md-sys-shape-corner-l);
  background: var(--md-sys-color-surface-container-low);
  overflow: hidden;
}
.panel > header {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 8px 10px 16px; flex: none;
}
.panel > header h2 {
  flex: 1 1 auto; margin: 0;
  font: 500 16px/24px var(--md-sys-typescale-plain-font); letter-spacing: 0.15px;
}
.panel > header .count {
  font: 500 11px/16px var(--md-sys-typescale-plain-font);
  padding: 2px 8px; border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
}
.panel .scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 0 12px 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--md-sys-color-outline-variant) transparent;
}
.panel .scroll::-webkit-scrollbar { width: 8px; }
.panel .scroll::-webkit-scrollbar-thumb {
  background: var(--md-sys-color-outline-variant); border-radius: 99px;
  border: 2px solid transparent; background-clip: padding-box;
}
.panel > footer { flex: none; padding: 12px; }
.panel > footer .md-fab { width: 100%; }

/* ---------- Sheet list ---------- */
.sheet-item { position: relative; }
.sheet-item .thumb {
  flex: none; width: 48px; height: 62px; border-radius: 6px;
  background: var(--md-sys-color-surface-container-highest);
  background-size: cover; background-position: center;
  box-shadow: inset 0 0 0 1px var(--md-sys-color-outline-variant);
  display: grid; place-items: center; overflow: hidden;
  transform: rotate(-2deg);
  transition: transform var(--md-sys-motion-duration-medium) var(--md-sys-motion-emphasized);
}
.sheet-item:hover .thumb { transform: rotate(0deg) scale(1.04); }
.sheet-item .thumb svg { width: 20px; height: 20px; fill: var(--md-sys-color-on-surface-variant); opacity: 0.7; }
.sheet-item .text { flex: 1 1 auto; min-width: 0; }
.sheet-item .text .headline { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-item .row-actions { display: flex; gap: 0; flex: none; opacity: 0; transition: opacity 120ms; }
.sheet-item:hover .row-actions,
.sheet-item[aria-selected="true"] .row-actions { opacity: 1; }
.sheet-item.dragging { opacity: 0.4; }
.sheet-item.drop-before { box-shadow: inset 0 3px 0 0 var(--md-sys-color-primary); }
.sheet-item.drop-after { box-shadow: inset 0 -3px 0 0 var(--md-sys-color-primary); }

.empty-state {
  margin: 24px 8px; padding: 24px 16px; text-align: center;
  border-radius: var(--md-sys-shape-corner-m);
  border: 1px dashed var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface-variant);
}
.empty-state svg { width: 32px; height: 32px; fill: currentColor; opacity: 0.6; }
.empty-state p { margin: 8px 0 0; font: 400 14px/20px var(--md-sys-typescale-plain-font); }

/* ---------- Viewport ---------- */
.viewport {
  position: relative; min-width: 0; min-height: 0;
  border-radius: var(--md-sys-shape-corner-l);
  overflow: hidden;
  background: linear-gradient(180deg, var(--app-studio-top), var(--app-studio-bottom));
  box-shadow: inset 0 0 0 1px var(--md-sys-color-outline-variant);
  touch-action: none;
}
.viewport canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.viewport-dock {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px; padding: 6px;
  border-radius: var(--md-sys-shape-corner-full);
  background: color-mix(in srgb, var(--md-sys-color-surface-container-high) 88%, transparent);
  backdrop-filter: blur(12px);
  box-shadow: var(--app-hairline);
  z-index: 5;
}
.viewport-dock .sep { width: 1px; height: 24px; margin: 0 4px; background: var(--md-sys-color-outline-variant); }

/* Collapsed to just the icon so it stays out of the way; click to read it. */
.viewport-hint {
  position: absolute; top: 12px; left: 12px; z-index: 5;
  display: inline-flex; align-items: center;
  height: 36px; padding: 0 9px; border: none; cursor: pointer;
  border-radius: var(--md-sys-shape-corner-full);
  background: color-mix(in srgb, var(--md-sys-color-surface-container-high) 82%, transparent);
  backdrop-filter: blur(12px);
  color: var(--md-sys-color-on-surface-variant);
  font: 500 12px/16px var(--md-sys-typescale-plain-font);
  box-shadow: var(--app-hairline);
  overflow: hidden;
  transition: padding var(--md-sys-motion-duration-medium) var(--md-sys-motion-emphasized),
              background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-standard);
}
.viewport-hint:hover { background: var(--md-sys-color-surface-container-high); }
.viewport-hint .icon { display: grid; place-items: center; flex: none; }
.viewport-hint .icon svg { width: 18px; height: 18px; }
.viewport-hint .text {
  display: block; max-width: 0; margin-left: 0; opacity: 0;
  white-space: nowrap; overflow: hidden;
  transition: max-width var(--md-sys-motion-duration-medium) var(--md-sys-motion-emphasized),
              margin-left var(--md-sys-motion-duration-medium) var(--md-sys-motion-emphasized),
              opacity var(--md-sys-motion-duration-short) var(--md-sys-motion-standard);
}
.viewport-hint[aria-expanded="true"] { padding: 0 14px 0 9px; }
.viewport-hint[aria-expanded="true"] .text { max-width: 60ch; margin-left: 8px; opacity: 1; }

.drop-overlay {
  position: absolute; inset: 12px; z-index: 10; display: none;
  place-items: center; text-align: center;
  border-radius: var(--md-sys-shape-corner-l);
  border: 2px dashed var(--md-sys-color-primary);
  background: color-mix(in srgb, var(--md-sys-color-primary-container) 70%, transparent);
  color: var(--md-sys-color-on-primary-container);
  font: 500 16px/24px var(--md-sys-typescale-plain-font);
  backdrop-filter: blur(4px);
}
.drop-overlay[data-active="true"] { display: grid; }
.drop-overlay svg { width: 40px; height: 40px; fill: currentColor; display: block; margin: 0 auto 8px; }

/* ---------- Inspector ---------- */
.group { padding: 4px 0 8px; }
.group + .group { border-top: 1px solid var(--md-sys-color-outline-variant); }
.group > .group-head {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 12px 4px; border: none; background: none; cursor: pointer;
  color: var(--md-sys-color-on-surface);
  font: 500 14px/20px var(--md-sys-typescale-plain-font); letter-spacing: 0.1px;
  border-radius: var(--md-sys-shape-corner-s);
}
.group > .group-head svg.lead { width: 20px; height: 20px; fill: var(--md-sys-color-primary); flex: none; }
.group > .group-head .grow { flex: 1 1 auto; text-align: left; }
.group > .group-head svg.chev {
  width: 20px; height: 20px; fill: var(--md-sys-color-on-surface-variant); flex: none;
  transition: transform var(--md-sys-motion-duration-medium) var(--md-sys-motion-emphasized);
}
.group[data-open="false"] > .group-head svg.chev { transform: rotate(-90deg); }
.group[data-open="false"] > .group-body { display: none; }
.group > .group-body { display: flex; flex-direction: column; gap: 14px; padding: 4px 4px 12px; }

.field-label {
  display: block; margin-bottom: 6px;
  font: 500 12px/16px var(--md-sys-typescale-plain-font); letter-spacing: 0.5px;
  color: var(--md-sys-color-on-surface-variant);
}
.hint {
  margin: 0; font: 400 12px/16px var(--md-sys-typescale-plain-font);
  color: var(--md-sys-color-on-surface-variant);
}

.swatches { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer; padding: 0;
  border: 1px solid var(--md-sys-color-outline-variant);
}
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--md-sys-color-surface-container-low), 0 0 0 4px var(--md-sys-color-primary); }
input[type="color"].swatch { -webkit-appearance: none; appearance: none; background: none; }
input[type="color"].swatch::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"].swatch::-webkit-color-swatch { border: none; border-radius: 50%; }

.upload-tile {
  position: relative; display: grid; place-items: center; gap: 8px;
  width: 100%; aspect-ratio: 4 / 3; cursor: pointer; padding: 12px;
  border-radius: var(--md-sys-shape-corner-m);
  border: 1px dashed var(--md-sys-color-outline);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
  background-size: cover; background-position: center;
  font: 500 13px/18px var(--md-sys-typescale-plain-font);
  text-align: center;
  overflow: hidden;
}
.upload-tile.has-image { border-style: solid; border-color: var(--md-sys-color-outline-variant); }
.upload-tile.has-image .placeholder { display: none; }
.upload-tile .placeholder { display: grid; place-items: center; gap: 6px; }
.upload-tile svg { width: 28px; height: 28px; fill: currentColor; }
.upload-tile .overlay-actions {
  position: absolute; right: 8px; bottom: 8px; display: flex; gap: 6px; opacity: 0;
  transition: opacity 120ms;
}
.upload-tile:hover .overlay-actions { opacity: 1; }
.upload-tile .overlay-actions .md-icon-button {
  background: color-mix(in srgb, var(--md-sys-color-surface-container-high) 90%, transparent);
  backdrop-filter: blur(6px);
}

.inspector-empty { padding: 40px 20px; text-align: center; color: var(--md-sys-color-on-surface-variant); }
.inspector-empty svg { width: 40px; height: 40px; fill: currentColor; opacity: 0.5; }
.inspector-empty p { font: 400 14px/20px var(--md-sys-typescale-plain-font); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

kbd {
  display: inline-block; min-width: 18px; padding: 1px 5px; text-align: center;
  border-radius: 4px; background: var(--md-sys-color-surface-container-highest);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  font: 500 11px/16px var(--md-sys-typescale-plain-font);
  color: var(--md-sys-color-on-surface);
}

.shortcuts { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; align-items: center; }
.shortcuts span { font: 400 14px/20px var(--md-sys-typescale-plain-font); }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 240px minmax(0, 1fr) 300px; }
}
@media (max-width: 960px) {
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: 300px auto 320px; }
  .panel--sheets { order: 2; }
  .viewport { order: 1; min-height: 320px; }
  .panel--inspector { order: 3; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}

/* ---------- Icons ---------- */
/* Material Symbols are filled shapes drawn to look outlined - one style for
   every icon, so nothing in the interface mixes stroke and fill. */
svg.md-icon {
  fill: currentColor;
  stroke: none;
}
[data-icon] { display: inline-grid; place-items: center; }
.md-top-app-bar .brand { color: var(--md-sys-color-primary); }
.md-top-app-bar .brand svg { width: 26px; height: 26px; }

/* ---------- Backdrop modes ---------- */
[data-backdrop="flat"] .viewport { background: var(--app-studio-top); }
[data-backdrop="transparent"] .viewport {
  background-color: var(--md-sys-color-surface-container-lowest);
  background-image:
    linear-gradient(45deg, var(--md-sys-color-surface-container-high) 25%, transparent 25%),
    linear-gradient(-45deg, var(--md-sys-color-surface-container-high) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--md-sys-color-surface-container-high) 75%),
    linear-gradient(-45deg, transparent 75%, var(--md-sys-color-surface-container-high) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

/* ---------- Offline render progress ---------- */
.md-progress {
  height: 4px; border-radius: 99px; overflow: hidden;
  background: var(--md-sys-color-secondary-container);
}
.md-progress .bar {
  height: 100%; width: 0%;
  background: var(--md-sys-color-primary);
  border-radius: 99px;
  transition: width 120ms linear;
}

.render-progress {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  z-index: 6; width: min(420px, calc(100% - 32px));
  display: grid; grid-template-columns: 1fr auto; align-items: center;
  gap: 4px 12px; padding: 12px 8px 12px 16px;
  border-radius: var(--md-sys-shape-corner-l);
  background: color-mix(in srgb, var(--md-sys-color-surface-container-high) 92%, transparent);
  backdrop-filter: blur(12px);
  box-shadow: var(--app-hairline);
}
.render-progress[hidden] { display: none; }
.render-progress .label {
  grid-column: 1; display: flex; align-items: center; gap: 8px;
  font: 500 12px/16px var(--md-sys-typescale-plain-font);
  color: var(--md-sys-color-on-surface);
}
.render-progress .label svg { width: 16px; height: 16px; }
.render-progress .md-progress { grid-column: 1; }
.render-progress button { grid-column: 2; grid-row: 1 / span 2; }

/* ---------- "Powered by" credit ----------
   Lives in the DOM on top of the canvas, never inside it, so it is present
   while you work and absent from every export. */
.viewport-credit {
  /* One number controls the whole badge: the artwork is 100x32 at scale 1. */
  --credit-scale: 2;
  position: absolute; top: 12px; right: 12px; z-index: 5;
  display: block; padding: 0; line-height: 0;
  border-radius: calc(9px * var(--credit-scale)); overflow: hidden;
  background: color-mix(in srgb, var(--md-sys-color-surface-container-high) 82%, transparent);
  backdrop-filter: blur(12px);
  box-shadow: var(--app-hairline);
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-standard);
}
.viewport-credit:hover {
  background: var(--md-sys-color-surface-container-high);
}
.viewport-credit svg {
  display: block;
  width: calc(100px * var(--credit-scale));
  height: calc(32px * var(--credit-scale));
}

/* Step it back on narrow viewports so it cannot run into the hint chip. */
@media (max-width: 1180px) { .viewport-credit { --credit-scale: 1.5; } }
@media (max-width: 960px)  { .viewport-credit { --credit-scale: 1.25; } }
.viewport-credit .credit-label { fill: var(--md-sys-color-on-surface-variant); }
.viewport-credit .credit-name,
.viewport-credit .credit-mark { fill: var(--md-sys-color-on-surface); }
