/* ========================
   Tokens
======================== */
:root {
  --bg: #fbed94;
  --panel: #074756;
  --ink: #ffdc00;
  --muted: #fbed94;
  --accent: #3a1c2d;

  --radius: 12px;
  --radius-sm: 8px;
  --gap: 16px;
  --shadow: 0 10px 20px rgba(0, 0, 0, .18);
  --control-h: 2.8rem;
  --arrow-w: .9em;
  --pad-x: .6em;
  --panel-w: clamp(360px, 50vw, 560px);
}

/* Motion safety */
@media (prefers-reduced-motion:reduce) {
  * {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* ========================
   Base
======================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Bagel Fat One", cursive;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  margin: 0;
  padding: var(--gap);
  height: 100dvh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

h1 {
  color: var(--panel);
}

:where(h1, h2, h3, h4, h5, h6, label, button, select, input, textarea) {
  font-weight: 400;
}

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ========================
   Utilities
======================== */
.fitline {
  display: block;
  width: 100%;
  white-space: nowrap;
  line-height: 1.18;
  padding-block: .05em .1em;
  overflow: visible;
  font-size: clamp(18px, 3.8vw, 42px);
}

.field-label {
  display: block;
  margin-bottom: 6px;
}

.step-card{
  background: #e5f2f1;
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid rgba(0,0,0,0.04);
}

#artFileName,
#sizeReadout{
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#artFileBtn { margin-top: 6px; }
#artFileName { margin-top: 4px; }

.bagel-select { margin-top: 6px; }

#qtNotes{
  width: 100%;
  max-width: none;
  display: block;
  margin: 0;
}

.mt-2 {
  margin-top: 8px;
}

.fitline-wrap {
  padding-inline: 12px;
}

.muted {
  color: var(--muted);
  font-size: 1.4rem;
}

/* Tips list */
.tips {
  margin: 6px 0 0;
  padding-left: 1.2em;
  color: var(--muted);
  line-height: 1.25;
}

.tips li {
  margin: .25em 0;
}

.tips li::marker {
  color: var(--ink);
}

/* ========================
   Layout
======================== */
.page-shell {
  width: min(1400px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  flex: 1 1 0;   /* keep it a flex child that fills the body */
  min-height: 0; /* allow children to shrink within the viewport */
}

.app {
  display: grid;
  grid-template-columns: clamp(320px, 36vw, 440px) 1fr;
  grid-template-rows: minmax(0, 1fr);
  gap: var(--gap);
  align-items: stretch;
  flex: 1 1 0;

  min-height: 0;
  padding: 0;
  overflow: hidden;
}

.stage {
  position: relative;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  height: 100%;
  min-height: 0;
}

#stage {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ========================
   Panel (left controls)
======================== */
.panel {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 0;
  height: 100%;
  min-height: 0;
  overflow: auto;
}

.panel :where(h1, h2,) {
  margin-bottom: 6px;
  color: var(--ink);
}

.field {
  margin-bottom: 16px;
}

.field.step-gap{
  margin-top: 14px;
}

.step-card{
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px;
  margin: 0 0 12px 0;
  border: 1px solid rgba(0,0,0,0.04);
}

/* Normalize spacing inside btn rows */
.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.btn-row>button {
  flex: 1 1 0;
  width: auto;
  display: flex;
  justify-content: center;
  margin: 0; /* override global button margin to keep consistent spacing */
}

/* ========================
   Controls (shared)
======================== */
:where(input, textarea, select, button) {
  font-family: inherit;
  line-height: 1.2;
}

:where(input, textarea, select) {
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: var(--bg);
  color: var(--panel);
}

/* Buttons — scoped so they don't affect panel handle, BagelSelect trigger, or swatches */
button:not(.qt-panel-handle):not(.bagel-trigger):not(.swatch) {
  display: block;
  width: 100%;
  margin: 0;
  padding: .45em 0;
  border: none;
  border-radius: 10px;
  font-size: clamp(20px, 1.8vw, 16px);
  cursor: pointer;
  background: var(--muted);
  color: var(--panel);
  transition: background .2s, transform .1s;
  background: var(--muted);
  color: var(--panel);
  transition: background .2s, transform .1s;
}

button.primary {
  background: var(--ink);
  color: var(--panel);
}

button:hover:not(:disabled):not(.qt-panel-handle):not(.bagel-trigger):not(.swatch) {
  background: var(--accent);
  color: var(--ink);
}

button:active:not(:disabled):not(.qt-panel-handle):not(.bagel-trigger):not(.swatch) {
  transform: scale(.96);
  background: var(--ink);
  color: var(--accent);
}

button:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.btn-row {
  display: flex;
  gap: 8px;
}

.btn-row>button {
  flex: 1 1 0;
}

/* Active state styling for BG remove toggle */
#bgRemoveBtn[data-active="true"] {
  background: var(--accent);
  color: var(--ink);
  border: 1px solid var(--ink);
}


/* ========================
   Native select (fallback)
======================== */
select {
  box-sizing: border-box;
  height: 3em;
  padding: .45em calc(var(--pad-x) + var(--arrow-w) + .4em) .65em var(--pad-x);
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: var(--bg);
  color: var(--panel);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'><path fill='%23005e5b' d='M0 0l5 6 5-6z'/></svg>");
  background-repeat: no-repeat;
  background-position: right var(--pad-x) center;
  background-size: var(--arrow-w) auto;
  white-space: nowrap;
  overflow: visible;
}

@supports (-webkit-appearance:none) {
  select {
    padding-bottom: .72em;
  }
}

select option {
  background: var(--bg);
  color: var(--panel);
}

/* ========================
   BG swatches
======================== */
.swatches {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.swatch {
  display: inline-block;
  width: 22px;
  height: 22px;
  padding: 0;
  margin: 0;
  line-height: 0;
  border: 2px solid rgba(0, 0, 0, .25);
  border-radius: 4px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  outline: none;
  background: transparent;
}

.swatch.selected {
  outline: 2px solid #fff;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .55) inset;
}

/* ========================
   BagelSelect
======================== */
.bagel-select {
  position: relative;
  font-family: inherit;
  --bagel-h: var(--control-h);
  --bagel-font: clamp(15px, calc(var(--bagel-h) * 0.42), 20px);
}

.bagel-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6em;
  padding: .5em calc(var(--pad-x) + var(--arrow-w) + .3em) .65em var(--pad-x);
  border: none;
  border-radius: 10px;
  background: var(--bg);
  color: var(--panel);
  line-height: 1.2;
  cursor: pointer;
  font-size: var(--bagel-font);
  font-weight: 400;
  min-height: var(--bagel-h);
}

.bagel-trigger:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.bagel-trigger__arrow {
  width: var(--arrow-w);
  height: auto;
  color: var(--panel);
  flex: 0 0 auto;
}

.bagel-list {
  position: absolute;
  inset: calc(100% + 4px) 0 auto 0;
  transform: none;
  max-height: 240px;
  overflow: auto;
  background: var(--bg);
  color: var(--panel);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
  margin: 0;
  list-style: none;
  display: none;
  z-index: 10;
}

.bagel-select[aria-open="true"] .bagel-list {
  display: block;
}

.bagel-list li {
  padding: .5em .6em;
  border-radius: 8px;
  line-height: 1.18;
  white-space: nowrap;
  cursor: pointer;
}

.bagel-list li[aria-selected="true"] {
  background: var(--ink);
  color: var(--panel);
}

.bagel-list li[aria-current="true"] {
  outline: 2px solid var(--accent);
}

.bagel-native {
  display: none;
}

.bagel-list li:hover {
  background: var(--accent);
  color: var(--ink);
}
.bagel-list li:active {
  background: var(--ink);
  color: var(--panel);
}

.bagel-list li:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#sizeReadout {
  font-size: clamp(12px, 10vw, 28px);
}


/* ========================
   Mobile
======================== */
@media (max-width:800px) {
  .app {
    grid-template-columns: 1fr;
    grid-auto-rows: auto;
  }

  .stage {
    height: auto;
    min-height: 50vh;
  }
}

/* ========================
   Off-canvas Order Panel
======================== */
.qt-order-panel {
  position: fixed;
  inset: auto 0 0 auto;
  right: 0;
  top: 0;
  width: var(--panel-w);
  max-width: 90vw;
  height: 100dvh;
  background: #fff;
  color: #222;
  box-shadow: -2px 0 18px rgba(0, 0, 0, .12);
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  border-left: 1px solid #eee;
  z-index: 9999;
  transform: translateX(100%);
  transition: transform 240ms ease;
}

.qt-order-panel.is-open {
  transform: translateX(0);
}

.qt-op-header {
  position: relative;
  padding: 14px 16px;
  border-bottom: 1px solid #eee;
  font-weight: 600;
}

.qt-op-body {
  padding: 12px 16px;
  overflow: auto;
  gap: 12px;
  display: grid;
}

.qt-op-field {
  display: grid;
  gap: 6px;
}

.qt-op-field label {
  font-size: 12px;
  color: #555;
}

.qt-op-field :where(input, textarea, select) {
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 14px;
  width: 100%;
}

.qt-op-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.qt-op-summary {
  background: #fafafa;
  border: 1px solid #eee;
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
}

.qt-op-summary div {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
}

.qt-op-footer {
  padding: 12px 16px;
  border-top: 1px solid #eee;
  display: grid;
  gap: 8px;
}

.qt-btn {
  appearance: none;
  border: none;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}

.qt-btn-primary {
  background: #0ea5e9;
  color: #fff;
}

.qt-btn-muted {
  background: #f3f4f6;
  color: #111;
}

.qt-note {
  font-size: 12px;
  color: #666;
}

.qt-op-close {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 6px;
}

/* Panel handle (fixed tab) */
.qt-panel-handle {
  position: fixed;
  top: 70%;
  right: 0;
  transform: translateY(-50%);
  width: 80px;
  height: 150px;
  border: none;
  border-radius: 8px 0 0 8px;
  background: var(--ink, #111);
  color: var(--accent);
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .16);
  z-index: 10000;
  transition: right 240ms ease;
  outline: none;
  overflow: hidden; /* contain glimmer */
  -webkit-tap-highlight-color: transparent;
}

.qt-panel-handle::after {
  content: "";
  position: absolute;
  inset: -5% -10%;
  background: linear-gradient(40deg, transparent 40%, var(--bg) 40%, var(--bg) 60%, transparent 60%);
  transform: translateY(-180%);
  animation: qtGlimmer 6s linear infinite;
  pointer-events: none;
  filter: none;
  opacity: 1;
}

@keyframes qtGlimmer {
  0%   { transform: translateY(-180%); }  /* fully out of view */
  25%  { transform: translateY(-140%); }  /* slow entry */
  45%  { transform: translateY(-100%); }  /* slow drift near top */
  55%  { transform: translateY(140%); }   /* fast burst through bottom */
  65%  { transform: translateY(-100%); }  /* fast lift away */
  85%  { transform: translateY(-140%); }  /* slowing toward exit */
  100% { transform: translateY(-180%); }  /* back out of view */
}

.qt-panel-handle,
.qt-panel-handle:hover,
.qt-panel-handle:active {
  transform: translateY(-50%) scale(1) !important;
}

.qt-panel-handle:focus {
  outline: none;
}

.qt-panel-handle:focus-visible {
  outline: 2px solid rgba(138, 180, 248, .9);
  outline-offset: 2px;
}

.qt-panel-handle__text {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-weight: 800;
  letter-spacing: .08em;
  font-size: 20px;
}

.qt-order-panel.is-open~.qt-panel-handle {
  right: var(--panel-w);
}

.error { color: #c62828; }

.qt-sizes{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(44px, 1fr));
  gap: 2px;
  white-space: normal;
}
.qt-sizes label,
.qt-size-col{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:2px;
}
.qt-sizes input[type=number],
.qt-sizes input[type=text]{
  width:3.6ch;
  min-width:3.6ch;
  flex:0 0 auto;
  text-align:right;
  padding:.25rem .35rem;
  font-variant-numeric:tabular-nums;
}


/* Front/Back toggle */
.qt-side-toggle{
  position:absolute; top:12px; left:12px; z-index:5;
  display:flex; gap:12px;
}

/* OFF state */
.qt-side-btn{
  all:unset;
  display:inline-flex; align-items:center; justify-content:center;
  padding: .6rem 1rem; border-radius:8px;
  font:inherit; line-height:1.1; cursor:pointer; user-select:none;
  text-align:center;
  min-width: 60px;
  min-height: 25px;
  background:var(--bg);
  color:var(--accent);
  border:1px solid var(--accent);
}

/* ON state (keep your last colors) */
#qtSideFront[aria-selected="true"],
#qtSideBack[aria-selected="true"]{
  background:var(--accent) !important;
  color:var(--ink) !important;
  border-color:var(--ink) !important;
}

/* Focus */
.qt-side-btn:focus-visible{
  outline:2px solid var(--ink);
  outline-offset:2px;
}
