:root {
    --paper: #f6f1e7;
    --paper-dark: #e7dec9;
    --paper-edge: #d8cdb2;
    --ink: #2a2622;
    --ink-light: #6b645a;
    --red: #b23a2e;
    --card-w: 1920px;
    --card-h: 1080px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background: #0a0a0f;
    color: #ccc;
    font-family: 'Exo 2', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
}

/* ── ПАНЕЛЬ ВВОДА ── */
.panel {
    position: relative; z-index: 10;
    background: rgba(18,15,12,0.95); backdrop-filter: blur(20px);
    border: 1px solid #8b7355;
    border-radius: 20px;
    padding: 25px 30px;
    width: 90%; max-width: 900px;
    margin-bottom: 15px;
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
    text-align: center;
}
.panel h1 {
    font-family: 'Cutive Mono', monospace;
    font-size: 2rem; color: var(--paper);
    letter-spacing: 4px; margin-bottom: 5px;
}
.subtitle {
    font-family: 'Exo 2', sans-serif; color: #999;
    font-size: 0.9rem; margin-bottom: 20px;
}
.input-row { display: flex; justify-content: center; margin-bottom: 12px; }
.input-row input {
    background: #111; border: 2px solid #444; color: #fff;
    padding: 10px 18px; border-radius: 8px; font-size: 0.9rem;
    outline: none; flex: 1 1 200px; max-width: 500px;
    font-family: 'Exo 2', sans-serif; transition: 0.3s;
}
.input-row input:focus { border-color: #8b7355; box-shadow: 0 0 15px rgba(139,115,85,0.4); }

button#generateBtn {
    background: linear-gradient(135deg, #5a4a3a, #8b7355);
    color: #fff; border: 2px solid #6b5a45;
    padding: 10px 25px; border-radius: 8px; cursor: pointer;
    font-family: 'Cutive Mono', monospace; font-size: 1rem; font-weight: 700;
    letter-spacing: 2px; transition: 0.3s; text-transform: uppercase;
}
button#generateBtn:hover:not(:disabled) {
    background: linear-gradient(135deg, #7a6a5a, #a08060);
    box-shadow: 0 0 25px rgba(139,115,85,0.5); transform: translateY(-2px);
}
button#generateBtn:disabled { opacity: 0.4; cursor: not-allowed; }

.progress {
    display: none; margin: 12px 0 0; color: #999;
    font-family: 'Exo 2', sans-serif; justify-content: center;
    align-items: center; gap: 10px;
}
.spinner {
    width: 22px; height: 22px; border: 3px solid rgba(139,115,85,0.2);
    border-top-color: #8b7355; border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error {
    display: none; color: #ff4444; margin-top: 12px;
    font-weight: bold; font-family: 'Exo 2', sans-serif;
}

.download-btn {
    display: none; margin: 15px auto 0;
    background: linear-gradient(135deg, #5a4a3a, #8b7355);
    color: #fff; border: 2px solid #6b5a45;
    padding: 10px 25px; border-radius: 8px; cursor: pointer;
    font-family: 'Cutive Mono', monospace; font-weight: 900;
    font-size: 0.9rem; letter-spacing: 2px; transition: 0.3s;
}
.download-btn:hover {
    background: linear-gradient(135deg, #7a6a5a, #a08060);
    box-shadow: 0 0 25px rgba(139,115,85,0.5); transform: translateY(-2px);
}
.download-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ═══════════ VIEWPORT (сцена 16:9) ═══════════ */
.viewport {
    display: none;
    width: calc(var(--card-w) * 0.98);
    height: calc(var(--card-h) * 0.98);
    max-width: 95vw;
    aspect-ratio: 16/9;
    position: relative;
    border-radius: 20px;
    box-shadow: 0 0 80px rgba(139,115,85,0.2);
    overflow: hidden;
    z-index: 5;
}

/* Карточка-сцена: тёмный стол, на нём лежит чек */
.receipt-card {
    width: var(--card-w);
    height: var(--card-h);
    position: absolute;
    top: 0; left: 0;
    transform-origin: top left;
    font-family: 'Cutive Mono', monospace;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    /* деревянный/тёмный стол */
    background:
        radial-gradient(ellipse 60% 80% at 50% 50%, rgba(80,60,40,0.35), transparent 70%),
        radial-gradient(ellipse 120% 120% at 50% 120%, rgba(20,14,10,0.6), transparent 60%),
        repeating-linear-gradient(94deg, #2a211a 0px, #2a211a 60px, #271e18 60px, #271e18 120px),
        linear-gradient(160deg, #34281f 0%, #1c1611 100%);
}

/* Декор стола по бокам — монеты, тень */
.table-decor { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.table-decor .coin {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle at 38% 35%, #f4d97a, #b8902f 60%, #8a6a20 100%);
    box-shadow: 0 4px 8px rgba(0,0,0,0.5), inset 0 -2px 4px rgba(0,0,0,0.3);
    border: 1px solid #6e5418;
}
.table-decor .coin::after {
    content: '€'; position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: rgba(110,84,24,0.6); font-weight: bold;
}

/* ── САМ ЧЕК (узкая бумажная лента) ── */
.receipt-paper {
    position: relative;
    z-index: 2;
    width: 560px;
    max-height: 1000px;
    background: linear-gradient(180deg, var(--paper) 0%, var(--paper-dark) 100%);
    color: var(--ink);
    padding: 38px 40px 26px;
    display: flex;
    flex-direction: column;
    box-shadow:
        0 30px 60px rgba(0,0,0,0.55),
        0 10px 20px rgba(0,0,0,0.4);
    transform: rotate(-0.6deg);
}

/* ФИЗИЧЕСКИЕ РВАНЫЕ КРАЯ (html2canvas сохранит их без проблем) */
.r-edge-top, .r-edge-bottom {
    position: absolute;
    left: 0; right: 0;
    height: 10px;
    z-index: 10;
}
.r-edge-top {
    top: -10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='10'%3E%3Cpath d='M0,10 H24 V0 H19 A7,7 0 0,0 5,0 H0 Z' fill='%23f6f1e7'/%3E%3C/svg%3E") repeat-x bottom left;
}
.r-edge-bottom {
    bottom: -10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='10'%3E%3Cpath d='M0,0 H24 V10 H19 A7,7 0 0,1 5,10 H0 Z' fill='%23e7dec9'/%3E%3C/svg%3E") repeat-x top left;
}

/* лёгкая текстура и пятна на бумаге */
.receipt-paper::before {
    content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none;
    background:
        repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(0,0,0,0.012) 3px, rgba(0,0,0,0.012) 4px),
        radial-gradient(circle at 18% 12%, rgba(120,90,50,0.10) 0%, transparent 90px),
        radial-gradient(circle at 82% 78%, rgba(120,90,50,0.08) 0%, transparent 70px);
}
.receipt-paper > * { position: relative; z-index: 1; }

/* ── ШАПКА ── */
.r-head { text-align: center; flex-shrink: 0; }
.r-logo {
    font-size: 1.7rem; font-weight: 700; letter-spacing: 7px;
}
.r-title {
    font-size: 0.95rem; font-weight: 700; letter-spacing: 5px; margin-top: 6px;
}
.r-sub {
    font-size: 0.62rem; color: var(--ink-light); letter-spacing: 2px; margin-top: 4px;
}
.r-meta {
    font-size: 0.6rem; color: var(--ink-light); letter-spacing: 1px;
    margin-top: 3px; line-height: 1.5;
}

.r-divider {
    border: none; border-top: 1px dashed rgba(0,0,0,0.35);
    margin: 9px 0; flex-shrink: 0;
}
.r-divider.solid { border-top: 2px solid rgba(0,0,0,0.55); border-bottom: none; }
.r-divider.double { border-top: 3px double rgba(0,0,0,0.5); }

/* ── ПОКУПАТЕЛЬ ── */
.r-customer {
    display: flex; align-items: center; gap: 14px; flex-shrink: 0;
}
.r-avatar {
    width: 52px; height: 52px; border-radius: 4px;
    border: 1px solid #999; object-fit: cover;
    filter: grayscale(0.55) contrast(1.1) sepia(0.25);
}
.r-cust-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.r-nick { font-size: 0.95rem; font-weight: 700; letter-spacing: 1px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-cust-line { font-size: 0.58rem; color: var(--ink-light); }

/* ── СТРОКИ ТОВАРОВ ── */
.r-items { flex: 1 1 auto; min-height: 0; overflow: hidden; }
.r-section-label {
    font-size: 0.6rem; letter-spacing: 2px; color: var(--ink-light);
    margin-bottom: 6px;
}
.r-item {
    display: flex; justify-content: space-between; align-items: baseline;
    gap: 12px; padding: 2px 0; font-size: 0.78rem;
}
.r-item .ri-idx { width: 20px; color: var(--ink-light); flex-shrink: 0; font-size: 0.7rem; }
.r-item .ri-name {
    flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    letter-spacing: 0.3px;
}
.r-item .ri-tag { font-size: 0.6rem; color: var(--ink-light); flex-shrink: 0; }
.r-item .ri-price { font-weight: 700; flex-shrink: 0; min-width: 78px; text-align: right; }
.r-item.unplayed .ri-name { color: var(--red); }
.r-item.unplayed .ri-name::after { content: ' ✗'; font-size: 0.6rem; }

/* ── ИТОГИ ── */
.r-totals { flex-shrink: 0; }
.r-total-row {
    display: flex; justify-content: space-between; align-items: baseline;
    padding: 2px 0; font-size: 0.74rem;
}
.r-total-row .rt-label { color: var(--ink-light); }
.r-total-row .rt-val { font-weight: 700; text-align: right; }
.r-total-row.grand {
    font-size: 1.15rem; font-weight: 900; letter-spacing: 1px;
    border-top: 2px solid rgba(0,0,0,0.45);
    margin-top: 6px; padding-top: 8px;
}
.r-total-row.grand .rt-val { color: var(--red); }
.r-fine-print {
    font-size: 0.5rem;
    color: var(--ink-light);
    font-style: italic;
    line-height: 1.4;
    margin-top: 6px;
    letter-spacing: 0.2px;
}

/* ── ШУТОЧНЫЕ ЭКВИВАЛЕНТЫ ── */
.r-fun { flex-shrink: 0; }
.r-fun-row {
    display: flex; justify-content: space-between; align-items: baseline;
    padding: 2px 0; font-size: 0.68rem;
}
.r-fun-row .rf-label { color: var(--ink-light); letter-spacing: 0.5px; }
.r-fun-row .rf-val { font-weight: 700; text-align: right; max-width: 58%;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── ШТРИХКОД + ПОДВАЛ ── */
.r-foot { text-align: center; flex-shrink: 0; }
.r-thanks { font-size: 0.78rem; font-weight: 700; letter-spacing: 3px; margin-bottom: 6px; }
.r-disclaimer { font-size: 0.54rem; color: var(--ink-light); line-height: 1.45; }
.r-barcode {
    height: 44px; margin: 10px auto 6px; width: 80%;
    background: transparent;
}
.r-barcode-num { font-size: 0.6rem; letter-spacing: 3px; color: var(--ink); }

/* ── ШТАМП ── */
.r-stamp {
    position: absolute; bottom: 120px; right: 90px; z-index: 3;
    width: 130px; height: 130px;
    border: 4px solid var(--red); border-radius: 50%;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    transform: rotate(-16deg); opacity: 0.5; pointer-events: none;
    color: var(--red);
}
.r-stamp .st-main { font-size: 1rem; font-weight: 900; letter-spacing: 3px; }
.r-stamp .st-sub { font-size: 0.7rem; font-weight: 700; letter-spacing: 2px; }

.receipt-empty {
    text-align: center; padding: 40px 20px; font-size: 0.9rem; color: var(--ink-light);
}

@media (max-width: 768px) {
    .panel h1 { font-size: 1.4rem; }
}

/* базовое позиционирование боковых вкладок */
.nav-side-btn {
    position: absolute;
    top: 25px;
    display: flex;
    align-items: center;
    height: 46px;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: 5;
}

/* ═══════════ ЗАГОЛОВОК ═══════════ */
.nav-left {
    background: rgba(18, 15, 12, 0.95);
    backdrop-filter: blur(10px);
    font-family: 'Cinzel', serif;
    font-size: 0.9rem;
    font-weight: bold;
    letter-spacing: 1px;
    color: var(--bone);
    left: -46px;
    width: 46px;
    border: 1px solid #8b7355;
    border-right: none;
    border-radius: 12px 0 0 12px;
    box-shadow: -5px 0 15px rgba(139, 115, 85, 0.3);
    flex-direction: row-reverse; /* Иконка прижата вправо (к плашке), текст слева */
}

.nav-left:hover {
    width: 190px;
    left: -190px;
    background: rgba(139, 115, 85, 0.15);
    box-shadow: -5px 0 20px var(--blood);
    border-color: #a08060;
}

.nav-icon {
    width: 46px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.nav-text {
    opacity: 0;
    transition: opacity 0.3s;
}

.nav-side-btn:hover .nav-text {
    opacity: 1;
    transition-delay: 0.1s;
}

/* Вкладка на чек (справа) */
.nav-right, .nav-right2 {
    background: rgba(18, 15, 12, 0.95);
    backdrop-filter: blur(10px);
    font-family: 'Cinzel', serif;
    font-size: 0.85rem;
    font-weight: bold;
    letter-spacing: 1px;
    color: var(--bone);
    right: -46px;
    width: 46px;
    border: 1px solid var(--blood);
    border: 1px solid #8b7355;
    border-left: none;
    border-radius: 0 12px 12px 0;
    box-shadow: 5px 0 15px rgba(139, 115, 85, 0.3);
    flex-direction: row;
}

.nav-right:hover, .nav-right2:hover {
    width: 190px;
    right: -190px;
    background: rgba(139, 115, 85, 0.15);
    box-shadow: 5px 0 20px rgba(139, 115, 85, 0.5);
    border-color: #a08060;
}

.nav-right { top: 25px; }
.nav-right2 { top: 81px; }