  :root {
    --bg: #F5F1E8;
    --surface: #FFFFFF;
    --ink: #0A0A0A;
    --accent: #FFE668;
    --accent-2: #FF6B4A;
    --accent-3: #4ADE80;
    --accent-4: #7C9EFF;
    --muted: #6B6B6B;
    --border: #0A0A0A;
    --shadow: 6px 6px 0 #0A0A0A;
    --shadow-sm: 3px 3px 0 #0A0A0A;
    --shadow-lg: 8px 8px 0 #0A0A0A;
    --radius: 14px;
  }
  [data-theme="dark"] {
    --bg: #141414;
    --surface: #1F1F1F;
    --ink: #F5F1E8;
    --accent: #FFE668;
    --accent-2: #FF6B4A;
    --accent-3: #4ADE80;
    --accent-4: #7C9EFF;
    --muted: #9A9A9A;
    --border: #F5F1E8;
    --shadow: 6px 6px 0 #F5F1E8;
    --shadow-sm: 3px 3px 0 #F5F1E8;
    --shadow-lg: 8px 8px 0 #F5F1E8;
  }

  * { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
  html, body {
    background: var(--bg);
    color: var(--ink);
    font-family: 'Bai Jamjuree', sans-serif;
    font-size: 16px;
    line-height: 1.5;
    min-height: 100vh;
    overscroll-behavior: none;
  }
  body {
    background-image: radial-gradient(circle at 1px 1px, rgba(10,10,10,0.08) 1px, transparent 0);
    background-size: 24px 24px;
    padding-bottom: 180px;
  }
  [data-theme="dark"] body {
    background-image: radial-gradient(circle at 1px 1px, rgba(245,241,232,0.06) 1px, transparent 0);
  }

  /* ============ HEADER ============ */
  header {
    position: sticky;
    top: 0;
    z-index: 40;
    background: var(--accent);
    border-bottom: 3px solid var(--border);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .logo { display: flex; align-items: center; gap: 10px; }
  .logo-mark {
    width: 36px; height: 36px;
    background: var(--ink);
    color: var(--accent);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 19px;
    transform: rotate(-4deg);
    box-shadow: 2px 2px 0 rgba(0,0,0,0.15);
  }
  .logo-text { font-weight: 800; font-size: 19px; letter-spacing: -0.02em; color: #0A0A0A; line-height: 1; }
  .logo-text span { font-size: 10px; font-weight: 500; opacity: 0.7; display: block; margin-top: 2px; }

  .head-actions { display: flex; gap: 6px; }
  .icon-btn {
    width: 38px; height: 38px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.15s;
  }
  .icon-btn:active { transform: scale(0.92); }

  /* ============ STICKY SUMMARY BAR ============ */
  .sticky-summary {
    position: sticky;
    top: 63px;
    z-index: 35;
    background: var(--accent);
    border-bottom: 3px solid var(--border);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    cursor: pointer;
  }
  .sum-left { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
  .sum-meta {
    display: flex;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    color: #0A0A0A;
    opacity: 0.75;
    align-items: center;
    flex-wrap: wrap;
  }
  .sum-meta .dot { opacity: 0.4; }
  .sum-total {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 800;
    font-size: 22px;
    color: #0A0A0A;
    line-height: 1;
    display: flex;
    align-items: baseline;
    gap: 4px;
  }
  .sum-total small { font-size: 13px; opacity: 0.6; }
  .sum-right { display: flex; align-items: center; gap: 8px; }
  .sum-expand {
    width: 36px; height: 36px;
    border-radius: 10px;
    background: #0A0A0A;
    color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
    border: 2px solid #0A0A0A;
    box-shadow: 2px 2px 0 rgba(0,0,0,0.2);
    transition: transform 0.15s;
  }
  .sticky-summary:active .sum-expand { transform: translate(1px, 1px); }
  .sum-per-preview {
    font-size: 11px;
    font-weight: 600;
    color: #0A0A0A;
    opacity: 0.75;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  /* ============ CONTAINER ============ */
  main { max-width: 720px; margin: 0 auto; padding: 16px 14px; }

  /* ============ SECTIONS ============ */
  .section {
    background: var(--surface);
    border: 2.5px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 14px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }
  .sec-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    cursor: pointer;
    user-select: none;
    gap: 8px;
  }
  .sec-title {
    font-size: 14px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
  }
  .sec-title .emoji { font-size: 18px; }
  .sec-header-right { display: flex; align-items: center; gap: 8px; }
  .badge {
    background: var(--ink);
    color: var(--surface);
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
  }
  .badge.accent { background: var(--accent); color: #0A0A0A; }
  .chev {
    display: inline-flex;
    width: 28px; height: 28px;
    align-items: center; justify-content: center;
    border-radius: 8px;
    background: var(--bg);
    font-size: 14px;
    transition: transform 0.25s ease;
  }
  .section.collapsed .chev { transform: rotate(-90deg); }
  .sec-body {
    max-height: 3000px;
    overflow: hidden;
    transition: max-height 0.35s ease, padding 0.3s ease, opacity 0.25s ease;
    padding: 0 16px 16px 16px;
    opacity: 1;
  }
  .section.collapsed .sec-body {
    max-height: 0;
    padding: 0 16px;
    opacity: 0;
  }

  .sec-preview {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
    display: none;
  }
  .section.collapsed .sec-preview { display: inline; }

  /* ============ BUTTONS ============ */
  .btn {
    border: 2.5px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    padding: 10px 16px;
    border-radius: 10px;
    font-family: inherit;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.08s, box-shadow 0.08s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
  }
  .btn:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 var(--border);
  }
  .btn.primary { background: var(--ink); color: var(--surface); }
  [data-theme="dark"] .btn.primary { background: var(--surface); color: var(--ink); }
  .btn.accent { background: var(--accent); color: #0A0A0A; }
  .btn.danger { background: var(--accent-2); color: white; }
  .btn.success { background: var(--accent-3); color: #0A0A0A; }
  .btn.ghost { background: transparent; box-shadow: none; border: 2px dashed var(--border); }
  .btn.sm { padding: 6px 10px; font-size: 12px; box-shadow: 2px 2px 0 var(--border); }
  .btn.block { width: 100%; justify-content: center; }

  /* ============ INPUTS ============ */
  .input, .select {
    width: 100%;
    border: 2.5px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    padding: 10px 12px;
    border-radius: 10px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 500;
    outline: none;
    transition: box-shadow 0.1s;
  }
  .input:focus, .select:focus {
    box-shadow: var(--shadow-sm);
    transform: translate(-1px, -1px);
  }
  .input.mono { font-family: 'JetBrains Mono', monospace; font-weight: 700; }
  .row { display: flex; gap: 8px; }
  .row > * { flex: 1; min-width: 0; }
  .row-tight { gap: 6px; }

  /* ============ PEOPLE CHIPS ============ */
  .people-grid { display: flex; flex-wrap: wrap; gap: 8px; min-height: 44px; }
  .chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--accent);
    color: #0A0A0A;
    border: 2.5px solid var(--border);
    padding: 6px 8px 6px 12px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 14px;
    box-shadow: 2px 2px 0 var(--border);
    max-width: 100%;
  }
  .chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
  .chip .x {
    width: 22px; height: 22px;
    border-radius: 50%;
    background: var(--ink);
    color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-weight: 800;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    flex-shrink: 0;
  }
  .chip:nth-child(3n) { background: var(--accent-3); }
  .chip:nth-child(3n+1) { background: var(--accent-4); color: white; }
  .chip:nth-child(3n+1) .x { background: white; color: var(--accent-4); }
  .chip:nth-child(3n+2) { background: var(--accent-2); color: white; }
  .chip:nth-child(3n+2) .x { background: white; color: var(--accent-2); }

  .empty {
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    padding: 14px;
    border: 2px dashed var(--border);
    border-radius: 10px;
    opacity: 0.6;
  }

  /* ============ ITEM LIST ============ */
  .item {
    border: 2.5px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    position: relative;
  }
  .item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
  .item-name { font-weight: 700; font-size: 15px; flex: 1; word-break: break-word; padding-right: 56px; }
  .item-price { font-family: 'JetBrains Mono', monospace; font-weight: 800; font-size: 16px; }
  .item-meta { font-size: 12px; opacity: 0.75; margin-top: 4px; font-family: 'JetBrains Mono', monospace; }
  .item-payers { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
  .payer-tag {
    padding: 3px 10px;
    border: 2px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    background: var(--surface);
    color: var(--ink);
    transition: transform 0.08s;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .payer-tag.on { background: var(--ink); color: var(--surface); }
  [data-theme="dark"] .payer-tag.on { background: var(--surface); color: var(--ink); }
  .payer-tag:active { transform: scale(0.95); }
  .item-actions { position: absolute; top: 10px; right: 10px; }

  /* ============ PRESETS ============ */
  .presets {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    margin-top: 10px;
    padding-bottom: 4px;
    scrollbar-width: none;
  }
  .presets::-webkit-scrollbar { display: none; }
  .preset {
    flex: 0 0 auto;
    padding: 6px 12px;
    border: 2px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--ink);
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
  }
  .preset:active { transform: scale(0.95); }

  /* ============ RECEIPT OCR ============ */
  .receipt-dropzone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 12px;
    background: linear-gradient(135deg, var(--surface), var(--bg));
  }
  .receipt-status {
    margin-top: 10px;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 12px;
    font-weight: 700;
    background: var(--surface);
  }
  .receipt-preview {
    margin-top: 12px;
    border: 2.5px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
  }
  .receipt-preview img {
    display: block;
    width: 100%;
    max-height: 240px;
    object-fit: cover;
  }
  .receipt-result {
    margin-top: 12px;
    border: 2.5px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
  }
  .receipt-result-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 13px;
  }
  .receipt-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .receipt-line {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    background: var(--bg);
  }
  .receipt-line strong {
    display: block;
    font-size: 14px;
    word-break: break-word;
  }
  .receipt-line span {
    font-size: 11px;
    color: var(--muted);
  }
  .receipt-line-price {
    font-family: 'JetBrains Mono', monospace;
    font-size: 15px;
    font-weight: 800;
    white-space: nowrap;
  }
  .receipt-raw {
    margin-top: 12px;
    border-top: 2px dashed var(--border);
    padding-top: 12px;
  }
  .receipt-raw summary {
    cursor: pointer;
    font-weight: 700;
    font-size: 12px;
  }
  .receipt-raw textarea {
    margin-top: 10px;
    width: 100%;
    min-height: 180px;
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    background: var(--bg);
    color: var(--ink);
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    resize: vertical;
  }

  /* ============ EXTRAS ============ */
  .extras { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .extra-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    font-size: 13px;
  }
  .extra-row label { font-weight: 600; display: flex; align-items: center; gap: 6px; }
  .switch {
    width: 40px; height: 22px;
    background: var(--border);
    border-radius: 999px;
    position: relative;
    cursor: pointer;
    flex-shrink: 0;
    opacity: 0.3;
    transition: opacity 0.15s;
  }
  .switch::after {
    content: '';
    position: absolute;
    width: 16px; height: 16px;
    background: white;
    border-radius: 50%;
    top: 3px; left: 3px;
    transition: left 0.15s;
  }
  .switch.on { background: var(--accent-3); opacity: 1; }
  .switch.on::after { left: 21px; }

  .discount-type {
    display: flex;
    gap: 4px;
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 2px;
    background: var(--surface);
  }
  .discount-type button {
    flex: 1;
    padding: 6px;
    border: none;
    background: transparent;
    font-family: inherit;
    font-weight: 700;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--ink);
  }
  .discount-type button.on { background: var(--ink); color: var(--surface); }
  [data-theme="dark"] .discount-type button.on { background: var(--surface); color: var(--ink); }

  /* ============ BILLS ============ */
  .bill-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 10px;
    margin-bottom: 8px;
    background: var(--surface);
    gap: 8px;
  }
  .bill-row .info { flex: 1; min-width: 0; }
  .bill-row .info strong { display: block; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bill-row .info small { font-size: 11px; opacity: 0.7; }

  /* ============ BOTTOM BAR ============ */
  .bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 3px solid var(--border);
    padding: 12px 14px;
    display: flex;
    gap: 8px;
    z-index: 25;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
  }

  /* ============ FAB ============ */
  .fab-top {
    position: fixed;
    right: 14px;
    bottom: 82px;
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--ink);
    color: var(--accent);
    border: 2.5px solid var(--border);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    font-size: 18px;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 24;
    transition: transform 0.15s;
  }
  [data-theme="dark"] .fab-top { background: var(--surface); color: var(--ink); }
  .fab-top.show { display: flex; }
  .fab-top:active { transform: scale(0.9); }

  /* ============ MODAL ============ */
  .modal-bg {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 100;
    display: none;
    align-items: flex-end;
    justify-content: center;
  }
  .modal-bg.show { display: flex; animation: fadein 0.2s; }
  @keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
  @keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }

  .modal {
    background: var(--bg);
    border-top: 3px solid var(--border);
    border-radius: 20px 20px 0 0;
    padding: 20px 18px;
    width: 100%;
    max-width: 720px;
    max-height: 92vh;
    overflow-y: auto;
    animation: slideup 0.25s;
  }
  .modal-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
  }
  .modal-title h3 { font-size: 18px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
  .close-btn {
    width: 36px; height: 36px;
    border-radius: 50%;
    border: 2.5px solid var(--border);
    background: var(--surface);
    font-size: 18px;
    cursor: pointer;
    font-weight: 700;
  }

  /* ============ SUMMARY MODAL ============ */
  .sum-big {
    background: var(--accent);
    color: #0A0A0A;
    border: 3px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    margin-bottom: 14px;
    position: relative;
    overflow: hidden;
  }
  .sum-big::before {
    content: '';
    position: absolute;
    top: -40px; right: -40px;
    width: 120px; height: 120px;
    background: var(--accent-2);
    border-radius: 50%;
    opacity: 0.3;
  }
  .sum-big-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.7; }
  .sum-big-amt {
    font-family: 'JetBrains Mono', monospace;
    font-size: 40px;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1;
    margin-top: 4px;
  }
  .sum-big-amt small { font-size: 16px; opacity: 0.6; margin-left: 4px; }
  .breakdown {
    display: flex; flex-direction: column; gap: 4px;
    font-size: 13px;
    margin-top: 12px;
    position: relative; z-index: 1;
  }
  .breakdown .row-b {
    display: flex; justify-content: space-between;
    font-family: 'JetBrains Mono', monospace;
  }
  .breakdown .row-b strong { font-weight: 800; }

  .per-person { display: flex; flex-direction: column; gap: 8px; }
  .per-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #0A0A0A;
    color: var(--accent);
    padding: 12px 14px;
    border-radius: 10px;
    font-weight: 700;
    border: 2px solid #0A0A0A;
  }
  .per-row .name { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
  .per-row .amt { font-family: 'JetBrains Mono', monospace; font-size: 17px; }

  /* ============ QR ============ */
  .qr-wrap {
    background: white;
    border: 3px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow);
    margin-top: 12px;
  }
  .qr-wrap img, .qr-wrap canvas { display: block; margin: 0 auto; max-width: 100%; }
  .qr-header {
    background: #002D5C;
    color: white;
    margin: -20px -20px 16px -20px;
    padding: 12px;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.1em;
    border-radius: 11px 11px 0 0;
  }
  .qr-amount {
    font-family: 'JetBrains Mono', monospace;
    font-size: 24px;
    font-weight: 800;
    color: #002D5C;
    margin-top: 10px;
  }
  .qr-recipient { font-size: 13px; color: #555; margin-top: 4px; word-break: break-all; }

  /* ============ TOAST ============ */
  .toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--ink);
    color: var(--surface);
    padding: 10px 18px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 13px;
    z-index: 200;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    white-space: nowrap;
  }
  .toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

  #exportCard {
    position: fixed;
    left: -9999px;
    top: 0;
    width: 500px;
    padding: 28px;
    background: var(--bg);
    font-family: 'Bai Jamjuree', sans-serif;
  }

  .hint { font-size: 11px; color: var(--muted); margin-top: 6px; line-height: 1.4; }
  .danger-link { color: var(--accent-2); font-size: 12px; font-weight: 700; cursor: pointer; background: none; border: none; font-family: inherit; }

  @media (max-width: 420px) {
    .extras { grid-template-columns: 1fr; }
    .sum-total { font-size: 20px; }
    .sum-big-amt { font-size: 32px; }
    .chip .name { max-width: 100px; }
  }
