:root {
  color-scheme: dark;
  /* Palette aligned to the main site (rawlity.co) so the app shares its look. */
  --bg: #000000;                 /* main --bg-dark */
  --bg-card: #1a1a1a;            /* main --bg-card  (panels / toolbars) */
  --bg-elevated: #242424;       /* main --bg-elevated (popovers / tiles) */
  --panel: rgba(17, 14, 10, 0.95);
  --panel-soft: rgba(222, 199, 160, 0.055);
  --line: rgba(255, 244, 212, 0.12);
  --line-strong: rgba(255, 244, 212, 0.26);
  --text: #efd8b9;              /* main --text-primary */
  --muted: #8f8a80;
  --accent: #FFF4D4;            /* main --accent  (bright cream — the brand pop) */
  --accent-light: #efd8b9;      /* main --accent-light (hover / secondary) */
  --pink: #ead6a3;
  --sand: #c9a86d;
  --danger: #9d5646;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', Arial, sans-serif;
}

body {
  overflow-x: hidden;
}

@media (min-width: 820px) and (orientation: landscape) {
  html,
  body,
  #app {
    height: 100%;
    overflow: hidden;
  }
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.015));
  color: var(--text);
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
}

.mobile-shell {
  display: grid;
  grid-template-rows: auto auto minmax(clamp(420px, 58svh, 620px), 1fr) auto auto auto auto auto;
  grid-template-areas:
    "top"
    "toppeek"
    "canvas"
    "controls"
    "actions"
    "cardtype"
    "result"
    "bottompeek";
  gap: 5px;
  width: min(100vw, 460px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(4px, env(safe-area-inset-top)) 5px max(6px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 50% 0%, rgba(216, 189, 131, 0.08), transparent 34%),
    linear-gradient(90deg, rgba(222, 199, 160, 0.024) 1px, transparent 1px) 0 0 / 26px 26px,
    repeating-linear-gradient(135deg, transparent 0 3px, rgba(255,255,255,0.012) 3px 4px),
    var(--bg);
}

.summary-panel,
.control-panel,
.action-row,
.summary-panel {
  padding: 6px;
}

.summary-panel {
  grid-area: top;
  position: sticky;
  top: 0;
  z-index: 12;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px) 0 0 / 26px 26px,
    rgba(0, 0, 0, 0.94);
  backdrop-filter: blur(10px);
}

.panel-brand {
  position: relative;
  display: grid;
  place-items: start;
  min-height: 74px;
  padding: 8px 174px 0 8px;
}

.panel-brand strong {
  display: block;
  color: #fff;
  font-size: clamp(28px, 8vw, 34px);
  font-weight: 1000;
  line-height: 0.78;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.36);
}

.panel-brand small {
  display: block;
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.62);
  font-size: 7px;
  font-weight: 800;
  letter-spacing: 1.2px;
}

.panel-brand::after {
  content: "";
  width: min(144px, 40vw);
  height: 1px;
  margin-top: -2px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.78), transparent);
}

.media-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 5px;
}

.upload-button {
  min-height: 40px;
  padding: 0 12px;
  color: var(--accent);
  font-size: 18px;
  border-radius: 10px;
  box-shadow: inset 0 0 16px rgba(129,255,37,0.08), 0 0 12px rgba(129,255,37,0.08);
}

.collapse-summary {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 34px;
  min-height: 30px;
  padding: 0;
  color: rgba(255,255,255,0.72);
  border-radius: 7px;
}

.summary-panel.is-collapsed {
  padding-bottom: 3px;
}

.summary-panel.is-collapsed .panel-brand {
  min-height: 34px;
}

.summary-panel.is-collapsed .panel-brand strong {
  font-size: 24px;
}

.summary-panel.is-collapsed .panel-brand small,
.summary-panel.is-collapsed .panel-brand::after,
.summary-panel.is-collapsed .summary-compact,
.summary-panel.is-collapsed .ratio-grid {
  display: none;
}

.summary-panel.is-collapsed .upload-button {
  min-height: 32px;
}

.media-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 42px;
  padding: 0;
  font-size: 0;
}

.media-button::before {
  content: "";
  width: 22px;
  height: 18px;
  border: 2px solid var(--accent);
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(129,255,37,0.32);
}

.image-button::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 8px;
  border-left: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: translateY(5px) skewX(-24deg);
}

.camera-button::before {
  width: 24px;
  height: 17px;
  border-radius: 5px;
}

.camera-button::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  box-shadow: inset 0 0 5px rgba(129,255,37,0.24);
}

.save-button {
  width: auto;
  min-width: 62px;
  padding-inline: 12px;
  color: #080706;
  background: linear-gradient(180deg, #ead197, #c8a46a);
  border-color: rgba(214, 179, 122, 0.82);
  font-size: 12px;
  font-weight: 1000;
  letter-spacing: 0.4px;
}

.summary-panel.is-collapsed .media-actions {
  top: 1px;
}

.summary-panel.is-collapsed .media-button {
  width: 34px;
}

.summary-panel.is-collapsed .save-button {
  min-width: 52px;
  min-height: 32px;
  padding-inline: 8px;
  font-size: 10px;
}

.top-peek,
.bottom-peek {
  position: relative;
  min-height: 18px;
  padding: 0;
  border-color: rgba(129,255,37,0.42);
  border-radius: 5px;
  color: var(--accent);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 1px;
  background: linear-gradient(180deg, rgba(129,255,37,0.11), rgba(255,255,255,0.025));
  box-shadow: inset 0 0 12px rgba(129,255,37,0.08);
}

.top-peek {
  grid-area: toppeek;
}

.bottom-peek {
  grid-area: bottompeek;
}

.top-peek[hidden],
.bottom-peek[hidden] {
  display: none !important;
}

.mobile-shell.top-hidden .summary-panel {
  display: none;
}

.mobile-shell.bottom-hidden .control-panel,
.mobile-shell.bottom-hidden .action-row,
.mobile-shell.bottom-hidden .inline-cardtype-toolbar,
.mobile-shell.bottom-hidden .bottom-nav {
  display: none;
}

.mobile-shell:not(.advanced-open) .control-panel,
.mobile-shell:not(.advanced-open) .advanced-tool {
  display: none;
}

.eye-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  font-size: 0 !important;
}

.eye-button::before {
  content: "";
  display: inline-block;
  width: 22px;
  height: 13px;
  border: 2px solid currentColor;
  border-radius: 70% 70% 70% 70% / 88% 88% 88% 88%;
  vertical-align: middle;
  box-shadow: 0 0 8px rgba(129,255,37,0.22);
  transform: rotate(-8deg);
}

.eye-button::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  border: 2px solid rgba(0,0,0,0.72);
  border-radius: 50%;
  background: currentColor;
  transform: translate(-50%, -50%);
}

#imageInput,
#cameraInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.summary-compact {
  display: grid;
  grid-template-columns: 1fr 112px;
  gap: 8px;
  align-items: stretch;
  margin-top: 4px;
}

.grade-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

.grade-card,
.summary-action {
  min-width: 0;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.5);
  text-align: center;
}

.grade-card {
  display: grid;
  align-content: center;
  min-height: 70px;
  padding: 4px 2px;
}

.grade-card span,
.summary-action span,
.ratio-grid span,
.control-block span,
.credits-bar span {
  display: block;
  color: #ececec;
  font-size: 12px;
  font-weight: 700;
}

.grade-card strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.summary-action {
  display: grid;
  place-items: center;
  min-height: 58px;
  padding: 4px;
  border-radius: 10px;
  box-shadow: inset 0 0 14px rgba(255,255,255,0.08), 0 0 10px rgba(0,0,0,0.55);
}

.summary-action strong {
  color: var(--accent);
  font-size: 22px;
  line-height: 1;
}

.icon-action {
  grid-template-rows: 14px 1fr 12px;
  gap: 1px;
}

.icon-action span,
.icon-action em {
  font-size: 10px;
  font-style: normal;
  line-height: 1;
}

.side-toggle strong {
  position: relative;
  display: block;
  width: 34px;
  height: 24px;
}

.side-toggle i {
  position: absolute;
  width: 21px;
  height: 28px;
  border: 2px solid var(--accent);
  border-radius: 3px;
  background: rgba(216, 189, 131, 0.06);
  box-shadow: 0 0 10px rgba(216, 189, 131, 0.18);
}

.side-toggle i:first-child {
  left: 0;
  top: 2px;
}

.side-toggle i:last-child {
  right: 0;
  top: -2px;
  border-color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.rotate-toggle strong {
  position: relative;
  display: block;
  width: 30px;
  height: 30px;
  border: 2px solid var(--accent);
  border-left-color: transparent;
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(216, 189, 131, 0.18);
}

.rotate-toggle strong::after {
  content: "";
  position: absolute;
  right: -2px;
  top: 0;
  border: 5px solid transparent;
  border-left-color: var(--accent);
  transform: rotate(-28deg);
}

.rotate-toggle em {
  color: var(--accent);
  font-weight: 900;
}

.ratio-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 2px;
  margin-top: 6px;
  padding: 7px 4px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.ratio-grid div {
  min-width: 0;
  text-align: center;
}

.ratio-grid strong {
  display: block;
  margin-top: 3px;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
}

.ratio-grid div:nth-child(3) strong,
.ratio-grid div:nth-child(6) strong {
  color: var(--accent);
  font-size: 15px;
}

.canvas-area {
  grid-area: canvas;
  position: relative;
  min-height: clamp(420px, 58svh, 620px);
  overflow: hidden;
  border: 1px solid var(--line);
  background: #020202;
  contain: layout paint size;
  touch-action: pan-y;
  user-select: none;
}

#mobileCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: clamp(420px, 58svh, 620px);
  contain: strict;
  will-change: contents;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
}

.empty-state[hidden] {
  display: none !important;
}

.restore-warning {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  padding: 8px 10px;
  border: 1px solid rgba(255, 231, 90, 0.58);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.78);
  color: #f2e5bf;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  pointer-events: none;
}

.restore-warning[hidden] {
  display: none !important;
}

.inline-perspective-toolbar {
  position: absolute;
  left: 50%;
  top: 8px;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
  width: min(360px, calc(100% - 12px));
  padding: 6px;
  border: 1px solid rgba(214, 179, 122, 0.42);
  border-radius: 8px;
  background: rgba(6, 5, 4, 0.82);
  box-shadow: 0 12px 34px rgba(0,0,0,0.58), inset 0 0 18px rgba(214,179,122,0.05);
  transform: translateX(-50%);
  backdrop-filter: blur(10px);
}

.inline-perspective-toolbar[hidden] {
  display: none !important;
}

.inline-perspective-toolbar button {
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 48px;
  padding: 5px 4px;
  border-color: rgba(214, 179, 122, 0.42);
  color: #f3ead8;
  background: linear-gradient(180deg, rgba(20,18,14,0.94), rgba(8,7,5,0.94));
  font-size: 10px;
}

.inline-perspective-toolbar .toolbar-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 20px;
  border: 1px solid rgba(214, 179, 122, 0.54);
  border-radius: 5px;
  color: #d6b37a;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

.inline-perspective-toolbar small {
  color: rgba(243,234,216,0.74);
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
}

.inline-rotate-toolbar {
  position: absolute;
  left: 50%;
  top: 8px;
  z-index: 5;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px 48px;
  align-items: center;
  gap: 6px;
  width: min(560px, calc(100% - 12px));
  padding: 6px;
  border: 1px solid rgba(214, 179, 122, 0.42);
  border-radius: 8px;
  background: rgba(6, 5, 4, 0.82);
  box-shadow: 0 12px 34px rgba(0,0,0,0.58), inset 0 0 18px rgba(214,179,122,0.05);
  transform: translateX(-50%);
  backdrop-filter: blur(10px);
}

.inline-rotate-toolbar[hidden] {
  display: none !important;
}

.inline-rotate-toolbar button {
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 48px;
  padding: 5px 4px;
  border-color: rgba(214, 179, 122, 0.42);
  color: #f3ead8;
  background: linear-gradient(180deg, rgba(20,18,14,0.94), rgba(8,7,5,0.94));
  font-size: 10px;
}

.inline-rotate-toolbar label {
  display: grid;
  gap: 5px;
}

.inline-rotate-toolbar label span {
  display: flex;
  justify-content: space-between;
  color: rgba(243,234,216,0.78);
  font-size: 11px;
  font-weight: 900;
}

.inline-rotate-toolbar label strong {
  color: #d6b37a;
}

.inline-rotate-toolbar input {
  width: 100%;
  min-height: 28px;
  accent-color: #d6b37a;
}

.inline-rotate-toolbar .toolbar-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 20px;
  border: 1px solid rgba(214, 179, 122, 0.54);
  border-radius: 5px;
  color: #d6b37a;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

.inline-rotate-toolbar small {
  color: rgba(243,234,216,0.74);
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
}

.inline-cardtype-toolbar {
  grid-area: cardtype;
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  gap: 10px;
  width: auto;
  margin: 0 6px;
  padding: 10px;
  border: 1px solid rgba(214, 179, 122, 0.42);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(18, 15, 11, 0.96), rgba(7, 6, 5, 0.96));
  box-shadow: inset 0 0 18px rgba(214,179,122,0.05);
}

.inline-cardtype-toolbar[hidden] {
  display: none !important;
}

.inline-cardtype-toolbar label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.inline-cardtype-toolbar label:nth-of-type(1) {
  order: 1;
}

.inline-cardtype-toolbar label:nth-of-type(2) {
  order: 2;
}

.inline-cardtype-toolbar label:nth-of-type(3) {
  order: 3;
}

.inline-cardtype-toolbar label span {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  color: rgba(243,234,216,0.78);
  font-size: 11px;
  font-weight: 900;
}

.inline-cardtype-toolbar label strong {
  color: #d6b37a;
}

.inline-cardtype-toolbar input {
  width: 100%;
  min-height: 34px;
  accent-color: #d6b37a;
}

@media (min-width: 820px) and (orientation: landscape) {
  .inline-perspective-toolbar {
    top: 12px;
    grid-template-columns: repeat(5, 58px);
    gap: 7px;
    width: auto;
    padding: 7px;
    display: grid;
  }

  .inline-rotate-toolbar {
    top: 12px;
    grid-template-columns: 58px minmax(260px, 420px) 58px 58px;
    gap: 7px;
    width: min(640px, calc(100% - 24px));
    padding: 7px;
    display: grid;
  }

  .inline-cardtype-toolbar {
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: 7px;
    width: auto;
    margin: 0 clamp(26px, 2vw, 32px);
    padding: 7px;
    display: grid;
  }

  .inline-cardtype-toolbar label:nth-of-type(2),
  .inline-cardtype-toolbar label:nth-of-type(3) {
    grid-column: auto;
  }

  .inline-cardtype-toolbar label {
    order: initial;
  }

  #perspectiveButton.active,
  #rotateButton.active,
  #cardTypeButton.active {
    border-color: rgba(214, 179, 122, 0.86);
    color: #080706;
    background: linear-gradient(180deg, #d6b37a, #c8a46a);
  }
}

.empty-state strong {
  color: #fff;
  font-size: 18px;
}

.control-panel {
  grid-area: controls;
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr;
  gap: 5px;
  align-items: center;
  padding: 7px;
}

.control-block {
  position: relative;
  min-width: 0;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.swatch {
  width: 18px;
  min-height: 18px;
  height: 18px;
  padding: 0;
  border-radius: 3px;
  background: var(--swatch);
}

.swatch.active {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.stepper {
  display: grid;
  grid-template-columns: 28px minmax(38px, 1fr) 28px;
  align-items: center;
  gap: 5px;
  margin-top: 5px;
}

.stepper button {
  min-height: 32px;
}

.stepper strong {
  text-align: center;
}

.filters-menu,
.overlay-menu {
  position: absolute;
  right: 0;
  bottom: 48px;
  z-index: 5;
  display: grid;
  width: 132px;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #070707;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.75);
}

.filters-menu[hidden],
.overlay-menu[hidden] {
  display: none !important;
}

.filters-menu button {
  min-height: 36px;
  text-align: left;
  padding-inline: 10px;
}

.overlay-menu {
  width: 180px;
  text-align: left;
}

.overlay-menu label {
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  min-height: 34px;
  color: #fff;
  font-size: 12px;
}

.overlay-menu input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.overlay-size-control {
  display: grid;
  gap: 5px;
  padding-top: 6px;
  border-top: 1px solid rgba(222, 199, 160, 0.18);
}

.overlay-size-control span {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.overlay-size-control strong {
  color: var(--accent);
}

.overlay-size-control input {
  width: 100%;
  min-height: 28px;
  accent-color: var(--accent);
}

.action-row {
  grid-area: actions;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
}

/* Wrapper around tool buttons; transparent on mobile so the 4 buttons stay as
   direct grid items of .action-row. Becomes the vertical tool rail on desktop. */
.toolrail-group {
  display: contents;
}

/* Wrapper around the inspector trio (grades / quick / ratio); transparent on
   mobile so the original vertical flow is preserved. Becomes the scrollable
   right property panel on desktop. */
.desk-inspector {
  display: contents;
}

/* Wrapper around the secondary (advanced) action buttons; transparent on
   mobile so they stay direct grid items of .action-row's 6-col grid. Becomes
   a horizontal strip in the desktop status row. */
.action-extra {
  display: contents;
}

.action-row button,
.action-menu-button {
  width: 100%;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.tool-icon-button {
  display: grid;
  grid-template-rows: 30px auto;
  place-items: center;
  gap: 4px;
  min-height: 64px;
  padding: 6px 4px;
}

.tool-icon-button b {
  display: block;
  color: inherit;
  font-size: 10px;
  font-weight: 1000;
  line-height: 1;
}

.card-corner-icon {
  position: relative;
  display: block;
  width: 36px;
  height: 28px;
  color: var(--accent);
}

.card-corner-icon::before,
.card-corner-icon::after {
  content: "";
  position: absolute;
  right: 2px;
  bottom: 2px;
  border-color: currentColor;
  filter: drop-shadow(0 0 7px rgba(216, 179, 122, 0.26));
}

.card-corner-icon::before {
  width: 25px;
  height: 19px;
  border-right: 3px solid;
  border-bottom: 3px solid;
  border-bottom-right-radius: 9px;
}

.card-corner-icon::after {
  width: 15px;
  height: 12px;
  border-right: 2px solid;
  border-bottom: 2px solid;
  border-bottom-right-radius: 7px;
  opacity: 0.62;
}

.card-corner-icon i {
  position: absolute;
  left: 0;
  top: 0;
  color: #f3ead8;
  font-size: 10px;
  font-style: normal;
  font-weight: 1000;
  line-height: 1;
}

.perspective-card-icon {
  position: relative;
  display: block;
  width: 36px;
  height: 28px;
}

.perspective-card-icon::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 5px;
  width: 20px;
  height: 18px;
  border: 2px solid var(--accent);
  border-radius: 3px;
  background: rgba(216, 179, 122, 0.04);
  box-shadow: 0 0 9px rgba(216, 179, 122, 0.22);
  transform: perspective(46px) rotateX(9deg) rotateY(-13deg);
}

.perspective-card-icon i {
  position: absolute;
  width: 8px;
  height: 8px;
}

.perspective-card-icon i::before,
.perspective-card-icon i::after {
  content: "";
  position: absolute;
  background: var(--accent);
  border-radius: 999px;
}

.perspective-card-icon i::before {
  width: 8px;
  height: 2px;
  top: 3px;
  left: 0;
}

.perspective-card-icon i::after {
  width: 2px;
  height: 8px;
  left: 3px;
  top: 0;
}

.perspective-card-icon i:nth-child(1) {
  left: 0;
  top: 0;
  transform: rotate(45deg);
}

.perspective-card-icon i:nth-child(2) {
  right: 0;
  top: 0;
  transform: rotate(135deg);
}

.perspective-card-icon i:nth-child(3) {
  right: 0;
  bottom: 0;
  transform: rotate(225deg);
}

.perspective-card-icon i:nth-child(4) {
  left: 0;
  bottom: 0;
  transform: rotate(315deg);
}

.action-menu {
  position: relative;
  min-width: 0;
}

.action-menu-button {
  padding-inline: 4px;
}

.action-menu-button.active {
  border-color: rgba(216, 189, 131, 0.78);
  color: var(--accent);
}

.bottom-nav {
  grid-area: result;
  position: relative;
  display: grid;
  padding: 2px 6px 6px;
}

.bottom-hide-eye {
  width: 100%;
  min-height: 44px;
  padding: 0;
  border-radius: 7px;
  color: rgba(255,255,255,0.72);
}

.donate-button {
  width: 100%;
  min-height: 46px;
  color: #080706;
  border-color: rgba(216, 189, 131, 0.72);
  background: linear-gradient(180deg, #ead6a3, #c9a86d);
  font-size: 13px;
  font-weight: 1000;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  box-shadow: 0 0 18px rgba(216, 189, 131, 0.18), inset 0 0 18px rgba(255,255,255,0.22);
}

@media (max-width: 380px) {
  .mobile-shell {
    padding-inline: 4px;
  }

  .summary-compact {
    grid-template-columns: 1fr 104px;
    gap: 5px;
  }

  .quick-actions {
    gap: 4px;
  }

  .control-panel {
    grid-template-columns: 1fr;
  }

  .action-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #generateAnalysis {
    grid-column: 1 / -1;
  }

}

@media (max-width: 699px) {
  .mobile-shell {
    grid-template-rows: auto auto minmax(clamp(430px, 61svh, 680px), 1fr) auto auto auto auto auto;
    gap: 3px;
    padding-inline: 3px;
  }

  .summary-panel {
    padding: 4px 5px;
  }

  .panel-brand {
    min-height: 58px;
    padding: 5px 154px 0 6px;
  }

  .panel-brand strong {
    font-size: clamp(28px, 7vw, 32px);
  }

  .panel-brand small {
    font-size: 6px;
    letter-spacing: 0.9px;
  }

  .panel-brand::after {
    width: min(112px, 34vw);
    margin-top: 0;
  }

  .media-actions {
    top: 5px;
    right: 5px;
    gap: 4px;
  }

  .media-button {
    width: 38px;
    min-height: 38px;
    border-radius: 9px;
  }

  .save-button {
    min-width: 58px;
    min-height: 38px;
    padding-inline: 10px;
    font-size: 11px;
  }

  .collapse-summary {
    width: 30px;
    min-height: 28px;
  }

  .summary-compact {
    grid-template-columns: 1fr 108px;
    gap: 5px;
    margin-top: 2px;
  }

  .grade-grid {
    gap: 2px;
  }

  .grade-card {
    min-height: 54px;
    padding-block: 3px;
  }

  .grade-card span,
  .summary-action span,
  .ratio-grid span {
    font-size: 10px;
  }

  .grade-card strong {
    margin-top: 4px;
    font-size: 23px;
  }

  .summary-action {
    min-height: 50px;
    border-radius: 9px;
  }

  .side-toggle strong {
    width: 30px;
    height: 22px;
  }

  .side-toggle i {
    width: 19px;
    height: 25px;
  }

  .rotate-toggle strong {
    width: 27px;
    height: 27px;
  }

  .ratio-grid {
    margin-top: 4px;
    padding: 5px 3px;
  }

  .ratio-grid strong {
    margin-top: 2px;
    font-size: 12px;
  }

  .ratio-grid div:nth-child(3) strong,
  .ratio-grid div:nth-child(6) strong {
    font-size: 14px;
  }

  .canvas-area,
  #mobileCanvas {
    min-height: clamp(430px, 61svh, 680px);
  }

  .control-panel {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 6px 8px;
    border: 1px solid rgba(222, 199, 160, 0.12);
    border-radius: 10px;
    background: rgba(5, 5, 5, 0.72);
  }

  .control-block span {
    font-size: 10px;
    letter-spacing: 0.2px;
  }

  .swatches {
    flex-wrap: nowrap;
    gap: 5px;
    margin-top: 5px;
    overflow-x: auto;
    padding: 2px 2px 4px;
    scrollbar-width: none;
  }

  .swatches::-webkit-scrollbar {
    display: none;
  }

  .swatch {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    min-height: 18px;
  }

  .stepper {
    grid-template-columns: 42px 1fr 42px;
    gap: 8px;
    margin-top: 4px;
  }

  .stepper button {
    min-height: 36px;
    border-radius: 9px;
  }

  .stepper strong {
    font-size: 18px;
  }

  .action-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    padding: 5px 6px;
  }

  .tool-icon-button {
    grid-template-rows: 24px auto;
    min-height: 52px;
    padding: 5px 3px;
  }

  .tool-icon-button b,
  .action-row button,
  .action-menu-button {
    font-size: 10px;
  }

  .perspective-card-icon,
  .card-corner-icon {
    transform: scale(0.86);
  }

  .bottom-nav {
    padding: 1px 6px 5px;
  }

  .donate-button {
    min-height: 42px;
    font-size: 12px;
  }
}

@media (min-width: 700px) and (orientation: portrait) {
  .mobile-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(clamp(620px, 66svh, 900px), 1fr) auto auto auto auto;
    grid-template-areas:
      "top"
      "toppeek"
      "canvas"
      "controls"
      "actions"
      "cardtype"
      "result"
      "bottompeek";
    width: min(100vw, 780px);
    min-height: 100svh;
    gap: 6px;
    padding: max(5px, env(safe-area-inset-top)) clamp(8px, 1.4vw, 14px) max(8px, env(safe-area-inset-bottom));
  }

  .summary-panel {
    padding-block: 4px;
  }

  .panel-brand {
    min-height: 38px;
  }

  .panel-brand strong {
    font-size: clamp(30px, 5.2vw, 36px);
  }

  .panel-brand small {
    margin-top: 1px;
    font-size: 6.5px;
  }

  .ratio-grid {
    margin-top: 4px;
    padding-block: 5px;
  }

  .canvas-area,
  #mobileCanvas {
    min-height: clamp(620px, 66svh, 900px);
  }

  .control-panel {
    grid-template-columns: 1.25fr 1fr 1fr;
    gap: 8px;
  }

  .action-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .bottom-nav {
    justify-self: center;
    width: min(520px, 100%);
  }

  .inline-cardtype-toolbar {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
    gap: 8px;
    margin-inline: 8px;
    padding: 8px;
  }

  .inline-cardtype-toolbar label {
    grid-column: auto;
  }

  .inline-cardtype-toolbar label {
    order: initial;
  }

  .inline-cardtype-toolbar input {
    min-height: 26px;
  }
}

@media (min-width: 820px) and (orientation: landscape) {
  .mobile-shell {
    grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto auto auto auto;
    grid-template-areas:
      "top top"
      "toppeek toppeek"
      "canvas canvas"
      "controls actions"
      "cardtype cardtype"
      "result result"
      "bottompeek bottompeek";
    width: min(100vw, 1530px);
    height: 100svh;
    min-height: 100svh;
    max-height: 100svh;
    gap: 5px;
    padding: max(4px, env(safe-area-inset-top)) clamp(5px, 0.9vw, 30px) max(5px, env(safe-area-inset-bottom));
    overflow: hidden;
  }

  .summary-panel {
    position: relative;
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(270px, auto) minmax(260px, 1fr);
    grid-template-areas:
      "grades brand quick"
      ". ratio quick";
    align-items: start;
    column-gap: clamp(18px, 3vw, 56px);
    padding: 10px clamp(14px, 2vw, 28px) 8px;
  }

  .panel-brand {
    grid-area: brand;
    position: static;
    min-height: 62px;
    padding-top: 0;
  }

  .panel-brand strong {
    font-size: clamp(34px, 2.7vw, 44px);
  }

  .panel-brand small {
    margin-top: 2px;
    font-size: 7px;
  }

  .collapse-summary {
    left: 50%;
    top: 48px;
    transform: translateX(-50%);
  }

  .media-actions {
    top: 10px;
    right: clamp(14px, 1.4vw, 24px);
    gap: 10px;
  }

  .media-button {
    width: 64px;
    min-height: 60px;
  }

  .summary-compact {
    display: contents;
  }

  .grade-grid {
    grid-area: grades;
    align-self: start;
    gap: clamp(14px, 2vw, 34px);
    padding-top: 22px;
  }

  .grade-card {
    min-height: 74px;
    background: transparent;
  }

  .grade-card span {
    font-size: 15px;
  }

  .grade-card strong {
    margin-top: 14px;
    font-size: 22px;
  }

  .quick-actions {
    grid-area: quick;
    justify-self: end;
    align-self: end;
    width: min(304px, 100%);
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    padding-top: 86px;
  }

  .summary-action {
    min-height: 106px;
    border: 1px solid rgba(222, 199, 160, 0.18);
    background: rgba(0, 0, 0, 0.36);
  }

  .ratio-grid {
    grid-area: ratio;
    width: min(632px, 42vw);
    justify-self: center;
    margin-top: -2px;
    padding: 12px 16px;
    border: 1px solid rgba(222, 199, 160, 0.16);
    background: rgba(14, 13, 12, 0.88);
  }

  .canvas-area,
  #mobileCanvas {
    min-height: 0;
    height: 100%;
  }

  .canvas-area {
    align-self: stretch;
  }

  .control-panel {
    grid-template-columns: minmax(250px, max-content) minmax(150px, 170px) minmax(150px, 170px);
    align-content: center;
    align-items: end;
    gap: 14px;
    justify-content: start;
    padding: 10px 4px 4px clamp(26px, 2vw, 32px);
    overflow: visible;
  }

  .control-block span {
    font-size: 11px;
  }

  .swatches {
    gap: 5px;
    margin-top: 5px;
    max-width: 238px;
  }

  .stepper {
    grid-template-columns: 46px minmax(62px, 1fr) 46px;
    margin-top: 4px;
  }

  .action-row {
    grid-template-columns: repeat(6, minmax(78px, 1fr));
    align-content: center;
    align-items: end;
    gap: 8px;
    padding: 10px clamp(26px, 2vw, 32px) 4px 12px;
  }

  #generateAnalysis,
  .bottom-hide-eye {
    grid-column: auto;
  }

  .filters-menu,
  .overlay-menu {
    top: calc(100% + 6px);
    bottom: auto;
  }

  .bottom-nav {
    justify-self: stretch;
    width: 100%;
    padding: 4px clamp(26px, 2vw, 32px) 18px;
  }

  .donate-button {
    min-height: 56px;
    font-size: 19px;
  }
}

@media (min-width: 1200px) and (orientation: landscape) {
  .mobile-shell {
    grid-template-columns: minmax(520px, 0.9fr) minmax(680px, 1.1fr);
    width: min(100vw, 1530px);
  }

  .canvas-area,
  #mobileCanvas {
    min-height: 0;
  }
}

@media (min-width: 820px) and (orientation: landscape) and (max-height: 760px) {
  .mobile-shell {
    gap: 4px;
    padding-block: max(3px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-bottom));
  }

  .summary-panel,
  .control-panel,
  .action-row {
    padding-block: 4px;
  }

  .panel-brand {
    min-height: 54px;
  }

  .panel-brand strong {
    font-size: 34px;
  }

  .collapse-summary {
    top: 42px;
  }

  .media-button {
    width: 54px;
    min-height: 52px;
  }

  .ratio-grid {
    margin-top: 3px;
    padding-block: 4px;
  }

  .grade-card {
    min-height: 62px;
  }

  .grade-card strong {
    margin-top: 4px;
    font-size: 22px;
  }

  .summary-action {
    min-height: 86px;
  }

  .quick-actions {
    padding-top: 72px;
    width: 286px;
  }

  .stepper button,
  .action-row button,
  .action-menu-button {
    min-height: 38px;
  }

  .donate-button {
    min-height: 48px;
  }

  .swatch {
    width: 16px;
    min-height: 16px;
    height: 16px;
  }

  .control-panel {
    grid-template-columns: minmax(220px, max-content) minmax(138px, 154px) minmax(138px, 154px);
    gap: 10px;
  }

  .swatches {
    max-width: 216px;
  }

  .stepper {
    grid-template-columns: 38px minmax(54px, 1fr) 38px;
  }

  .canvas-area,
  #mobileCanvas {
    min-height: 0;
  }
}

@media (min-width: 820px) and (orientation: landscape) {
  .inline-cardtype-toolbar {
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: 10px;
    margin: 0 clamp(26px, 2vw, 32px);
    padding: 8px 10px;
  }

  .inline-cardtype-toolbar label {
    grid-column: auto;
    gap: 4px;
  }

  .inline-cardtype-toolbar label span {
    font-size: 10px;
  }

  .inline-cardtype-toolbar input {
    min-height: 26px;
  }
}

.rotate-sheet,
.capture-sheet,
.tool-sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: end center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.92);
}

.rotate-sheet[hidden],
.capture-sheet[hidden],
.tool-sheet[hidden] {
  display: none !important;
}

.rotate-stage,
.capture-stage {
  display: grid;
  grid-template-rows: auto minmax(320px, 1fr) auto;
  gap: 14px;
  width: min(430px, 100%);
  height: min(760px, 100svh - 24px);
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #030303;
  box-shadow: inset 0 0 22px rgba(255, 255, 255, 0.06), 0 18px 45px rgba(0, 0, 0, 0.8);
}

.rotate-top,
.capture-top {
  display: grid;
  grid-template-columns: 82px 1fr 82px;
  align-items: center;
  gap: 8px;
}

.rotate-top div,
.capture-top div {
  text-align: center;
}

.rotate-top strong,
.rotate-top span,
.capture-top strong,
.capture-top span {
  display: block;
}

.rotate-top strong,
.capture-top strong {
  font-size: 18px;
}

.rotate-top span,
.capture-top span {
  margin-top: 4px;
  color: var(--accent);
  font-size: 15px;
  font-weight: 900;
}

.rotate-top button,
.rotate-controls button,
.capture-top button,
.capture-controls button {
  min-height: 44px;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

#rotateConfirm,
#rotateConfirm {
  color: #000;
  background: var(--accent);
}

.rotate-preview,
.capture-preview {
  position: relative;
  min-height: 320px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.06) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(0deg, rgba(255,255,255,0.06) 1px, transparent 1px) 0 0 / 24px 24px,
    #020202;
}

#rotateCanvas,
#captureCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 320px;
}

#captureVideo {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 320px;
  object-fit: contain;
  background: #020202;
}

#captureVideo[hidden] {
  display: none !important;
}

#captureCanvas.live-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: transparent;
  pointer-events: none;
}

.capture-preview,
#captureCanvas {
  touch-action: none;
}

.capture-shutter {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 5;
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  min-height: 72px;
  padding: 0;
  border: 4px solid rgba(216,179,122,0.98);
  border-radius: 999px;
  background: rgba(0,0,0,0.42);
  box-shadow: 0 0 22px rgba(216,179,122,0.38), inset 0 0 16px rgba(255,255,255,0.12);
  pointer-events: auto;
  transform: translateX(-50%);
}

.capture-shutter span {
  display: block;
  width: 50px;
  height: 50px;
  border-radius: inherit;
  background: linear-gradient(180deg, #fffaf0, #d6b37a);
  box-shadow: inset 0 -4px 9px rgba(0,0,0,0.18);
}

.capture-shutter:active span {
  transform: scale(0.9);
}

.capture-shutter b {
  display: none;
}

.capture-review-mode .capture-shutter {
  width: min(220px, calc(100% - 36px));
  height: 58px;
  min-height: 58px;
  border-width: 1px;
  border-radius: 10px;
  color: #070605;
  background: linear-gradient(180deg, #fff0c8, #d6b37a);
}

.capture-review-mode .capture-shutter span {
  display: none;
}

.capture-review-mode .capture-shutter b {
  display: block;
  font-size: 15px;
  font-weight: 1000;
  letter-spacing: 0;
}

.capture-frame {
  position: absolute;
  border: 2px solid rgba(216, 179, 122, 0.98);
  border-radius: 12px;
  box-shadow: 0 0 18px rgba(216,179,122,0.34), inset 0 0 22px rgba(216,179,122,0.1);
  pointer-events: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.capture-frame::before,
.capture-frame::after {
  content: "";
  position: absolute;
  background: rgba(216,179,122,0.72);
  box-shadow: 0 0 8px rgba(216,179,122,0.42);
}

.capture-frame::before {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
}

.capture-frame::after {
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
}

.capture-ready .capture-frame {
  border-color: rgba(140, 255, 87, 0.98);
  box-shadow: 0 0 20px rgba(140,255,87,0.36), inset 0 0 22px rgba(140,255,87,0.1);
}

.capture-ready .capture-frame::before,
.capture-ready .capture-frame::after {
  background: rgba(140,255,87,0.74);
  box-shadow: 0 0 8px rgba(140,255,87,0.42);
}

.capture-level-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  color: #d6b37a;
  text-shadow: 0 0 10px rgba(0,0,0,0.8);
}

.capture-level-overlay[hidden] {
  display: none !important;
}

.level-rail,
.level-visual-horizon,
.level-cross,
.level-status,
#captureLevelEnable {
  position: absolute;
}

.level-rail {
  border: 1px solid rgba(243,234,216,0.18);
  background: rgba(0,0,0,0.46);
  box-shadow: inset 0 0 12px rgba(255,255,255,0.06), 0 0 18px rgba(0,0,0,0.34);
}

.level-rail i,
.level-cross i {
  position: absolute;
  background: currentColor;
  opacity: 0.78;
  box-shadow: 0 0 10px currentColor;
}

.level-rail b,
.level-cross b {
  position: absolute;
  display: block;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 14px currentColor;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.level-rail-x {
  left: 50%;
  top: 14px;
  width: min(210px, 58%);
  height: 25px;
  border-radius: 999px;
  transform: translateX(-50%);
}

.level-rail-x i {
  left: 50%;
  top: 3px;
  bottom: 3px;
  width: 1px;
}

.level-rail-x b {
  left: calc(50% - 7px);
  top: 5px;
  width: 14px;
  height: 14px;
}

.level-rail-y {
  right: 14px;
  top: 50%;
  width: 25px;
  height: min(210px, 58%);
  border-radius: 999px;
  transform: translateY(-50%);
}

.level-rail-y i {
  left: 3px;
  right: 3px;
  top: 50%;
  height: 1px;
}

.level-rail-y b {
  left: 5px;
  top: calc(50% - 7px);
  width: 14px;
  height: 14px;
}

.level-cross {
  left: 50%;
  top: 50%;
  width: 86px;
  height: 86px;
  border: 2px solid currentColor;
  border-radius: 999px;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 18px currentColor, inset 0 0 18px rgba(255,255,255,0.05);
}

.level-cross i:first-child {
  left: 50%;
  top: -38px;
  bottom: -38px;
  width: 1px;
}

.level-cross i:nth-child(2) {
  left: -38px;
  right: -38px;
  top: 50%;
  height: 1px;
}

.level-cross b {
  left: calc(50% - 8px);
  top: calc(50% - 8px);
  width: 16px;
  height: 16px;
}

.level-visual-horizon {
  left: 50%;
  top: 50%;
  width: 76%;
  height: 2px;
  color: #f2c84b;
  transform-origin: center;
  pointer-events: none;
}

.level-visual-horizon[hidden] {
  display: none !important;
}

.level-visual-horizon i {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  background: currentColor;
  box-shadow: 0 0 12px currentColor;
}

.level-visual-horizon b {
  position: absolute;
  left: 50%;
  top: -7px;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-radius: 999px;
  background: rgba(0,0,0,0.52);
  transform: translateX(-50%);
  box-shadow: 0 0 12px currentColor;
}

.level-status {
  left: 50%;
  top: 10px;
  display: block;
  min-width: 0;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0,0,0,0.46);
  text-align: center;
  transform: translateX(-50%);
  white-space: nowrap;
}

.level-status strong,
.level-status span {
  display: none;
}

.level-status em {
  font-style: normal;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  opacity: 0.82;
}

#captureLevelEnable {
  left: 50%;
  top: 52px;
  min-height: 38px;
  padding: 0 14px;
  pointer-events: auto;
  color: #0b0a08;
  background: linear-gradient(180deg, #9aff63, #5fe63d);
  transform: translateX(-50%);
}

.level-level {
  color: #8cff57;
}

.level-warn,
.level-waiting,
.level-visual {
  color: #f2c84b;
}

.level-tilt,
.level-unavailable {
  color: #ff4f45;
}

.level-unavailable .level-rail,
.level-unavailable .level-cross {
  opacity: 0.34;
}

.corner-frame {
  position: absolute;
  inset: 20px;
  pointer-events: none;
}

.corner-frame span {
  position: absolute;
  width: 42px;
  height: 42px;
  border-color: rgba(255, 255, 255, 0.82);
  filter: drop-shadow(0 0 8px rgba(255,255,255,0.42));
}

.corner-frame span:nth-child(1) {
  left: 0;
  top: 0;
  border-top: 2px solid;
  border-left: 2px solid;
}

.corner-frame span:nth-child(2) {
  right: 0;
  top: 0;
  border-top: 2px solid;
  border-right: 2px solid;
}

.corner-frame span:nth-child(3) {
  right: 0;
  bottom: 0;
  border-right: 2px solid;
  border-bottom: 2px solid;
}

.corner-frame span:nth-child(4) {
  left: 0;
  bottom: 0;
  border-left: 2px solid;
  border-bottom: 2px solid;
}

.rotate-controls,
.capture-controls {
  display: grid;
  gap: 10px;
}

.capture-controls {
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
}

@media (max-width: 520px) {
  .capture-controls {
    grid-template-columns: minmax(0, 1fr);
  }
}

#rotateSlider {
  width: 100%;
  min-height: 44px;
  accent-color: var(--accent);
}

.tick-track {
  display: grid;
  grid-template-columns: repeat(21, 1fr);
  align-items: end;
  height: 22px;
  padding-inline: 10px;
}

.tick-track i {
  justify-self: center;
  width: 1px;
  height: 9px;
  background: rgba(255, 255, 255, 0.34);
}

.tick-track i.major {
  height: 18px;
  background: rgba(255, 255, 255, 0.78);
}

.analysis-modal,
.history-panel,
.donate-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(10px);
}

.tool-card {
  display: grid;
  gap: 14px;
  width: min(430px, 100%);
  max-height: calc(100svh - 24px);
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #030303;
  box-shadow: inset 0 0 22px rgba(255, 255, 255, 0.06), 0 18px 45px rgba(0, 0, 0, 0.8);
}

.tool-card header,
.tool-actions {
  display: grid;
  gap: 8px;
  align-items: center;
}

.tool-card header {
  grid-template-columns: 1fr auto;
}

.tool-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tool-card header strong {
  font-size: 18px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.preset-grid button.active {
  border-color: rgba(214, 179, 122, 0.86);
  color: #080706;
  background: linear-gradient(180deg, #d6b37a, #c8a46a);
}

.angle-control {
  display: grid;
  gap: 8px;
}

.angle-control span {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.angle-control strong {
  color: var(--accent);
}

.angle-control input {
  width: 100%;
  min-height: 44px;
  accent-color: var(--accent);
}

.perspective-card {
  width: min(520px, 100%);
}

.perspective-help {
  margin: -4px 0 0;
  color: rgba(243,234,216,0.72);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.perspective-workspace {
  display: grid;
  justify-items: center;
}

.perspective-panel {
  display: none;
}

#perspectiveCanvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #020202;
  touch-action: none;
}

@media (min-width: 820px) and (orientation: landscape) {
  .perspective-card {
    width: min(1200px, calc(100vw - 40px));
    max-height: calc(100svh - 24px);
    padding: 20px 24px;
  }

  .perspective-card header strong {
    font-size: 28px;
    letter-spacing: 1px;
    text-transform: uppercase;
  }

  .perspective-help {
    font-size: 18px;
  }

  .perspective-workspace {
    width: 100%;
    grid-template-columns: minmax(150px, 180px) minmax(520px, 760px) minmax(150px, 180px);
    align-items: center;
    justify-content: center;
    gap: 18px;
  }

  .perspective-panel {
    align-self: stretch;
    display: grid;
    align-content: center;
    gap: 14px;
    min-height: 460px;
    padding: 18px 14px;
    border: 1px solid rgba(216, 189, 131, 0.16);
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(12,11,9,0.88), rgba(3,3,3,0.72));
  }

  .perspective-panel strong {
    color: rgba(243,234,216,0.72);
    font-size: 14px;
    font-weight: 900;
    letter-spacing: 0.5px;
  }

  .perspective-panel label {
    display: grid;
    gap: 9px;
  }

  .perspective-panel label span {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: rgba(243,234,216,0.82);
    font-size: 13px;
    font-weight: 900;
  }

  .perspective-panel label em {
    color: #d6b37a;
    font-style: normal;
  }

  .perspective-panel small {
    display: block;
    margin-top: -8px;
    color: rgba(243,234,216,0.48);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.4px;
  }

  .perspective-panel input[type="range"] {
    width: 100%;
    min-height: 44px;
    accent-color: #c8a46a;
  }

  #perspectiveCanvas {
    justify-self: center;
    width: min(760px, 100%);
  }

  .perspective-card .tool-actions {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

.analysis-modal[hidden],
.history-panel[hidden],
.donate-modal[hidden] {
  display: none !important;
}

.analysis-card,
.history-card {
  position: relative;
  width: min(430px, 100%);
  max-height: calc(100svh - 28px);
  overflow: auto;
  border: 1px solid rgba(216, 189, 131, 0.28);
  border-radius: 10px;
  background: linear-gradient(180deg, #090909, #030303);
  box-shadow: 0 22px 60px rgba(0,0,0,0.86), inset 0 0 24px rgba(129,255,37,0.05);
}

.analysis-card {
  aspect-ratio: 3 / 4;
  display: grid;
  grid-template-rows: auto auto auto auto;
  padding: 14px;
  gap: 8px;
}

.modal-x {
  position: absolute;
  right: 10px;
  top: 10px;
  width: 38px;
  min-height: 38px;
  border-radius: 50%;
  font-size: 18px;
  z-index: 2;
}

.analysis-brand {
  text-align: center;
}

.analysis-brand strong {
  display: block;
  font-size: 28px;
  font-weight: 1000;
  line-height: 0.9;
}

.analysis-brand small,
.analysis-brand em {
  display: block;
  color: rgba(255,255,255,0.62);
  font-size: 9px;
  font-style: normal;
  letter-spacing: 1.2px;
}

.analysis-brand span {
  display: block;
  margin-top: 8px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 900;
}

.analysis-images {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.analysis-images figure {
  min-width: 0;
  margin: 0;
}

.analysis-images figcaption {
  margin-bottom: 4px;
  color: #fff;
  font-size: 11px;
  text-align: center;
}

.analysis-images img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  height: auto;
  max-height: 218px;
  object-fit: contain;
  border: 1px solid rgba(216, 189, 131, 0.76);
  border-radius: 7px;
  background: #020202;
}

.analysis-summary {
  display: grid;
  gap: 7px;
}

.analysis-summary h2 {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0;
  font-size: 14px;
}

.analysis-summary h2 i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.analysis-grades,
.analysis-ratios {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.analysis-ratios {
  grid-template-columns: repeat(2, 1fr);
}

.analysis-grades div,
.analysis-ratios div {
  padding: 7px 4px;
  border: 1px solid var(--line);
  border-radius: 7px;
  text-align: center;
  background: rgba(255,255,255,0.035);
}

.analysis-grades span,
.analysis-ratios span {
  display: block;
  font-size: 10px;
}

.analysis-grades strong,
.analysis-ratios strong {
  display: block;
  margin-top: 3px;
  color: var(--accent);
  font-size: 20px;
}

.analysis-ratios strong {
  font-size: 15px;
}

.analysis-ratios div:nth-child(3) {
  display: none;
}

.analysis-verdict {
  padding: 8px;
  border: 1px solid rgba(129,255,37,0.72);
  border-radius: 8px;
  text-align: center;
}

.analysis-verdict strong {
  display: block;
  color: var(--accent);
  font-size: 16px;
}

.analysis-verdict span,
#modalDate {
  display: block;
  color: rgba(255,255,255,0.7);
  font-size: 12px;
  text-align: center;
}

.analysis-contact {
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border: 1px solid rgba(216, 189, 131, 0.65);
  border-radius: 8px;
  text-align: center;
  background: rgba(216, 189, 131, 0.035);
  font-family: 'DM Sans', Arial, sans-serif;
}

.analysis-contact strong {
  color: var(--accent);
  font-size: 13px;
  font-weight: 1000;
}

.analysis-contact span {
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}

.analysis-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.analysis-actions .primary {
  grid-column: 1 / -1;
  color: #000;
  background: var(--accent);
  font-weight: 1000;
}

.analysis-actions .danger,
.history-delete {
  color: #ff4545;
}

.history-card {
  padding: 12px;
}

.history-head {
  display: grid;
  grid-template-columns: 68px 1fr 68px;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.history-head strong {
  text-align: center;
}

.storage-meter {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.storage-meter i {
  grid-column: 1 / -1;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,0.14);
}

.storage-meter b {
  display: block;
  height: 100%;
  background: var(--accent);
}

.history-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.history-item {
  display: grid;
  grid-template-columns: 24px 1fr 64px;
  gap: 7px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.history-load {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
  padding: 0;
  border: 0;
  text-align: left;
  background: transparent;
}

.history-thumbs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.history-thumbs img {
  width: 44px;
  height: 58px;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,0.22);
}

.history-meta strong,
.history-meta small,
.history-meta em,
.history-meta b {
  display: block;
}

.history-meta small,
.history-meta em {
  color: rgba(255,255,255,0.68);
  font-size: 10px;
  font-style: normal;
}

.history-meta b {
  color: var(--accent);
  font-size: 11px;
}

.history-item-actions {
  display: grid;
  gap: 6px;
}

.history-edit,
.history-delete {
  min-height: 36px;
  font-size: 10px;
}

.history-edit {
  color: var(--accent);
}

.history-actions {
  margin-top: 10px;
}

.history-actions button {
  width: 100%;
}

.history-empty {
  padding: 24px;
  color: rgba(255,255,255,0.62);
  text-align: center;
}

.donate-modal {
  z-index: 45;
  background: rgba(0, 0, 0, 0.86);
}

.donate-card {
  position: relative;
  width: min(430px, 100%);
  max-height: calc(100svh - 28px);
  overflow: auto;
  border: 1px solid rgba(216, 189, 131, 0.34);
  border-radius: 10px;
  background: #030303;
  box-shadow: 0 22px 60px rgba(0,0,0,0.88), inset 0 0 24px rgba(216, 189, 131, 0.05);
}

.donate-card img {
  display: block;
  width: 100%;
  height: auto;
  background: #000;
}

.donate-fallback {
  display: grid;
  gap: 12px;
  padding: 56px 22px 24px;
  color: #fff;
  text-align: center;
  font-family: 'DM Sans', Arial, sans-serif;
}

.donate-fallback[hidden] {
  display: none !important;
}

.donate-fallback strong {
  color: var(--accent);
  font-size: 24px;
  font-weight: 1000;
}

.donate-fallback span {
  font-size: 22px;
  font-weight: 900;
}

.donate-fallback > span:not(.donate-live),
.donate-fallback > em:not(.donate-live),
.donate-fallback > small:not(.donate-live) {
  display: none;
}

.donate-fallback em {
  color: rgba(255,255,255,0.86);
  font-size: 18px;
  font-style: normal;
  font-weight: 800;
}

.donate-fallback small {
  margin-top: 10px;
  color: var(--accent);
  font-size: 22px;
}

.mobile-debug {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 70;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 8px;
  padding: 10px;
  border: 1px solid rgba(129,255,37,0.58);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.88);
  color: rgba(255,255,255,0.82);
  font-size: 10px;
  pointer-events: none;
  box-shadow: 0 0 20px rgba(129,255,37,0.16);
}

.mobile-debug[hidden] {
  display: none !important;
}

.mobile-debug strong {
  grid-column: 1 / -1;
  color: var(--accent);
  font-size: 11px;
}

/* Brand alignment with rawlity.co — DM Serif wordmark */
.panel-brand strong { font-family: "DM Serif Display", serif; letter-spacing: .02em; }

/* ── Luxury polish — align to rawlity.co design language ── */
.canvas-area { position: relative; }
.canvas-area::before,
.canvas-area::after {
  content: ""; position: absolute; width: 26px; height: 26px;
  border-color: var(--accent); border-style: solid; opacity: .5;
  pointer-events: none; z-index: 4;
  transition: opacity .3s ease, inset .3s ease;
}
.canvas-area::before { top: 12px; left: 12px;  border-width: 1.5px 0 0 1.5px; }
.canvas-area::after  { bottom: 12px; right: 12px; border-width: 0 1.5px 1.5px 0; }
/* depth instead of a flat void (only seen when empty; canvas covers it once an image loads) */
.empty-state strong {
  font-family: "DM Serif Display", serif; font-weight: 400;
  letter-spacing: .05em; font-size: 1.18rem;
}
.empty-state span { letter-spacing: .22em; opacity: .8; }

/* ════════════════════════════════════════════════════════════════════
   DESKTOP LANDSCAPE — PHOTO-EDITOR SHELL (Photoshop-style)
   This block is LAST in the file, so it wins the cascade over every earlier
   desktop block for the properties it sets.  Layout:

        ┌──────────────────────────────────────────────────────┐
        │  TOP BAR   wordmark · Upload / Camera / SAVE          │
        ├──────┬────────────────────────────────────┬──────────┤
        │ TOOL │                                     │ PROPERTY │
        │ RAIL │           HERO  CANVAS              │  PANEL   │
        │ (L)  │            (dominant)               │   (R)    │
        ├──────┴────────────────────────────────────┴──────────┤
        │  STATUS STRIP (inline card-type toolbar / peeks)      │
        └──────────────────────────────────────────────────────┘

   Technique: the template keeps its original section wrappers, but here we set
   display:contents on .summary-panel / .summary-compact / .action-row so their
   leaf groups become direct grid items of .mobile-shell and can be assigned to
   editor zones.  Every id + JS-targeted class is preserved.  top-hidden /
   bottom-hidden / advanced-open toggles still set display:none on the wrappers
   (higher specificity), so show/hide keeps working.
   Mobile/portrait is a different media query and is untouched.
   ════════════════════════════════════════════════════════════════════ */
@media (min-width: 820px) and (orientation: landscape) {
  .mobile-shell {
    grid-template-columns: clamp(98px, 7.5vw, 118px) minmax(0, 1fr) clamp(280px, 24vw, 340px);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "topbar  topbar  topbar"
      "tools   canvas  panel"
      "status  status  status"
      "status2 status2 status2";
    width: 100%;
    max-width: none;
    height: 100svh;
    min-height: 100svh;
    max-height: 100svh;
    gap: clamp(8px, 0.9vw, 14px);
    padding: clamp(8px, 1vh, 14px) clamp(10px, 1.4vw, 22px) clamp(8px, 1vh, 14px);
    overflow: hidden;
    background:
      radial-gradient(120% 60% at 50% -8%, rgba(216,189,131,0.08), transparent 60%),
      linear-gradient(90deg, rgba(222,199,160,0.018) 1px, transparent 1px) 0 0 / 34px 34px,
      var(--bg);
  }

  /* ── wrappers become transparent so their children are grid items ──── */
  .summary-panel,
  .action-row {
    display: contents;
  }

  /* ════ TOP BAR ═══════════════════════════════════════════════════════
     .panel-brand holds the wordmark, the absolute .media-actions (Upload /
     Camera / SAVE) and the file inputs.  Stretch it across the top. ─────── */
  .panel-brand {
    grid-area: topbar;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    min-height: 0;
    height: clamp(54px, 7vh, 70px);
    padding: 0 clamp(220px, 22vw, 320px) 0 clamp(54px, 5vw, 64px);
    border: 1px solid var(--line);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(20,17,13,0.94), rgba(8,7,6,0.9));
    backdrop-filter: blur(12px);
  }

  .panel-brand strong {
    font-family: "DM Serif Display", serif;
    font-weight: 400;
    font-size: clamp(24px, 2.2vw, 34px);
    line-height: 1;
    letter-spacing: 0.06em;
    text-shadow: 0 0 18px rgba(216,189,131,0.22);
  }

  .panel-brand small {
    margin: 0 0 0 14px;
    color: rgba(243,234,216,0.5);
    font-size: 8px;
    letter-spacing: 0.3em;
    align-self: center;
  }

  .panel-brand::after { display: none; }   /* drop the underline in the bar */

  /* primary actions: right side of the top bar */
  .media-actions {
    position: absolute;
    top: 50%;
    right: clamp(12px, 1.4vw, 20px);
    transform: translateY(-50%);
    gap: 8px;
    z-index: 14;
  }

  .media-button {
    width: 50px;
    min-height: 42px;
    border-radius: 10px;
    border-color: var(--line-strong);
    background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.012));
  }

  .save-button {
    min-width: 62px;
    min-height: 42px;
  }

  /* eye / hide-top toggle pinned to the far left of the bar */
  .collapse-summary {
    position: absolute;
    left: clamp(12px, 1.2vw, 18px);
    top: 50%;
    transform: translateY(-50%);
    z-index: 14;
  }

  /* ════ LEFT TOOL RAIL ════════════════════════════════════════════════
     The 4 primary tools stacked vertically as icon tiles. ───────────────── */
  .toolrail-group {
    grid-area: tools;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-content: start;
    padding: 10px 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(18,16,12,0.7), rgba(6,6,5,0.6));
    overflow-y: auto;
  }

  .toolrail-group > button {
    width: 100%;
    min-height: clamp(56px, 8vh, 72px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 2px;
    border-radius: 12px;
    font-size: 9px;
    letter-spacing: 0.04em;
    background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(0,0,0,0.3));
  }

  .toolrail-group > button.active {
    border-color: var(--accent);
    box-shadow: inset 0 0 14px rgba(216,189,131,0.18);
  }

  .toolrail-group .tool-icon-button b {
    font-size: 9px;
  }

  /* ════ HERO CANVAS — the dominant centre region ──────────────────────── */
  .canvas-area {
    grid-area: canvas;
    align-self: stretch;
    justify-self: stretch;
    min-height: 0;
    height: 100%;
    border: 1px solid var(--line-strong);
    border-radius: 16px;
    background:
      radial-gradient(120% 90% at 50% 0%, rgba(216,189,131,0.07), transparent 62%),
      radial-gradient(90% 70% at 50% 120%, rgba(216,189,131,0.04), transparent 70%),
      linear-gradient(180deg, #0a0908, #040403);
    box-shadow:
      inset 0 0 60px rgba(0,0,0,0.7),
      inset 0 0 1px rgba(216,189,131,0.3),
      0 24px 60px rgba(0,0,0,0.55);
  }

  #mobileCanvas { border-radius: 15px; }

  /* four bright viewfinder corner brackets on the hero */
  .canvas-area::before,
  .canvas-area::after {
    width: 40px;
    height: 40px;
    border-width: 2px 0 0 2px;
    opacity: 0.85;
    filter: drop-shadow(0 0 6px rgba(216,189,131,0.25));
  }
  .canvas-area::before { top: 16px; left: 16px; }
  .canvas-area::after  { top: 16px; right: 16px; left: auto; bottom: auto;
                         border-width: 2px 2px 0 0; }

  .canvas-area > #emptyState::before,
  .canvas-area > #emptyState::after {
    content: "";
    position: absolute;
    width: 40px;
    height: 40px;
    border-color: var(--accent);
    border-style: solid;
    opacity: 0.85;
    filter: drop-shadow(0 0 6px rgba(216,189,131,0.25));
    pointer-events: none;
  }
  .canvas-area > #emptyState::before { bottom: 16px; left: 16px; top: auto;
                                       border-width: 0 0 2px 2px; }
  .canvas-area > #emptyState::after  { bottom: 16px; right: 16px; top: auto;
                                       border-width: 0 2px 2px 0; }

  .empty-state strong {
    font-size: 1.4rem;
    color: var(--accent);
    text-shadow: 0 0 24px rgba(216,189,131,0.3);
  }
  .empty-state span { color: rgba(243,234,216,0.5); }

  /* ════ RIGHT PROPERTIES PANEL ════════════════════════════════════════
     .desk-inspector is the single scrollable property rail.  Its children —
     the grade grid, the quick actions and the ratio readout — stack as tidy
     framed "panels".  One grid item, so no inter-panel overlap is possible. */
  .desk-inspector {
    grid-area: panel;
    display: flex;
    flex-direction: column;
    gap: clamp(10px, 1.4vh, 16px);
    min-height: 0;
    height: 100%;
    padding: 2px;
    overflow-y: auto;
  }

  .summary-compact {
    display: flex;
    flex-direction: column;
    gap: clamp(10px, 1.4vh, 16px);
    width: 100%;
  }

  /* force every inspector block to the full panel width (override earlier
     desktop rules that set fixed widths / justify-self for the old layout) */
  .desk-inspector .grade-grid,
  .desk-inspector .ratio-grid,
  .desk-inspector .quick-actions,
  .desk-inspector .summary-compact {
    width: 100%;
    max-width: none;
    min-width: 0;
    justify-self: stretch;
    align-self: stretch;
    flex: 0 0 auto;
  }

  .grade-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    margin: 0;
    padding: 12px 6px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(255,255,255,0.025), rgba(0,0,0,0.28));
    box-shadow: inset 0 0 22px rgba(216,189,131,0.04);
  }

  .grade-card {
    position: relative;
    min-height: 0;
    padding: 4px 2px;
    background: transparent;
  }

  .grade-card + .grade-card::before {
    content: "";
    position: absolute;
    left: 0; top: 16%; bottom: 16%;
    width: 1px;
    background: var(--line);
  }

  .grade-card span {
    color: rgba(243,234,216,0.62);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.16em;
  }

  .grade-card strong {
    margin-top: 8px;
    font-family: "DM Serif Display", serif;
    font-weight: 400;
    font-size: 22px;
    color: var(--accent);
  }

  .quick-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 0;
    padding: 0;
  }

  .summary-action {
    min-height: 72px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(0,0,0,0.34));
    box-shadow: inset 0 0 16px rgba(216,189,131,0.05);
  }

  .ratio-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px 4px;
    margin: 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(16,14,12,0.9), rgba(6,6,6,0.82));
  }

  .ratio-grid span {
    color: rgba(243,234,216,0.5);
    font-size: 10px;
    letter-spacing: 0.14em;
  }
  .ratio-grid strong { font-size: 14px; }
  .ratio-grid div:nth-child(3) strong,
  .ratio-grid div:nth-child(6) strong { font-size: 16px; }

  /* ════ BOTTOM STATUS STRIP ════════════════════════════════════════════
     The control-panel (colour / opacity, shown when Advanced is on) plus the
     remaining .advanced-tool buttons (Reset View / Filters / Overlay / Hide
     UI) and the inline card-type toolbar all share the status row.  They are
     hidden by default (advanced-tool / [hidden]); when shown they sit in one
     centered horizontal strip and never overlap the tool rail or panel. ──── */
  .control-panel {
    grid-area: status;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: clamp(14px, 2vw, 28px);
    margin: 0;
    padding: 8px clamp(16px, 2vw, 32px);
    border: 1px solid var(--line);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(18,16,12,0.7), rgba(6,6,5,0.6));
  }

  .control-block {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .control-block span {
    font-size: 10px;
    letter-spacing: 0.16em;
    color: rgba(243,234,216,0.6);
  }
  .swatches { max-width: none; }

  /* leftover (advanced) action buttons share their own status2 row as one
     centered horizontal strip. They only appear when Advanced is on, so the
     default status2 row collapses to nothing. */
  .action-extra {
    grid-area: status2;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
  }

  .action-extra .action-menu { position: relative; }
  .action-row .action-menu-button { border-radius: 10px; }
  #resetView, .bottom-hide-eye { border-radius: 10px; }

  .filters-menu,
  .overlay-menu {
    bottom: calc(100% + 6px);
    top: auto;
  }

  /* inline card-type toolbar (corner editing) takes the status row when active */
  .inline-cardtype-toolbar {
    grid-area: status;
    max-width: 900px;
    margin-inline: auto;
  }

  /* peeks span the status / top strips when the bars are hidden */
  .bottom-peek { grid-area: status2; }
  .top-peek { grid-area: topbar; }
}

/* Taller desktops: let the hero stage breathe even more */
@media (min-width: 820px) and (orientation: landscape) and (min-height: 860px) {
  .summary-action { min-height: 84px; }
  .toolrail-group > button { min-height: 76px; }
}

/* ── Photoshop-style colour picker (native input styled as a swatch) ── */
.color-picker-input{width:30px;height:30px;padding:0;border:1px solid var(--line-strong);border-radius:8px;background:none;cursor:pointer;flex:0 0 auto;-webkit-appearance:none;appearance:none;}
.color-picker-input::-webkit-color-swatch-wrapper{padding:2px;}
.color-picker-input::-webkit-color-swatch{border:1px solid rgba(0,0,0,.35);border-radius:6px;}
.color-picker-input::-moz-color-swatch{border:1px solid rgba(0,0,0,.35);border-radius:6px;}

/* ── Desktop: no ADVANCED toggle (space is ample) — always show the
      colour/opacity + Reset/Filters/Overlay tools. Submenus stay [hidden]. ── */
@media (min-width: 820px) and (orientation: landscape) {
  #advancedButton { display: none; }
  .mobile-shell:not(.advanced-open) .control-panel { display: flex; }
  .mobile-shell:not(.advanced-open) #resetView,
  .mobile-shell:not(.advanced-open) .action-extra .action-menu,
  .mobile-shell:not(.advanced-open) #filtersButton,
  .mobile-shell:not(.advanced-open) #overlayButton { display: inline-flex; }
}

/* ── Desktop bottom toolbars: compact + centered (no full-width empty bars) ── */
@media (min-width: 820px) and (orientation: landscape) {
  .control-panel {
    justify-self: center;
    width: fit-content;
    max-width: calc(100% - 44px);
  }
  .action-extra {
    justify-self: center;
    width: fit-content;
    max-width: calc(100% - 44px);
    flex-wrap: nowrap;
    gap: 12px;
    margin-top: 2px;
    padding: 7px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(18,16,12,0.7), rgba(6,6,5,0.6));
  }
  .action-extra > * { flex: 0 0 auto; }
  /* buttons fit their label (no stretching), tidy & consistent */
  .action-extra #resetView,
  .action-extra .action-menu-button {
    width: auto;
    min-width: 0;
    min-height: 38px;
    padding: 0 16px;
    border-radius: 9px;
    letter-spacing: 0.08em;
  }
}

/* force compact/centered bottom toolbars (override any stretch defaults) */
@media (min-width: 820px) and (orientation: landscape) {
  .mobile-shell > .control-panel,
  .mobile-shell > .action-extra {
    justify-self: center !important;
    width: fit-content !important;
    max-width: calc(100% - 44px) !important;
  }
  .mobile-shell .action-extra #resetView,
  .mobile-shell .action-extra .action-menu-button { width: auto !important; flex: 0 0 auto !important; }
}

/* ── Canva-style left tool rail: bigger icon+label buttons, clean active ── */
@media (min-width: 820px) and (orientation: landscape) {
  .mobile-shell .toolrail-group {
    gap: 10px;
    padding: 12px 10px;
    background: linear-gradient(180deg, rgba(20,17,13,0.5), rgba(6,6,5,0.36));
  }
  .mobile-shell .toolrail-group > button {
    min-height: clamp(88px, 12vh, 106px) !important;
    gap: 9px !important;
    padding: 14px 6px !important;
    border-radius: 16px !important;
    border: 1px solid transparent !important;
    background: transparent !important;
    transition: background .18s ease, border-color .18s ease, color .18s ease;
  }
  .mobile-shell .toolrail-group > button > span { transform: scale(1.12); }
  .mobile-shell .toolrail-group .tool-icon-button b {
    font-size: 11px !important;
    letter-spacing: 0.05em;
    margin-top: 2px;
  }
  .mobile-shell .toolrail-group > button:hover {
    background: rgba(239,216,185,0.06) !important;
    border-color: var(--line) !important;
  }
  .mobile-shell .toolrail-group > button.active {
    background: rgba(239,216,185,0.12) !important;
    border-color: var(--accent) !important;
    color: var(--accent) !important;
    box-shadow: inset 0 0 18px rgba(216,189,131,0.16) !important;
  }
  .mobile-shell .toolrail-group > button.active b { color: var(--accent); }
}

/* ── History = saved-analyses library: a labelled chip in the top bar (not a tool) ── */
.history-chip{
  font-size:11px !important;
  font-weight:700;
  letter-spacing:.1em;
  text-transform:uppercase;
  color:var(--accent);
  background:linear-gradient(180deg, rgba(255,255,255,0.04), rgba(0,0,0,0.28));
  border:1px solid var(--line-strong);
  border-radius:10px;
  padding:0 16px;
  min-height:54px;
  cursor:pointer;
  display:inline-flex;
  align-items:center;
  gap:8px;
}
.history-chip::before{
  content:"";
  width:13px;height:13px;flex:0 0 13px;
  border:1.5px solid currentColor;border-radius:3px;
  box-shadow:3px 3px 0 -1px currentColor;
  opacity:.9;
}
.history-chip:hover{background:rgba(239,216,185,0.1);border-color:var(--accent);}
@media (max-width:699px){ .history-chip{min-height:44px;padding:0 10px;font-size:10px !important;} }

/* ---- Auto Scan button (OpenCV client-side edge detection) ---- */
.auto-scan-button{
  width:auto;
  min-width:62px;
  padding-inline:12px;
  font-size:12px;
  font-weight:800;
  letter-spacing:0.4px;
  color:var(--accent);
  background:linear-gradient(180deg, rgba(239,216,185,0.14), rgba(200,164,106,0.08));
  border:1px solid rgba(214,179,122,0.7);
  box-shadow:inset 0 0 14px rgba(239,216,185,0.12), 0 0 12px rgba(239,216,185,0.1);
  position:relative;
}
.auto-scan-button::before{
  content:"";
  display:inline-block;
  width:13px;height:13px;
  margin-right:7px;
  vertical-align:-2px;
  border:1.5px solid currentColor;
  border-radius:3px;
  box-shadow:inset 0 0 0 2px transparent;
  background:
    linear-gradient(currentColor,currentColor) left top/4px 1.5px no-repeat,
    linear-gradient(currentColor,currentColor) right top/4px 1.5px no-repeat,
    linear-gradient(currentColor,currentColor) left bottom/4px 1.5px no-repeat,
    linear-gradient(currentColor,currentColor) right bottom/4px 1.5px no-repeat;
  opacity:0.92;
}
.auto-scan-button:hover:not(:disabled){
  border-color:var(--accent);
  background:linear-gradient(180deg, rgba(239,216,185,0.22), rgba(200,164,106,0.12));
}
.auto-scan-button:disabled{
  opacity:0.42;
  cursor:not-allowed;
  filter:grayscale(0.3);
}
.auto-scan-button.is-scanning{
  opacity:0.85;
  animation:autoScanPulse 0.9s ease-in-out infinite;
}
@keyframes autoScanPulse{
  0%,100%{ box-shadow:inset 0 0 14px rgba(239,216,185,0.12), 0 0 12px rgba(239,216,185,0.1); }
  50%{ box-shadow:inset 0 0 18px rgba(239,216,185,0.3), 0 0 18px rgba(239,216,185,0.28); }
}
.summary-panel.is-collapsed .auto-scan-button{
  min-width:52px;
  min-height:32px;
  padding-inline:8px;
  font-size:10px;
}
@media (max-width:699px){
  .auto-scan-button{ min-height:44px; font-size:11px; }
  .auto-scan-button::before{ width:12px;height:12px; margin-right:5px; }
}

/* ============================================================
   PHOTOSHOP / CANVA 3-ZONE REDESIGN  (.ps-shell)
   LEFT tools | CENTER canvas | RIGHT results + TOP options bar
   Overrides legacy grid via higher specificity (.mobile-shell.ps-shell)
   ============================================================ */
.mobile-shell.ps-shell{
  display:grid;
  grid-template-columns:112px minmax(0,1fr) 326px;
  grid-template-rows:58px minmax(0,1fr);
  grid-template-areas:"options options options" "tools canvas results";
  gap:0; width:100%; height:100svh; max-height:100svh; min-height:0;
  padding:0; overflow:hidden; background:#000000;
}
.ps-shell .ps-legacy{ position:absolute!important; width:1px;height:1px;opacity:0;pointer-events:none;overflow:hidden; }
.ps-shell #imageInput, .ps-shell #cameraInput{ position:absolute; width:1px;height:1px;opacity:0;pointer-events:none; }

/* ---- TOP OPTIONS BAR ---- */
.ps-shell .ps-optionsbar{
  grid-area:options; display:flex; align-items:center; gap:18px;
  padding:0 18px; min-height:58px; overflow-x:auto; overflow-y:hidden;
  background:#1a1a1a; border-bottom:1px solid rgba(255,244,212,.10);
}
.ps-shell .ps-brand{ display:flex; flex-direction:column; line-height:1.05; flex:0 0 auto; }
.ps-shell .ps-brand strong{ font-family:'DM Serif Display',serif; color:var(--accent,#efd8b9); font-size:16px; letter-spacing:.16em; }
.ps-shell .ps-brand small{ font-size:8px; letter-spacing:.34em; color:rgba(255,244,212,.5); }
.ps-shell .ps-optdivider{ width:1px; height:26px; background:rgba(255,244,212,.14); flex:0 0 auto; }
.ps-shell .ps-opt-title{ font-size:12px; letter-spacing:.18em; text-transform:uppercase; color:rgba(255,244,212,.68); white-space:nowrap; }
.ps-shell .ps-opt-title[hidden]{ display:none; }
.ps-shell .ps-opt{ display:none; }
.ps-shell .ps-opt:not([hidden]){ display:flex; align-items:center; gap:24px; }
.ps-shell .ps-opt-group{ display:flex; align-items:center; gap:10px; }
.ps-shell .ps-opt-group>span{ font-size:9px; letter-spacing:.2em; text-transform:uppercase; color:rgba(255,244,212,.55); }
.ps-shell .ps-opt-group .swatches{ display:flex; gap:5px; max-width:none; margin:0; }
.ps-shell .ps-opt-group .stepper{ display:grid; grid-template-columns:26px 46px 26px; align-items:center; }

/* ---- LEFT TOOL RAIL ---- */
.ps-shell .ps-toolrail{
  grid-area:tools; display:flex; flex-direction:column; align-items:stretch; gap:6px;
  padding:12px 8px; overflow-y:auto; overflow-x:visible;
  background:#1a1a1a; border-right:1px solid rgba(255,244,212,.10);
}
.ps-shell .ps-tool{
  position:relative; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:5px;
  min-height:64px; padding:8px 4px; border:1px solid transparent; border-radius:12px;
  background:transparent; color:rgba(255,244,212,.82); cursor:pointer; width:100%;
  transition:background .16s, color .16s, transform .12s, border-color .16s;
}
.ps-shell .ps-tool .ps-ico{ display:flex; align-items:center; justify-content:center; height:22px; font-size:19px; line-height:1; }
.ps-shell .ps-tool b{ font-size:10.5px; font-weight:600; letter-spacing:.03em; }
.ps-shell .ps-tool em#rotationBadge{ font-style:normal; font-size:9px; color:var(--accent,#efd8b9); }
.ps-shell .ps-tool:hover{ background:rgba(255,244,212,.07); color:var(--accent,#efd8b9); transform:translateY(-1px); }
.ps-shell .ps-tool.is-active, .ps-shell .ps-tool.active{
  background:rgba(255,244,212,.11); color:var(--accent,#efd8b9); border-color:rgba(255,244,212,.20);
}
.ps-shell .ps-tool.is-active::before, .ps-shell .ps-tool.active::before{
  content:""; position:absolute; left:-8px; top:14px; bottom:14px; width:3px; border-radius:0 2px 2px 0; background:var(--accent,#efd8b9);
}
.ps-shell .ps-tool .perspective-card-icon.ps-ico, .ps-shell .ps-tool .card-corner-icon.ps-ico{ width:24px; height:22px; transform:scale(.82); }
.ps-shell .ps-tool--sub{ min-height:50px; opacity:.74; }
.ps-shell .ps-tool--sub .ps-ico{ font-size:15px; height:18px; }
.ps-shell .ps-tool-sep{ height:1px; background:rgba(255,244,212,.12); margin:7px 4px; }
.ps-shell .ps-tool-wrap{ position:relative; }
.ps-shell .ps-popover{
  position:absolute; left:calc(100% + 8px); top:0; z-index:60; min-width:180px; margin:0;
  background:#242424; border:1px solid rgba(255,244,212,.18); border-radius:12px; padding:10px;
  box-shadow:0 18px 50px rgba(0,0,0,.62);
}
.ps-shell .ps-popover[hidden]{ display:none; }
.ps-shell .ps-popover:not([hidden]){ display:flex; flex-direction:column; gap:6px; }

/* ---- CENTER CANVAS ---- */
.ps-shell .canvas-area{ grid-area:canvas; position:relative; min-width:0; min-height:0; background:#000000; overflow:hidden; }
.ps-shell .empty-state.ps-dropzone{
  border:2px dashed rgba(255,244,212,.22); border-radius:18px; gap:8px;
  background:rgba(255,244,212,.02); padding:34px 28px;
}
.ps-shell .empty-state.ps-dropzone.dragover{ border-color:var(--accent,#efd8b9); background:rgba(255,244,212,.06); }
.ps-shell .ps-drop-ico{ font-size:34px; color:var(--accent,#efd8b9); line-height:1; }
.ps-shell .inline-cardtype-toolbar:not([hidden]){
  position:absolute; left:50%; bottom:14px; transform:translateX(-50%); z-index:30; width:min(640px,92%);
  display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:10px; margin:0; padding:10px 12px;
  background:rgba(13,13,13,.94); border:1px solid rgba(255,244,212,.16); border-radius:14px; backdrop-filter:blur(8px);
}

/* ---- RIGHT RESULTS PANEL ---- */
.ps-shell .ps-results{
  grid-area:results; display:flex; flex-direction:column; gap:12px; padding:20px 18px;
  background:#1a1a1a; border-left:1px solid rgba(255,244,212,.10); overflow-y:auto;
}
.ps-shell .ps-results-head{ font-family:'DM Serif Display',serif; color:var(--accent,#efd8b9); font-size:18px; letter-spacing:.18em; }
.ps-shell .ps-section-label{ display:flex; align-items:center; gap:6px; margin-top:4px; font-size:10px; letter-spacing:.22em; text-transform:uppercase; color:rgba(255,244,212,.5); }
.ps-shell .ps-section-label small{ display:inline-flex; align-items:center; justify-content:center; width:14px; height:14px; border-radius:50%; border:1px solid rgba(255,244,212,.32); font-size:8px; color:rgba(255,244,212,.7); cursor:help; }
.ps-shell .ps-centering{ display:grid; grid-template-columns:1fr 1fr; gap:8px; margin:0; padding:0; }
.ps-shell .ps-centering>div{ display:flex; flex-direction:column; gap:3px; padding:10px; border-radius:10px; background:rgba(255,244,212,.04); }
.ps-shell .ps-centering>div span{ font-size:9px; letter-spacing:.14em; text-transform:uppercase; color:rgba(255,244,212,.55); }
.ps-shell .ps-centering>div strong{ font-size:17px; color:var(--text); font-variant-numeric:tabular-nums; }
.ps-shell .ps-centering .ps-ratio{ background:rgba(255,244,212,.085); }
.ps-shell .ps-centering .ps-ratio strong{ color:var(--accent,#efd8b9); }
.ps-shell .ps-grades{ display:grid; grid-template-columns:1fr 1fr; gap:8px; }
.ps-shell .ps-grades .grade-card{ display:flex; flex-direction:column; gap:3px; min-height:0; padding:10px; border-radius:10px; background:rgba(255,244,212,.04); }
.ps-shell .ps-grades .grade-card span{ font-size:9px; letter-spacing:.18em; color:rgba(255,244,212,.55); }
.ps-shell .ps-grades .grade-card strong{ margin:0; font-size:18px; color:var(--accent,#efd8b9); }
.ps-shell .ps-save{
  margin-top:auto; padding:15px; border:none; border-radius:12px; cursor:pointer; width:100%;
  background:var(--accent,#efd8b9); color:#1a1208; font-weight:700; letter-spacing:.14em; font-size:13px;
  transition:filter .15s, transform .12s;
}
.ps-shell .ps-save:hover{ filter:brightness(1.06); transform:translateY(-1px); }
.ps-shell .ps-save:active{ transform:translateY(0); }

/* ---- MOBILE / NARROW: stack vertically ---- */
@media (max-width:899px){
  .mobile-shell.ps-shell{
    grid-template-columns:1fr; grid-template-rows:auto auto minmax(46svh,1fr) auto;
    grid-template-areas:"options" "tools" "canvas" "results";
    height:auto; min-height:100svh; max-height:none; overflow:auto;
  }
  .ps-shell .ps-toolrail{ flex-direction:row; flex-wrap:nowrap; overflow-x:auto; border-right:none; border-bottom:1px solid rgba(255,244,212,.10); padding:8px; }
  .ps-shell .ps-tool{ min-width:66px; flex:0 0 auto; min-height:58px; }
  .ps-shell .ps-tool-sep{ width:1px; height:auto; margin:4px 6px; }
  .ps-shell .ps-popover{ position:fixed; left:50%; right:auto; top:auto; bottom:84px; transform:translateX(-50%); }
  .ps-shell .ps-results{ border-left:none; border-top:1px solid rgba(255,244,212,.10); }
  .ps-shell .ps-optionsbar{ flex-wrap:nowrap; }
}

/* ============================================================
   HYBRID LAYOUT  (.hybrid-shell)  = OLD stacked layout + NEW left rail
   Columns: [ rail | main ];  main stacks top inspector / canvas / controls
   Reuses .ps-toolrail + .ps-tool styles; overrides the 3-zone grid.
   ============================================================ */
.mobile-shell.hybrid-shell{
  grid-template-columns:114px minmax(0,1fr);
  grid-template-rows:auto minmax(0,1fr) auto;
  grid-template-areas:"rail top" "rail canvas" "rail controls";
  width:100%; height:100svh; max-height:100svh; gap:0; padding:0; overflow:hidden; background:#000000;
}
.hybrid-shell .ps-optionsbar, .hybrid-shell .ps-results{ display:none !important; }
.hybrid-shell .ps-toolrail{ grid-area:rail; }
.hybrid-shell .hybrid-top{ grid-area:top; }
.hybrid-shell .canvas-area{ grid-area:canvas; }
.hybrid-shell .control-panel{ grid-area:controls; }

/* ---- TOP INSPECTOR (slim bar: brand | grades | ratios | save) ---- */
.hybrid-shell .hybrid-top{
  display:flex; align-items:center; gap:clamp(14px,2vw,34px); flex-wrap:nowrap;
  padding:10px clamp(14px,1.6vw,24px); min-height:0; overflow-x:auto;
  background:#1a1a1a; border-bottom:1px solid rgba(255,244,212,.10);
}
.hybrid-shell .hybrid-top .ps-brand{ display:flex; flex-direction:row; align-items:center; gap:9px; line-height:1.05; flex:0 0 auto; }
.hybrid-shell .hybrid-top .ps-brand-logo{ height:30px; width:auto; display:block; }
.hybrid-shell .hybrid-top .ps-brand-text{ display:flex; flex-direction:column; line-height:1.05; }
.hybrid-shell .hybrid-top .ps-brand strong{ font-family:'DM Serif Display',serif; color:var(--accent,#efd8b9); font-size:17px; letter-spacing:.16em; }
.hybrid-shell .hybrid-top .ps-brand small{ font-size:8px; letter-spacing:.34em; color:rgba(255,244,212,.5); }
.hybrid-shell .hybrid-grades{ display:grid; grid-template-columns:repeat(4,minmax(54px,72px)); gap:8px; margin:0; padding:0; }
.hybrid-shell .hybrid-grades .grade-card{ display:flex; flex-direction:column; align-items:center; gap:2px; min-height:0; padding:7px 6px; border-radius:9px; background:rgba(255,244,212,.05); }
.hybrid-shell .hybrid-grades .grade-card span{ font-size:8.5px; letter-spacing:.16em; color:rgba(255,244,212,.55); }
.hybrid-shell .hybrid-grades .grade-card strong{ margin:0; font-size:17px; color:var(--accent,#efd8b9); }
.hybrid-shell .hybrid-ratio{ display:grid; grid-template-columns:repeat(6,minmax(46px,1fr)); gap:6px; margin:0; padding:0; flex:1 1 auto; min-width:300px; }
.hybrid-shell .hybrid-ratio>div{ display:flex; flex-direction:column; align-items:center; gap:1px; padding:6px 4px; border-radius:8px; background:rgba(255,244,212,.04); }
.hybrid-shell .hybrid-ratio>div span{ font-size:8px; letter-spacing:.1em; text-transform:uppercase; color:rgba(255,244,212,.5); }
.hybrid-shell .hybrid-ratio>div strong{ font-size:14px; color:var(--accent); font-variant-numeric:tabular-nums; }
.hybrid-shell .hybrid-ratio .ps-ratio{ background:rgba(255,244,212,.085); }
.hybrid-shell .hybrid-ratio .ps-ratio strong{ color:var(--accent,#efd8b9); }
.hybrid-shell .hybrid-save{ flex:0 0 auto; width:auto; min-width:118px; margin:0; padding:12px 22px; border:none; border-radius:11px; cursor:pointer; background:var(--accent,#efd8b9); color:#1a1208; font-weight:700; letter-spacing:.14em; font-size:12px; transition:filter .15s, transform .12s; }
.hybrid-shell .hybrid-save:hover{ filter:brightness(1.06); transform:translateY(-1px); }
.hybrid-shell .hybrid-save:active{ transform:translateY(0); }

/* ---- CANVAS ---- */
.hybrid-shell .canvas-area{ grid-area:canvas; position:relative; min-width:0; min-height:0; background:#000000; overflow:hidden; }

/* ---- BOTTOM CONTROLS (old line/opacity bar) ---- */
.hybrid-shell .control-panel.hybrid-controls{
  display:flex; align-items:center; gap:clamp(16px,2.4vw,40px); flex-wrap:wrap;
  padding:10px clamp(14px,1.6vw,24px); margin:0; min-height:0;
  background:#1a1a1a; border-top:1px solid rgba(255,244,212,.10);
}
.hybrid-shell .hybrid-controls .control-block{ display:flex; align-items:center; gap:10px; }
.hybrid-shell .hybrid-controls .control-block>span{ font-size:9px; letter-spacing:.2em; text-transform:uppercase; color:rgba(255,244,212,.55); }
.hybrid-shell .hybrid-controls .swatches{ display:flex; gap:5px; margin:0; max-width:none; }
.hybrid-shell .hybrid-controls .stepper{ display:grid; grid-template-columns:28px 50px 28px; align-items:center; }

/* ============================================================
   MOBILE / PHONE  ( <= 899px )  — app-shell, NO horizontal scrollers.
   Everything WRAPS so all buttons/values are always visible (no hidden,
   no auto-scroll). order: [ inspector ] [ canvas (flex) ] [ tools ] [ line ]
   ============================================================ */
@media (max-width:899px){
  .mobile-shell.hybrid-shell{
    grid-template-columns:1fr;
    grid-template-rows:auto minmax(0,1fr) auto auto;
    grid-template-areas:"top" "canvas" "rail" "controls";
    width:100%; height:100svh; max-height:100svh; min-height:0; overflow:hidden;
  }

  /* TOP — 2-row grid, all results visible (no scroll) */
  .hybrid-shell .hybrid-top{
    display:grid; grid-template-columns:auto minmax(0,1fr) auto;
    grid-template-areas:"logo grades save" "ratio ratio ratio";
    align-items:center; gap:6px 9px; padding:8px 10px; overflow:visible;
  }
  .hybrid-shell .hybrid-top .ps-brand{ display:flex; grid-area:logo; align-items:center; }
  .hybrid-shell .hybrid-top .ps-brand-logo{ height:20px; }
  .hybrid-shell .hybrid-grades{ grid-area:grades; grid-template-columns:repeat(4,1fr); gap:6px; }
  .hybrid-shell .hybrid-grades .grade-card{ padding:5px 4px; }
  .hybrid-shell .hybrid-grades .grade-card strong{ font-size:15px; }
  .hybrid-shell .hybrid-save{ grid-area:save; min-width:0; padding:10px 18px; font-size:11px; }
  .hybrid-shell .hybrid-ratio{ grid-area:ratio; grid-template-columns:repeat(6,1fr); gap:5px; min-width:0; }
  .hybrid-shell .hybrid-ratio>div{ padding:5px 2px; }
  .hybrid-shell .hybrid-ratio>div span{ font-size:7.5px; }
  .hybrid-shell .hybrid-ratio>div strong{ font-size:13px; }

  /* CANVAS — flexible centre */
  .hybrid-shell .canvas-area{ min-height:0; }

  /* RAIL — wrap ALL tools into rows, no horizontal scroll, all visible */
  .hybrid-shell .ps-toolrail{
    flex-direction:row; flex-wrap:wrap; justify-content:center; align-items:stretch; gap:6px;
    overflow:visible; padding:8px 10px;
    border-right:none; border-top:1px solid rgba(255,244,212,.10); border-bottom:none;
  }
  .hybrid-shell .ps-toolrail .ps-tool{
    width:auto !important; flex:0 0 auto; min-width:58px; min-height:50px; padding:5px 8px; border-radius:11px;
  }
  .hybrid-shell .ps-toolrail .ps-tool b{ font-size:9px; letter-spacing:0; }
  .hybrid-shell .ps-toolrail .ps-tool .ps-ico{ font-size:17px; height:18px; }
  .hybrid-shell .ps-toolrail .ps-tool.is-active::before, .hybrid-shell .ps-toolrail .ps-tool.active::before{ display:none; }
  .hybrid-shell .ps-toolrail .ps-tool.is-active, .hybrid-shell .ps-toolrail .ps-tool.active{ box-shadow:inset 0 -3px 0 var(--accent,#efd8b9); }
  .hybrid-shell .ps-tool--sub{ min-height:50px; opacity:.82; }
  .hybrid-shell .ps-tool-sep{ display:none; }
  .hybrid-shell .ps-tool-wrap{ flex:0 0 auto; }

  /* LINE CONTROLS — wrap so swatches + steppers all fit */
  .hybrid-shell .control-panel.hybrid-controls{
    flex-wrap:wrap; justify-content:center; gap:12px 20px; padding:8px 12px; overflow:visible;
    border-top:1px solid rgba(255,244,212,.10);
  }
  .hybrid-shell .hybrid-controls .control-block{ flex:0 0 auto; }

  /* popovers + inline toolbars anchored to viewport / canvas */
  .hybrid-shell .ps-popover{ position:fixed; left:50%; right:auto; top:auto; bottom:120px; transform:translateX(-50%); z-index:80; }
  .hybrid-shell .inline-cardtype-toolbar:not([hidden]){ width:min(94%,560px); }
}

/* very small phones */
@media (max-width:400px){
  .hybrid-shell .ps-toolrail .ps-tool{ min-width:54px; }
  .hybrid-shell .hybrid-ratio>div strong{ font-size:12px; }
}

/* ---- Compact line-colour control: icon + swatch popup ---- */
.line-color-toggle{ display:none; }                 /* desktop: hidden, swatches show inline */
.line-color-pop{ display:flex; align-items:center; gap:10px; }

@media (max-width:899px){
  .hybrid-shell .control-block.colors{ position:relative; }
  .hybrid-shell .line-color-toggle{
    display:inline-block; width:22px; height:22px; min-height:22px; padding:0; flex:0 0 auto;
    border-radius:5px; border:1px solid rgba(255,244,212,.5); background:var(--cur,#d8bd83);
    cursor:pointer;
  }
  .hybrid-shell .colors .line-color-pop{
    display:none; position:absolute; left:0; bottom:calc(100% + 10px); z-index:90;
    flex-direction:column; gap:10px; width:max-content; padding:12px;
    background:#242424; border:1px solid rgba(255,244,212,.2); border-radius:14px;
    box-shadow:0 18px 50px rgba(0,0,0,.6);
  }
  .hybrid-shell .colors .line-color-pop.open{ display:flex; }
  .hybrid-shell .colors .line-color-pop .swatches{ display:grid; grid-template-columns:repeat(5,26px); gap:8px; max-width:none; }
  .hybrid-shell .colors .line-color-pop .swatch{ width:26px; height:26px; min-height:26px; border-radius:7px; }
  .hybrid-shell .colors .line-color-pop .color-picker-input{ width:100%; height:30px; }
}

/* ---- "R" watermark on the card-placement canvas ---- */
.canvas-area .canvas-watermark{
  position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
  font-family:'DM Serif Display', serif; font-weight:400; line-height:1;
  font-size:min(52vh, 46vw, 460px); color:var(--accent); opacity:.05;
  pointer-events:none; user-select:none; z-index:2;
}
.canvas-area #mobileCanvas{ position:relative; z-index:1; }
.canvas-area .empty-state{ z-index:3; }
