/* =====================================================
   DTP · Digital Thermal Printer — style.css
   ===================================================== */


/* === RESET === */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
}


/* === LAYOUT === */

:root {
  /* Brand colours */
  --clr-bg:          #EDE0C4;
  --clr-orange:      #F07020;
  --clr-orange-dim:  #A04A10;
  --clr-orange-glow: rgba(240, 112, 32, 0.55);
  --clr-screen-bg:   #0a0a0a;
  --clr-screen-text: #F07020;
  --clr-screen-dim:  #7a3810;
  --clr-white:       #ffffff;
  --clr-selected-bg: rgba(240, 112, 32, 0.18);
  --clr-paper:       #F3EDE0; /* thermal paper warm white */
  --clr-desk:        #D8CDBA; /* slightly darker than page */

  /* Screen font */
  --font-screen: 'Share Tech Mono', 'Courier New', monospace;

  /* Device size — printer occupies ~40% of the viewport */
  --device-width:  clamp(260px, 40vw, 540px);
  --device-radius: 28px;

  /* Screen unit: 1% of device width — all screen text scales with device */
  --su: calc(var(--device-width) / 100);

  /* Screen overlay — % of device-container (base aspect 2534:2757)
     CALIBRATION: adjust these if overlay drifts from the image screen */
  --screen-left:   55%;
  --screen-top:    41%;
  --screen-width:  40%;
  --screen-height: 41%;

  /* Button size = 151.2px / 608.16px (Illustrator) = 24.9% of base width */
  --btn-size: 24.9%;

  /* Transitions */
  --t-fast:   80ms;
  --t-normal: 220ms;
  --t-slow:   400ms;
}

body {
  background-color: var(--clr-bg);
  display: flex;
  font-family: var(--font-screen);
}

/* Two-column: printer left | desk right */
.page-wrapper {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  width: 100%;
  min-height: 100vh;
}

/* ── Printer column ── */
.printer-section {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding: 0 clamp(16px, 2vw, 32px) clamp(40px, 6vw, 80px) clamp(24px, 3vw, 48px);
}

/* ── Desk column ── */
.desk-section {
  flex: 1;
  max-width: 58vw;   /* desk never takes more than ~58% of viewport */
  position: relative;
  min-height: 100vh;
  background-color: var(--clr-desk);
  /* subtle inner shadow on the left edge */
  box-shadow: inset 6px 0 24px rgba(0,0,0,0.08);
  overflow: hidden;
}

.desk {
  position: absolute;
  inset: 0;
}

.desk-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-screen);
  font-size: 11px;
  color: rgba(0,0,0,0.2);
  letter-spacing: 0.1em;
  pointer-events: none;
  transition: opacity 0.4s;
}

/* ── Mobile: printer full-screen, no desk ── */
@media (max-width: 700px) {
  :root {
    /* Printer fills ~85% of viewport width on mobile */
    --device-width: min(85vw, 380px);
  }

  .page-wrapper {
    flex-direction: column;
    align-items: stretch;
  }

  .printer-section {
    flex: 1;
    min-height: 100svh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 32px 20px 48px;
  }

  /* Gallery hidden on mobile — replaced by the print overlay */
  .desk-section { display: none; }
}


/* === DEVICE === */

.device-container {
  position: relative;
  width: var(--device-width);
}

.device-base {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}


/* === PRINT STRIP ===
   Slides out of the top slot of the device during printing.
   Positioned so its BOTTOM edge aligns with the top slot (~5% from top).
   JS drives height from 0 → print height.                              */

.print-strip {
  position: absolute;
  left:    22%;
  width:   56%;
  bottom:  95%;   /* bottom edge at ~5% from top = slot position */
  height:  0;
  overflow: hidden;
  background: var(--clr-paper);
  box-shadow: 0 -4px 14px rgba(0,0,0,0.22);
  z-index: 20;
  /* subtle torn-edge top via mask */
  border-radius: 1px 1px 0 0;
  opacity: 0;
  transition: opacity 0.15s;
}

.print-strip.is-visible {
  opacity: 1;
}

/* The dithered image canvas fills the strip */
#strip-canvas {
  display: block;
  width:  100%;
  height: auto;
}


/* === BUTTONS === */

/* Hit-zone: top/left = CENTER of button (translate centers it exactly) */
.btn-zone {
  position: absolute;
  width:        var(--btn-size);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(-50%, -50%);
  outline: none;
  -webkit-touch-callout: none;
}

/* Positions from Illustrator artboard 1920×1080, base at (960,540)
   Formula: left = (btnX − baseLeft) / baseW  ·  top = (btnY − baseTop) / baseH */
.btn-zone[data-btn="color"]   { top: 19.0%; left: 38.1%; }
.btn-zone[data-btn="print"]   { top: 19.0%; left: 84.2%; }
.btn-zone[data-btn="effects"] { top: 33.1%; left: 15.5%; }
.btn-zone[data-btn="size"]    { top: 47.2%; left: 38.1%; }
.btn-zone[data-btn="add"]     { top: 61.3%; left: 15.5%; }

.btn-icon {
  display: block;
  width:  100%;
  height: 100%;
  border-radius: 50%;
  pointer-events: none;
  transition:
    transform var(--t-fast) ease-in-out,
    filter    var(--t-fast) ease-in-out;
  filter: drop-shadow(0 2px 5px rgba(0,0,0,0.35));
}

.btn-zone.is-pressed .btn-icon {
  transform: scale(0.88);
  filter: brightness(0.72) drop-shadow(0 1px 2px rgba(0,0,0,0.45));
}

.btn-zone.is-active .btn-icon {
  filter: brightness(1.12) drop-shadow(0 0 8px var(--clr-orange-glow));
}

.btn-zone::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
  opacity: 0;
  pointer-events: none;
}

.btn-zone.is-pressed::after {
  animation: btn-flash var(--t-normal) ease-out forwards;
}

.btn-zone:focus-visible .btn-icon {
  outline: 2px solid var(--clr-orange);
  outline-offset: 3px;
  border-radius: 50%;
}

.hidden-input {
  position: absolute;
  width: 0; height: 0; opacity: 0;
  pointer-events: none;
}


/* === SCREEN === */

.screen-overlay {
  position: absolute;
  left:     var(--screen-left);
  top:      var(--screen-top);
  width:    var(--screen-width);
  height:   var(--screen-height);
  overflow: hidden;
  background: transparent;
}

.grain-svg {
  position: absolute;
  width: 0; height: 0;
  overflow: hidden;
  pointer-events: none;
}

.screen-content {
  position: relative;
  width: 100%;
  height: 100%;
  padding: calc(var(--su) * 2.2) calc(var(--su) * 1.8);
  color: var(--clr-screen-text);
  font-family: var(--font-screen);
  font-size: calc(var(--su) * 3.3);
  line-height: 1.4;
  overflow: hidden;
  transition: opacity var(--t-normal) ease;
}

.screen-content.is-fading { opacity: 0; }

.screen-content > * {
  animation: screen-fadein var(--t-normal) ease both;
}


/* === MENUS === */

.screen-title {
  font-size: calc(var(--su) * 4.2);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #EDE0C4;
  border-bottom: 1px solid rgba(237,224,196,0.25);
  padding-bottom: calc(var(--su) * 0.8);
  margin-bottom: calc(var(--su) * 1.2);
}

.menu-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: calc(var(--su) * 0.6);
}

.menu-item {
  font-size: calc(var(--su) * 3.8);
  letter-spacing: 0.06em;
  padding: calc(var(--su) * 0.4) calc(var(--su) * 0.6);
  border-radius: 2px;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-item:hover,
.menu-item.is-highlighted { background: var(--clr-selected-bg); color: #fff; }

.menu-item.is-selected { color: var(--clr-orange); }

.menu-item.is-selected::before { content: '▶ '; font-size: calc(var(--su) * 2.8); }


/* === IDLE — PIXEL ART TEXT === */

.screen-idle {
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.px-header  { font-size: calc(var(--su) * 4.5); letter-spacing: 0.06em; color: var(--clr-orange); line-height: 1.2; }
.px-divider { font-size: calc(var(--su) * 2);   letter-spacing: -0.12em; color: var(--clr-screen-dim); overflow: hidden; white-space: nowrap; line-height: 1; }
.px-status  { font-size: calc(var(--su) * 3.8); color: var(--clr-orange); letter-spacing: 0.1em; line-height: 1.3; }
.px-info    { font-size: calc(var(--su) * 3.8); color: var(--clr-screen-text); letter-spacing: 0.04em; line-height: 1.3; }
.px-hint    { font-size: calc(var(--su) * 3.5); color: var(--clr-screen-dim); letter-spacing: 0.03em; line-height: 1.4; }
.px-spacer  { flex: 1; }

.blink { animation: blink-cursor 0.9s step-end infinite; }


/* === PRINT ANIMATION (screen text) === */

.screen-print {
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
}


/* === PRINT CARDS (desk output) === */

.print-card {
  position: absolute;
  width: clamp(120px, 14vw, 200px);
  /* No background — the canvas image carries its own paper colour.
     The transparent torn edges reveal the desk surface beneath. */
  background: transparent;
  padding: 0 0 20px 0;  /* only bottom gap for the footer */
  cursor: grab;
  transition: filter 0.15s;
  will-change: transform;
}

.print-card:active { cursor: grabbing; }

/* Card image — the dithered thermal print with transparent torn edges */
.card-image {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated; /* keep dither crisp */
  /* drop-shadow respects transparency — shadow follows the torn shape */
  filter: drop-shadow(2px 4px 10px rgba(0,0,0,0.28))
          drop-shadow(0  1px  3px rgba(0,0,0,0.16));
}

/* Small receipt-style footer — floats below the torn image */
.card-footer {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 2px 4px 3px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-date {
  font-family: var(--font-screen);
  font-size: 7px;
  color: rgba(0,0,0,0.3);
  letter-spacing: 0.04em;
}

/* Selected state — orange glow on the image shadow */
.print-card.is-selected .card-image {
  filter: drop-shadow(2px 4px 14px rgba(0,0,0,0.35))
          drop-shadow(0   0  6px rgba(240,112,32,0.45));
}

/* Download button — appears on selected card */
.download-btn {
  display: block;
  background: var(--clr-orange);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 2px 7px;
  font-family: var(--font-screen);
  font-size: 7px;
  letter-spacing: 0.05em;
  cursor: pointer;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.print-card.is-selected .download-btn {
  opacity: 1;
  pointer-events: auto;
}

/* Entrance animation — card slides in from the printer side */
@keyframes card-enter {
  from { opacity: 0; translate: -40px 0; }
  to   { opacity: 1; translate:   0   0; }
}

.print-card.is-entering {
  animation: card-enter 0.5s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}

/* Torn edges are now rendered directly into the canvas image — no ::before needed */


/* === PRINT OVERLAY (mobile) === */

.print-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  z-index: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px 24px;
  /* hidden by default */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.print-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-image {
  max-width: 80vw;
  max-height: 62vh;
  width: auto;
  height: auto;
  image-rendering: pixelated;
  filter: drop-shadow(0 12px 40px rgba(0,0,0,0.7));
  /* Subtle entrance scale */
  transform: scale(0.88);
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.print-overlay.is-visible .overlay-image {
  transform: scale(1);
}

.overlay-download {
  background: var(--clr-orange);
  color: #fff;
  border: none;
  border-radius: 24px;
  padding: 14px 40px;
  font-family: var(--font-screen);
  font-size: 13px;
  letter-spacing: 0.12em;
  cursor: pointer;
  transition: filter var(--t-fast);
}

.overlay-download:active {
  filter: brightness(0.85);
}

.overlay-hint {
  font-family: var(--font-screen);
  font-size: 11px;
  color: rgba(255, 255, 255, 0.38);
  letter-spacing: 0.04em;
  text-align: center;
  margin-top: -6px;
  min-height: 16px;
}

.overlay-close {
  background: transparent;
  color: rgba(255, 255, 255, 0.45);
  border: none;
  font-family: var(--font-screen);
  font-size: 11px;
  letter-spacing: 0.14em;
  cursor: pointer;
  padding: 8px 16px;
  transition: color var(--t-fast);
}

.overlay-close:active {
  color: rgba(255, 255, 255, 0.85);
}


/* === ANIMATIONS === */

@keyframes feed-scroll {
  from { transform: translateY(0); }
  to   { transform: translateY(-3px); }
}

@keyframes blink-cursor {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

@keyframes screen-fadein {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes btn-flash {
  0%   { opacity: 0.6; }
  100% { opacity: 0; }
}


/* === THERMAL EFFECTS (for future use / preview) === */

.thermal      { filter: grayscale(70%)  contrast(130%) brightness(0.95) sepia(15%); }
.thermal-warm { filter: grayscale(30%)  contrast(120%) brightness(0.92) sepia(40%); }
.thermal-cold { filter: grayscale(55%)  contrast(125%) brightness(1.0)  hue-rotate(200deg) saturate(60%); }
.thermal-faded{ filter: grayscale(50%)  contrast(80%)  brightness(1.1)  sepia(25%); }
.thermal-sepia{ filter: grayscale(100%) contrast(110%) brightness(0.9)  sepia(80%); }
.thermal-bw   { filter: grayscale(100%) contrast(140%) brightness(0.88); }
