:root {
  --receipt-bg: #f5f0e8;
  --receipt-paper: #fffcf5;
  --ink: #1a1a1a;
  --muted: #8a8580;
  --accent: #c8401f;
  --accent-light: #e8d5d0;
  --green: #2d7a3a;
  --line: #d4cfc5;
  --mono: 'Courier New', 'Courier', monospace;
  --serif: 'Georgia', 'Times New Roman', serif;
}

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

body {
  background: var(--receipt-bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

#app {
  max-width: 580px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

/* Top bar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--ink);
}

.brand {
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  font-weight: bold;
  letter-spacing: -0.3px;
}

.brand .accent { color: var(--accent); }

.lang-switch {
  display: flex;
  gap: 0;
  border: 1px solid var(--ink);
  font-size: 11px;
}

.lang-switch button {
  background: none;
  border: none;
  border-right: 1px solid var(--ink);
  padding: 4px 10px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink);
  transition: all 0.1s;
}

.lang-switch button:last-child { border-right: none; }
.lang-switch button.active { background: var(--ink); color: var(--receipt-bg); }
.lang-switch button:hover:not(.active) { background: var(--accent-light); }

/* Intro */
.intro { margin-bottom: 28px; }

.intro h1 {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: bold;
  line-height: 1.25;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.intro p {
  color: var(--muted);
  font-size: 13px;
}

/* Input */
.input-area { margin-bottom: 20px; }

.input-area textarea {
  width: 100%;
  min-height: 110px;
  padding: 14px;
  border: 2px solid var(--ink);
  background: var(--receipt-paper);
  font-family: var(--mono);
  font-size: 14px;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}

.input-area textarea:focus { border-color: var(--accent); }
.input-area textarea::placeholder { color: #bbb; }

.sample-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.sample-link {
  font-size: 12px;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
}

.sample-link:hover { color: var(--accent); }

.char-count {
  font-size: 11px;
  color: var(--muted);
}

.btn-generate {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--ink);
  color: var(--receipt-bg);
  border: none;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  margin-top: 12px;
  transition: background 0.15s;
  letter-spacing: 0.5px;
}

.btn-generate:hover { background: var(--accent); }
.btn-generate:disabled { opacity: 0.4; cursor: wait; }

.pricing-hint {
  margin-top: 14px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px dashed var(--line);
  border-bottom: 1px dashed var(--line);
}

.pricing-hint strong { color: var(--ink); }

/* Loading */
.loading {
  display: none;
  text-align: center;
  padding: 40px 20px;
  background: var(--receipt-paper);
  border: 2px dashed var(--line);
}

.loading.visible { display: block; }

.loading .msg {
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  color: var(--muted);
}

.loading .dots::after {
  content: '';
  animation: dots 1.4s infinite;
}

@keyframes dots {
  0%, 20% { content: ''; }
  40% { content: '.'; }
  60% { content: '..'; }
  80%, 100% { content: '...'; }
}

/* Receipt */
.receipt-container {
  display: none;
  margin-top: 28px;
}

.receipt-container.visible { display: block; }

.receipt {
  background: var(--receipt-paper);
  border: none;
  padding: 0;
  position: relative;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  /* jagged top and bottom edges */
  -webkit-mask-image:
    linear-gradient(#fff, #fff),
    linear-gradient(45deg, transparent 33%, #fff 33%, #fff 67%, transparent 67%),
    linear-gradient(-45deg, transparent 33%, #fff 33%, #fff 67%, transparent 67%);
  -webkit-mask-size: 100% 100%, 12px 12px, 12px 12px;
  -webkit-mask-position: top, bottom, bottom;
  -webkit-mask-repeat: repeat-x, repeat-x, repeat-x;
}

/* Crinkled paper effect */
.receipt::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 28px,
      rgba(212, 207, 197, 0.15) 28px,
      rgba(212, 207, 197, 0.15) 29px
    );
  pointer-events: none;
}

.receipt-header {
  text-align: center;
  padding: 24px 20px 12px;
  border-bottom: 2px dashed var(--ink);
  position: relative;
}

.receipt-header .store {
  font-family: var(--serif);
  font-style: italic;
  font-size: 20px;
  font-weight: bold;
  line-height: 1.2;
}

.receipt-header .addr {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.receipt-header .receipt-id {
  font-size: 10px;
  color: var(--muted);
  margin-top: 8px;
  letter-spacing: 1px;
}

.receipt-meta {
  padding: 12px 20px;
  border-bottom: 1px dashed var(--line);
  font-size: 11px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

.receipt-items {
  padding: 8px 20px;
}

.item-row {
  padding: 10px 0;
  border-bottom: 1px dotted var(--line);
}

.item-name {
  font-size: 13px;
  line-height: 1.4;
  margin-bottom: 4px;
}

.item-detail {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}

.item-detail .price {
  font-family: var(--mono);
  font-weight: bold;
  color: var(--ink);
}

.item-category {
  display: inline-block;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 1px 6px;
  border: 1px solid var(--line);
  margin-right: 6px;
  color: var(--muted);
}

.receipt-totals {
  padding: 16px 20px;
  border-top: 2px dashed var(--ink);
}

.total-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
}

.total-row.grand {
  border-top: 2px solid var(--ink);
  margin-top: 8px;
  padding-top: 12px;
  font-size: 18px;
  font-weight: bold;
}

.total-row.grand .amount {
  font-family: var(--serif);
  font-size: 28px;
  font-style: italic;
  color: var(--accent);
}

.receipt-footer {
  padding: 16px 20px;
  border-top: 2px dashed var(--ink);
  text-align: center;
}

.receipt-footer .payment {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.receipt-footer .cashier {
  font-size: 11px;
  color: var(--muted);
}

.receipt-footer .barcode {
  font-family: var(--mono);
  font-size: 24px;
  letter-spacing: -2px;
  margin: 8px 0;
  color: var(--ink);
  overflow: hidden;
  white-space: nowrap;
}

.receipt-footer .barcode-text {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--muted);
}

.qr-section {
  margin-top: 12px;
  text-align: center;
}

.qr-code {
  width: 80px;
  height: 80px;
  display: block;
  margin: 0 auto;
  image-rendering: pixelated;
}

.qr-code rect {
  fill: var(--ink);
}

.qr-label {
  font-size: 9px;
  color: var(--muted);
  margin-top: 4px;
  letter-spacing: 1px;
}

/* Return policy (premium) */
.return-policy {
  margin-top: 0;
  padding: 16px 20px;
  border-top: 2px dashed var(--ink);
  background: rgba(200, 64, 31, 0.04);
}

.return-policy .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  font-weight: bold;
  margin-bottom: 6px;
}

.return-policy .text {
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
}

/* Share actions */
.share-actions {
  margin-top: 24px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-share {
  flex: 1;
  min-width: 120px;
  padding: 10px 14px;
  border: 1px solid var(--ink);
  background: var(--receipt-paper);
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.1s;
  text-align: center;
}

.btn-share:hover { background: var(--ink); color: var(--receipt-bg); }

.btn-premium {
  flex: 2;
  min-width: 200px;
  padding: 12px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  transition: opacity 0.15s;
  text-align: center;
}

.btn-premium:hover { opacity: 0.85; }

.btn-again {
  width: 100%;
  padding: 12px;
  background: none;
  color: var(--muted);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 13px;
  cursor: pointer;
  margin-top: 12px;
}

.btn-again:hover { color: var(--ink); border-color: var(--ink); }

/* Payment modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.visible { display: flex; }

.modal {
  background: var(--receipt-bg);
  border: 2px solid var(--ink);
  max-width: 460px;
  width: 100%;
  padding: 28px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal h2 {
  font-family: var(--serif);
  font-size: 22px;
  margin-bottom: 6px;
  font-style: italic;
}

.modal .sub {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 20px;
}

.modal .price-tag {
  font-family: var(--serif);
  font-style: italic;
  font-size: 36px;
  color: var(--accent);
  margin: 12px 0;
}

.modal .step {
  margin-bottom: 16px;
}

.modal .step-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 4px;
}

.wallet-box {
  font-family: var(--mono);
  font-size: 12px;
  padding: 10px;
  background: var(--receipt-paper);
  border: 1px solid var(--ink);
  word-break: break-all;
  position: relative;
  padding-right: 60px;
}

.wallet-box .copy-btn {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  background: var(--ink);
  color: var(--receipt-bg);
  border: none;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  font-family: var(--mono);
}

.modal input[type="text"] {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  outline: none;
  background: var(--receipt-paper);
}

.modal input[type="text"]:focus { border-color: var(--accent); }

.modal .btn-submit {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--ink);
  color: var(--receipt-bg);
  border: none;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  margin-top: 16px;
}

.modal .btn-submit:hover { background: var(--accent); }
.modal .btn-submit:disabled { opacity: 0.4; cursor: wait; }

.modal .btn-close {
  display: block;
  width: 100%;
  padding: 10px;
  background: none;
  color: var(--muted);
  border: none;
  font-family: var(--mono);
  font-size: 13px;
  cursor: pointer;
  margin-top: 8px;
}

.modal .error-msg {
  color: var(--accent);
  font-size: 13px;
  margin-top: 8px;
}

/* Footer */
.footer {
  margin-top: 48px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

.footer a { color: var(--muted); text-decoration: underline; }

/* Mobile */
@media (max-width: 480px) {
  .intro h1 { font-size: 23px; }
  .total-row.grand .amount { font-size: 24px; }
  .receipt-header .store { font-size: 17px; }
  .share-actions { flex-direction: column; }
  .btn-share, .btn-premium { flex: none; }
}

/* Sample banner */
.sample-banner {
  background: var(--accent-light);
  color: var(--accent);
  font-size: 12px;
  text-align: center;
  padding: 8px 12px;
  border: 1px dashed var(--accent);
  border-radius: 3px;
  margin-bottom: 12px;
  font-family: var(--mono);
}
