/* TV screen: fullscreen. Loading and pairing screens have a dark background; the menu's colors come from the theme. */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #14110f;
  color: #fafaf9;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  cursor: none;
}

[hidden] { display: none !important; }

/* Stage and rotation. Sizes use --vh/--vw instead of vh/vw: on a rotated stage
   the stage's height is the screen's width. .rotated and --rotation on html are set by screen.js. */
:root { --vh: 1vh; --vw: 1vw; --rotation: 0deg; }
html.rotated { --vh: 1vw; --vw: 1vh; }
.stage { position: fixed; inset: 0; overflow: hidden; }
html.rotated .stage {
  inset: auto;
  top: 50%;
  left: 50%;
  width: 100vh;
  height: 100vw;
  transform: translate(-50%, -50%) rotate(var(--rotation));
}

.status {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: calc(5 * var(--vh)) calc(5 * var(--vw));
}
.status-text { font-size: calc(4 * var(--vh)); color: #a8a29e; }

/* Pairing */
.pairing {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: calc(6 * var(--vh)) calc(6 * var(--vw));
}
.pairing h1 { font-size: calc(7 * var(--vh)); margin: 0 0 calc(5 * var(--vh)); }
.pairing-body { display: flex; gap: calc(6 * var(--vw)); align-items: center; }
.qr {
  flex: none;
  width: calc(52 * var(--vh));
  height: calc(52 * var(--vh));
  background: #fff;
  padding: calc(2 * var(--vh));
  border-radius: calc(2 * var(--vh));
}
.qr svg { width: 100%; height: 100%; display: block; }
.pairing-info { font-size: calc(3.6 * var(--vh)); color: #d6d3d1; }
.pairing-info ol { margin: 0 0 calc(3 * var(--vh)); padding-left: 1.2em; line-height: 1.5; }
.pairing-code {
  font-size: calc(16 * var(--vh));
  font-weight: 800;
  letter-spacing: 0.12em;
  margin: 0;
  color: #fbbf24;
  font-variant-numeric: tabular-nums;
}
.pairing-expiry { color: #a8a29e; margin: calc(1 * var(--vh)) 0 0; }
/* On a portrait stage: QR on top, instructions below */
.portrait .pairing h1 { font-size: calc(3.6 * var(--vh)); margin-bottom: calc(3 * var(--vh)); }
.portrait .pairing-body { flex-direction: column; gap: calc(3 * var(--vh)); align-items: center; }
.portrait .qr { width: calc(60 * var(--vw)); height: calc(60 * var(--vw)); }
.portrait .pairing-info { font-size: calc(2.2 * var(--vh)); }
.portrait .pairing-code { font-size: calc(8 * var(--vh)); }
.portrait .pairing-url { font-size: calc(1.6 * var(--vh)); }
.pairing-url { color: #78716c; font-size: calc(2.4 * var(--vh)); margin-top: calc(3 * var(--vh)); word-break: break-all; }

/* Menu — colors come from public/js/themes.js as CSS variables.
   The font size is set by screen.js so the menu fits the screen (--fs); all sizes are in em. */
.menu {
  --fs: 32px;
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: calc(4 * var(--vh)) calc(4 * var(--vw)) calc(2 * var(--vh));
  overflow: hidden;
  background: linear-gradient(170deg, var(--bg-top), var(--bg-bottom));
  color: var(--text);
  font-family: var(--font-body, inherit);
  text-shadow: 0 0.05em 0.12em var(--shadow);
}

/* Corner decorations */
.deco { position: absolute; width: min(calc(28 * var(--vh)), calc(28 * var(--vw))); height: min(calc(28 * var(--vh)), calc(28 * var(--vw))); opacity: 0.75; pointer-events: none; }
.deco-leaves { top: 0; left: 0; }
.deco-beans { right: 0; bottom: 0; }
.menu:not([data-corners]) .deco { display: none; }

.menu-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.9em;
  font-size: var(--fs);
  overflow: hidden;
}

.category { flex: 1 0 auto; display: flex; flex-direction: column; }
.category-head { display: flex; align-items: baseline; gap: 1em; }
.category-head .category-title { flex: 1; min-width: 0; }

/* Large, bold, uppercase category title */
.category-title {
  margin: 0 0 0.3em;
  font-size: 1.9em;
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--title);
  font-family: var(--font-title, inherit);
}
/* Small categories: dark 'etiket' (tag) box */
.category.etiket .category-title {
  flex: none;
  align-self: flex-start;
  font-size: 1.15em;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 0.25em 0.75em;
  border-radius: 0.3em;
  background: var(--tag-bg);
  color: var(--tag-text);
  text-shadow: none;
}

.category-body { flex: 1; display: flex; gap: 1.2em; }
.category.has-photos .category-body { min-height: 6.5em; }
.category.photos-left .category-body { flex-direction: row-reverse; }

.product-list { flex: 0 1 26em; min-width: 0; margin: 0; padding: 0; list-style: none; }
.category:not(.has-photos) .product-list { flex: 1 1 auto; }

/* Product name on the left, price on the right; no dotted leader */
.product {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1em;
  padding: 0.1em 0;
  line-height: 1.2;
}
.product-name { min-width: 0; font-weight: 600; }
.product-desc { display: block; font-size: 0.68em; font-weight: 400; color: var(--text-soft); }
.product-price { flex: none; font-weight: 800; font-variant-numeric: tabular-nums; }
/* Two-size price (e.g. Büyük / Ç.Büyük): two right-aligned fixed-width columns with their labels on top. */
.two-prices .product-name { flex: 1 1 auto; }
.two-prices { --col: 4.6; } /* price column width (em, relative to the product font size) */
.two-prices .product-price { width: calc(var(--col) * 1em); text-align: right; }
.size-label {
  flex: none;
  width: calc(var(--col) * 1em / 0.62);
  font-size: 0.62em;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-align: right;
  text-transform: uppercase;
  color: var(--text-soft);
  white-space: nowrap;
}
.category.etiket .category-head { align-items: center; }
.product.size-row { padding-bottom: 0; }
.product.soldout { opacity: 0.55; }
.product.soldout .product-price { text-decoration: line-through; }
.soldout-badge {
  font-size: 0.6em;
  font-weight: 700;
  color: #fff;
  background: var(--soldout);
  border-radius: 0.3em;
  padding: 0.05em 0.4em;
  margin-left: 0.5em;
  vertical-align: middle;
  text-shadow: none;
}

/* Product photos: beside the list, spanning the category's full height.
   Absolutely positioned, so they don't affect the font size calculation. */
.category-photos { position: relative; flex: 1 1 30%; min-width: 30%; }
.category-photos-inner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-evenly;
  gap: 0.6em;
}
.category-photos img {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  filter: drop-shadow(0 0.35em 0.4em var(--shadow));
}
.category-photos img:not([src]) { visibility: hidden; }
/* Portrait stage: list at full width, photos side by side below the list, so they sit between categories. */
.portrait .category-body,
.portrait .category.photos-left .category-body { flex-direction: column; gap: 0.5em; }
.portrait .product-list { flex: none; }
.portrait .category-photos { flex: 1 0 5.5em; min-width: 0; }
.portrait .category-photos-inner { justify-content: center; gap: 1.5em; }
.portrait .category-photos img { flex: 0 1 auto; max-width: 30%; }

.menu-empty { font-size: 1em; color: var(--text-soft); }

/* Extras / note box (extras from the cafe settings; the admin chooses which screens show it). */
.extras {
  flex: none;
  align-self: flex-end;
  min-width: 50%;
  max-width: 100%;
  font-size: 0.8em;
  padding: 0.6em 1em;
  border-radius: 0.6em;
  background: var(--box-bg);
  border: 0.08em solid var(--box-line);
}
.extras-title {
  display: inline-block;
  margin: 0 0 0.4em;
  font-size: 1em;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.2em 0.7em;
  border-radius: 0.3em;
  background: var(--tag-bg);
  color: var(--tag-text);
  text-shadow: none;
}
.extras-list { margin: 0; padding: 0; list-style: none; color: var(--extras-text); }
.menu-notes { flex: none; text-align: center; font-size: 0.7em; color: var(--text-soft); }
.menu-notes p { margin: 0; }
.star { margin-right: 0.3em; font-size: 0.8em; }

/* Bottom: round cafe logo */
.menu-footer { position: relative; flex: none; display: flex; justify-content: center; padding-top: calc(1.5 * var(--vh)); }
.cafe-logo {
  width: calc(13 * var(--vh));
  height: calc(13 * var(--vh));
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--logo-bg);
  box-shadow: 0 0 0 calc(0.6 * var(--vh)) var(--logo-ring), 0 calc(1 * var(--vh)) calc(2 * var(--vh)) var(--shadow);
  color: var(--logo-text);
  font-weight: 900;
  font-size: calc(2 * var(--vh));
  line-height: 1.1;
  text-align: center;
  text-transform: uppercase;
  text-shadow: none;
  padding: calc(1 * var(--vh));
}
.cafe-logo.has-image { padding: 0; }
.price-date { margin: 0; align-self: flex-end; font-size: calc(2.6 * var(--vh)); color: var(--date-text); }
.cafe-logo img { width: 100%; height: 100%; object-fit: cover; }

/* ---------------------------------------------------------------------------
   Kara Tahta theme (themes.js → karatahta). Theme settings arrive as data-* on .menu:
   data-texture="tebesir", data-frame="ahsap", data-hand (handwritten feel), data-strip="sag" | "sol". */

/* Wooden frame: background inside, fine-grained dark wood at the edge. The top band is thicker. */
.menu[data-frame="ahsap"] {
  border: solid transparent;
  border-width: calc(3.4 * var(--vh)) calc(2.2 * var(--vh)) calc(2.4 * var(--vh));
  background:
    linear-gradient(170deg, var(--bg-top), var(--bg-bottom)) padding-box,
    repeating-linear-gradient(93deg, var(--frame) 0 0.35em, var(--frame-2) 0.35em 0.45em, var(--frame) 0.45em 1.1em, var(--frame-2) 1.1em 1.15em) border-box;
  box-shadow: inset 0 0 calc(2 * var(--vh)) rgb(0 0 0 / 0.55);
}

/* Chalk dust and eraser marks: the color comes from the theme (--text), the pattern from the mask. */
.menu[data-texture="tebesir"]::before,
.menu[data-texture="tebesir"]::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.menu[data-texture="tebesir"]::before {
  background: var(--text);
  opacity: 0.09;
  -webkit-mask-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1600 900' preserveAspectRatio='none'%3E%3Cfilter id='b'%3E%3CfeGaussianBlur stdDeviation='28'/%3E%3C/filter%3E%3Cg filter='url(%23b)' fill='none' stroke='%23000' stroke-linecap='round'%3E%3Cpath stroke-width='90' stroke-opacity='.55' d='M120 180 C380 120 560 260 820 170'/%3E%3Cpath stroke-width='120' stroke-opacity='.4' d='M980 640 C1150 560 1330 700 1520 610'/%3E%3Cpath stroke-width='70' stroke-opacity='.45' d='M260 720 C420 660 560 760 700 700'/%3E%3Cpath stroke-width='60' stroke-opacity='.35' d='M1180 140 C1280 220 1380 120 1500 210'/%3E%3Cpath stroke-width='140' stroke-opacity='.25' d='M500 450 C700 380 900 520 1100 430'/%3E%3C/g%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.4 -.45'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  -webkit-mask-size: 100% 100%, 240px 240px;
  -webkit-mask-composite: source-over;
  mask-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1600 900' preserveAspectRatio='none'%3E%3Cfilter id='b'%3E%3CfeGaussianBlur stdDeviation='28'/%3E%3C/filter%3E%3Cg filter='url(%23b)' fill='none' stroke='%23000' stroke-linecap='round'%3E%3Cpath stroke-width='90' stroke-opacity='.55' d='M120 180 C380 120 560 260 820 170'/%3E%3Cpath stroke-width='120' stroke-opacity='.4' d='M980 640 C1150 560 1330 700 1520 610'/%3E%3Cpath stroke-width='70' stroke-opacity='.45' d='M260 720 C420 660 560 760 700 700'/%3E%3Cpath stroke-width='60' stroke-opacity='.35' d='M1180 140 C1280 220 1380 120 1500 210'/%3E%3Cpath stroke-width='140' stroke-opacity='.25' d='M500 450 C700 380 900 520 1100 430'/%3E%3C/g%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.4 -.45'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mask-size: 100% 100%, 240px 240px;
  mask-composite: add;
}
/* Fine dark dust over the text: the chalk writing looks broken in places. */
.menu[data-texture="tebesir"]::after {
  z-index: 2;
  background: var(--bg-bottom);
  opacity: 0.35;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.3' numOctaves='2' seed='4' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2.2 -1'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.3' numOctaves='2' seed='4' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2.2 -1'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.menu[data-texture="tebesir"] {
  text-shadow: 0 0 0.04em var(--shadow), 0 0 0.25em rgb(0 0 0 / 0.25);
}

/* Handwriting: rows and titles get a small, fixed tilt and offset derived from the product id (screen.js → handTilt).
   The tilt is applied to the name and price separately, so they stay aligned even on a wide row. */
.menu[data-hand] .product > span,
.menu[data-hand] .category-head > * { display: inline-block; transform: translate(var(--dx, 0), var(--dy, 0)) rotate(var(--tilt, 0deg)); }
/* Keep the name and price from drifting too far apart: the category is centered at a readable width. */
.menu[data-hand] .category { width: 100%; max-width: 28em; align-self: center; }
.menu[data-hand] .category-head .category-title { min-width: auto; } /* don't overlap the size labels */
.menu[data-hand] .category-title { font-size: 1.7em; font-weight: 700; letter-spacing: 0.04em; }
/* Don't wrap the product name; if it doesn't fit, the font size shrinks. A little margin at the edges for tilt/offset. */
.menu[data-hand] .menu-body { padding: 0 0.3em; }
.menu[data-hand] .product-name { white-space: nowrap; min-width: auto; flex-shrink: 0; }
.menu[data-hand] .product-desc { white-space: normal; }
.menu[data-hand] .product { padding: 0.02em 0; line-height: 1.12; }
.menu[data-hand] .product-name { font-weight: 600; }
.menu[data-hand] .product-price { font-weight: 700; }
.menu[data-hand] .size-label {
  font-family: var(--font-body, inherit);
  font-size: 0.8em;
  width: calc(var(--col) * 1em / 0.8);
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
}
.menu[data-hand] .star { color: var(--date-text); }

/* Thin hand-drawn vertical chalk lines between and in front of the two price columns. */
.menu[data-hand] .two-prices .product-list { position: relative; align-self: flex-start; }
.portrait .menu[data-hand] .category .product-list { flex: none; align-self: stretch; }
.menu[data-hand] .two-prices .product-list::before,
.menu[data-hand] .two-prices .product-list::after {
  content: "";
  position: absolute;
  top: -0.2em;
  bottom: 0;
  width: 0.14em;
  background: var(--text);
  opacity: 0.55;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 400' preserveAspectRatio='none'%3E%3Cpath d='M5 0 C3 60 7 120 5 170 C3 230 7 290 4 340 C3 370 6 390 5 400' stroke='%23000' stroke-width='7' fill='none' stroke-dasharray='60 3 90 4 120 2'/%3E%3C/svg%3E") center / 100% 100%;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 400' preserveAspectRatio='none'%3E%3Cpath d='M5 0 C3 60 7 120 5 170 C3 230 7 290 4 340 C3 370 6 390 5 400' stroke='%23000' stroke-width='7' fill='none' stroke-dasharray='60 3 90 4 120 2'/%3E%3C/svg%3E") center / 100% 100%;
}
.menu[data-hand] .two-prices .product-list::before { right: calc(var(--col) * 1em + 0.5em - 0.07em); }
.menu[data-hand] .two-prices .product-list::after { right: calc(var(--col) * 2em + 1.5em - 0.07em); }
/* A portrait screen is narrow: columns shrink and rows spread out (text fits by width, so height shouldn't go unused). */
.portrait .menu[data-hand] .two-prices { --col: 3.7; }
.portrait .menu[data-hand] .product { padding: 0.28em 0; }

/* Extras box: a frame hand-drawn in pale blue chalk. */
.menu[data-hand] .extras {
  border-width: 0.1em;
  border-color: var(--box-line);
  border-radius: 1.2em 0.4em 1em 0.5em / 0.5em 1em 0.4em 1.2em;
  min-width: 40%;
  transform: rotate(-0.4deg);
}
.menu[data-hand] .extras-title {
  background: none;
  color: var(--extras-text);
  font-family: var(--font-title, inherit);
  padding: 0;
  letter-spacing: 0.04em;
}
.menu[data-hand] .menu-notes { font-size: 0.75em; }

/* Decoration strip: vertical along one edge of the screen, chalk drawings stacked top to bottom. */
.menu-strip { display: none; }
.menu[data-strip] .menu-strip {
  position: absolute;
  z-index: 1;
  top: calc(2 * var(--vh));
  bottom: calc(2 * var(--vh));
  width: calc(14 * var(--vw));
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
  gap: calc(1 * var(--vh));
}
.menu[data-strip="sag"] .menu-strip { right: calc(1.5 * var(--vw)); }
.menu[data-strip="sol"] .menu-strip { left: calc(1.5 * var(--vw)); }
.menu[data-strip="sag"] { padding-right: calc(18 * var(--vw)); }
.menu[data-strip="sol"] { padding-left: calc(18 * var(--vw)); }
.menu-strip svg { flex: 1 1 0; min-height: 0; width: 100%; overflow: visible; }
/* A thin chalk line on the strip's inner edge (like a line separating two board sections). */
.menu[data-strip] .menu-strip::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0.2vh;
  background: var(--deco);
  opacity: 0.35;
}
.menu[data-strip="sag"] .menu-strip::before { left: calc(-1.5 * var(--vw)); }
.menu[data-strip="sol"] .menu-strip::before { right: calc(-1.5 * var(--vw)); }
.portrait .menu[data-strip] .menu-strip { width: calc(13 * var(--vw)); }
.portrait .menu[data-strip="sag"] { padding-right: calc(17 * var(--vw)); }
.portrait .menu[data-strip="sol"] { padding-left: calc(17 * var(--vw)); }

/* Bottom: if there is no logo image (this theme doesn't write the cafe name), only the price update date. */
.menu[data-hand] .menu-footer { justify-content: space-between; align-items: flex-end; min-height: calc(4 * var(--vh)); }
.menu[data-hand] .price-date { font-family: var(--font-body, inherit); font-weight: 700; }

/* Few-product screen (theme: fill; screen.js → .few). The remaining height is spread across rows (--spread),
   size labels are in the list's first row, and the extras box grows. */
.menu-body.few .category .product { padding-top: calc(0.02em + var(--spread, 0px)); padding-bottom: calc(0.02em + var(--spread, 0px)); }
.menu-body.few .product.size-row { padding-top: 0; padding-bottom: 0.15em; }
.menu[data-hand] .menu-body.few .extras { font-size: 1em; border-width: 0.14em; padding: 0.7em 1.2em 0.8em; }
.menu[data-hand] .menu-body.few .extras-title { font-size: 1.25em; margin-bottom: 0.3em; }
.menu[data-hand] .menu-body.few .extras .product { padding: 0.1em 0; }
.menu[data-hand] .menu-body.few .menu-notes { font-size: 0.85em; }
/* Single category + extras on a landscape screen: title across the full width on top; list on the left, extras box to its right at the bottom. */
html:not(.portrait) .menu[data-hand] .menu-body.few.side-extras {
  display: grid;
  grid-template-columns: auto max-content; /* keep the box from shrinking and overflowing: if it doesn't fit, the font size shrinks */
  grid-template-rows: auto 1fr auto;
  justify-content: center;
  column-gap: 2.5em;
  row-gap: 0.4em;
}
html:not(.portrait) .menu[data-hand] .menu-body.few.side-extras .category { display: contents; }
html:not(.portrait) .menu[data-hand] .menu-body.few.side-extras .category-head { grid-column: 1 / -1; }
html:not(.portrait) .menu[data-hand] .menu-body.few.side-extras .extras { grid-column: 2; grid-row: 2; align-self: end; min-width: 0; }
html:not(.portrait) .menu[data-hand] .menu-body.few.side-extras .menu-notes { grid-column: 1 / -1; }
