:root {
    --paper: #fdf5f8;
    --text: oklch(0.38 0.05 350);
    --text-soft: oklch(0.58 0.04 350);
    --text-faint: oklch(0.68 0.03 350);
    --rose: oklch(0.7 0.13 350);
    --rose-deep: oklch(0.62 0.16 350);
    --rose-light: oklch(0.93 0.035 350);
    --rose-border: oklch(0.85 0.06 350);
    --mint: oklch(0.6 0.1 165);
    --peach: oklch(0.8 0.09 40);
    --ease: cubic-bezier(0.25, 1, 0.5, 1);
    --serif: "Songti SC", "Noto Serif SC", "STSong", serif;
    --sans: "PingFang SC", "Microsoft YaHei", sans-serif;
  }
  * { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  html, body { height: 100%; }
  body {
    font-family: var(--sans);
    color: var(--text);
    background-color: var(--paper);
    background-image:
      radial-gradient(circle at 12px 12px, oklch(0.9 0.05 350 / 0.5) 1.5px, transparent 1.6px),
      radial-gradient(ellipse 130% 80% at 50% -20%, #ffe3ee, transparent 60%),
      radial-gradient(ellipse 100% 60% at 100% 115%, #ffe8f1, transparent 70%);
    background-size: 26px 26px, 100% 100%, 100% 100%;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-user-select: none; user-select: none;
  }
  .app { max-width: 480px; margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 16px 32px; }
  .hide { display: none !important; }

  header {
    display: flex; flex-direction: column; gap: 8px;
    padding: 6px 2px 12px;
    border-bottom: 1.5px dashed var(--rose-border);
  }
  header h1 {
    font-family: var(--serif); font-size: 18px; font-weight: 900;
    letter-spacing: 0.1em; color: var(--rose-deep); text-align: center;
  }
  header h1 .heart { color: var(--rose); font-size: 0.75em; margin: 0 2px; vertical-align: 0.1em; }
  header .row2 {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
  }
  header .room-code {
    font-family: var(--serif); font-size: 12px; color: var(--rose-deep); letter-spacing: 0.2em;
    background: var(--rose-light); border: 1px dashed var(--rose-border);
    border-radius: 999px; padding: 4px 10px; cursor: pointer; white-space: nowrap;
  }
  .hbtns { display: flex; gap: 6px; }
  .ghost-btn {
    font-family: var(--serif); font-size: 12px; letter-spacing: 0.12em;
    color: var(--text-soft); background: #fff;
    border: 1px solid var(--rose-border); border-radius: 999px;
    padding: 4px 10px; cursor: pointer; white-space: nowrap;
    transition: all 0.25s var(--ease);
    box-shadow: 0 2px 6px oklch(0.85 0.06 350 / 0.25);
  }
  .ghost-btn:active { color: #fff; background: var(--rose); border-color: var(--rose); }

  /* ===== 进门 ===== */
  .gate { padding-top: 10vh; text-align: center; }
  .gate .logo {
    font-family: var(--serif); font-size: clamp(38px, 12vw, 54px); font-weight: 900;
    letter-spacing: 0.15em; color: var(--rose-deep); text-indent: 0.15em;
    text-shadow: 0 2px 0 #fff, 0 4px 10px oklch(0.8 0.08 350 / 0.5);
  }
  .gate .logo .heart { color: var(--rose); font-size: 0.7em; vertical-align: 0.15em; }
  .gate .tip { font-size: 13px; color: var(--text-faint); letter-spacing: 0.18em; margin: 12px 0 40px; }
  .gate .field { margin: 0 auto 14px; max-width: 300px; text-align: left; }
  .gate label {
    display: block; font-family: var(--serif); font-size: 13px;
    color: var(--rose); letter-spacing: 0.2em; margin-bottom: 6px;
  }
  .gate input {
    width: 100%; font-size: 20px; font-family: var(--serif); font-weight: 700;
    color: var(--text); background: #fff;
    border: 1.5px solid var(--rose-border); border-radius: 14px;
    padding: 12px 14px; outline: none; letter-spacing: 0.1em;
    transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
    box-shadow: 0 3px 8px oklch(0.85 0.06 350 / 0.2);
  }
  .gate input:focus { border-color: var(--rose); box-shadow: 0 3px 12px oklch(0.8 0.08 350 / 0.4); }
  .gate .enter {
    margin-top: 26px; width: 300px;
    font-family: var(--serif); font-size: 18px; font-weight: 900;
    letter-spacing: 0.4em; text-indent: 0.4em;
    color: #fff;
    background: linear-gradient(180deg, oklch(0.74 0.12 350), var(--rose-deep));
    border: none; border-radius: 999px; padding: 15px 0; cursor: pointer;
    box-shadow: 0 4px 14px oklch(0.75 0.12 350 / 0.55), 0 1px 0 oklch(0.9 0.08 350 / 0.8) inset;
    transition: transform 0.25s var(--ease);
  }
  .gate .enter:active { transform: translateY(2px) scale(0.98); }
  .gate .hint { margin-top: 22px; font-size: 12px; color: var(--text-faint); line-height: 1.8; }

  /* ===== 牌面 ===== */
  .table {
    display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px;
  }
  .tile {
    position: relative; text-align: left; border: 1.5px solid var(--rose-light);
    background: linear-gradient(170deg, #fff 0%, #fff4f8 100%);
    border-radius: 18px; padding: 14px 14px 12px;
    box-shadow: 0 4px 12px oklch(0.82 0.06 350 / 0.35), 0 1px 0 #fff inset;
    cursor: pointer; overflow: hidden;
    transition: transform 0.3s var(--ease), box-shadow 0.3s var(--ease);
  }
  .tile:active {
    transform: translateY(2px) scale(0.98);
    box-shadow: 0 2px 6px oklch(0.82 0.06 350 / 0.3);
    border-color: var(--rose);
  }
  .tile .badge {
    position: absolute; top: 10px; right: 10px; font-size: 11px; font-weight: 700;
    color: #fff; background: var(--rose); border-radius: 999px; padding: 2px 8px;
    box-shadow: 0 2px 5px oklch(0.75 0.12 350 / 0.5);
  }
  .tile .badge.away-b {
    right: 44px; background: var(--text-faint);
    box-shadow: 0 2px 5px oklch(0.7 0.03 350 / 0.35);
  }
  .tile.away { opacity: 0.55; filter: grayscale(0.4); }
  .tile .name {
    font-family: var(--serif); font-weight: 700; font-size: 18px;
    max-width: 8em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    border-bottom: 2px dotted var(--rose-border);
    padding-bottom: 4px; margin-bottom: 8px;
  }
  .tile .total {
    font-size: clamp(30px, 9vw, 40px); font-weight: 800;
    font-variant-numeric: tabular-nums; line-height: 1; letter-spacing: -0.02em;
  }
  .total.pos-v { color: var(--rose-deep); }
  .total.neg-v { color: var(--mint); }
  .total.zero-v { color: var(--text-faint); }

  /* ===== 流水 ===== */
  .log-box { margin-top: 26px; }
  .log-box h3 {
    font-family: var(--serif); font-size: 14px; letter-spacing: 0.25em;
    color: var(--rose); margin-bottom: 8px;
  }
  .log-item {
    display: flex; justify-content: space-between; gap: 10px;
    padding: 8px 4px; font-size: 13px;
    border-bottom: 1px dashed var(--rose-border);
    color: var(--text-soft);
  }
  .log-item .no { color: var(--rose); flex-shrink: 0; }

  /* ===== 抽屉 ===== */
  .sheet-mask {
    position: fixed; inset: 0; background: oklch(0.5 0.08 350 / 0.35);
    backdrop-filter: blur(3px); opacity: 0; pointer-events: none;
    transition: opacity 0.35s var(--ease); z-index: 10;
  }
  .sheet-mask.open { opacity: 1; pointer-events: auto; }
  .sheet {
    position: fixed; left: 0; right: 0; bottom: 0; max-width: 480px; margin: 0 auto;
    background: linear-gradient(180deg, #fff, #fdf1f6);
    border-radius: 24px 24px 0 0;
    border-top: 1.5px solid var(--rose-border);
    padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
    transform: translateY(105%); transition: transform 0.45s var(--ease);
    z-index: 11;
    box-shadow: 0 -8px 30px oklch(0.8 0.08 350 / 0.35);
  }
  .sheet.open { transform: translateY(0); }
  .sheet h2 {
    font-family: var(--serif); font-size: 18px; letter-spacing: 0.1em;
    color: var(--rose-deep); margin-bottom: 12px; text-align: center;
  }
  .dir-switch {
    display: flex; border: 1.5px solid var(--rose-border); border-radius: 999px;
    overflow: hidden; margin-bottom: 12px; background: #fff;
  }
  .dir-switch button {
    flex: 1; font-family: var(--serif); font-size: 14px; font-weight: 700;
    padding: 9px 0; background: none; border: none; color: var(--text-faint); cursor: pointer;
    letter-spacing: 0.08em; transition: all 0.2s var(--ease);
  }
  .dir-switch button.on { background: linear-gradient(180deg, oklch(0.74 0.12 350), var(--rose-deep)); color: #fff; }
  .amt-display {
    width: 100%; text-align: center; font-size: 40px; font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--rose-deep); background: #fff;
    border: 1.5px solid var(--rose-border); border-radius: 16px;
    padding: 10px 0 12px; outline: none; letter-spacing: 0.03em; margin-bottom: 12px;
    box-shadow: 0 2px 6px oklch(0.85 0.06 350 / 0.2) inset;
  }
  .amt-display:focus { border-color: var(--rose); }
  .quick { display: flex; gap: 8px; margin-bottom: 12px; }
  .quick button {
    flex: 1; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums;
    padding: 9px 0; border-radius: 999px; cursor: pointer;
    border: 1.5px solid var(--rose-border); background: #fff; color: var(--rose-deep);
    transition: transform 0.15s var(--ease);
    box-shadow: 0 2px 5px oklch(0.85 0.06 350 / 0.2);
  }
  .quick button:active { transform: scale(0.92); background: var(--rose-light); }
  .pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .pad button {
    font-size: 21px; font-weight: 700; padding: 13px 0; border-radius: 14px;
    background: #fff; border: 1.5px solid var(--rose-light);
    color: var(--text); cursor: pointer;
    transition: all 0.15s var(--ease);
    box-shadow: 0 2px 5px oklch(0.85 0.06 350 / 0.18);
  }
  .pad button:active { background: var(--rose-light); border-color: var(--rose); transform: scale(0.95); }
  .pad .fn { color: var(--rose); }
  .actions { display: flex; gap: 10px; margin-top: 12px; }
  .actions button {
    flex: 1; font-family: var(--serif); font-size: 16px; font-weight: 700;
    letter-spacing: 0.2em; text-indent: 0.2em; padding: 12px 0;
    border-radius: 999px; border: none; cursor: pointer;
  }
  .btn-cancel { background: #fff; color: var(--text-soft); border: 1.5px solid var(--rose-border) !important; }
  .btn-confirm {
    background: linear-gradient(180deg, oklch(0.74 0.12 350), var(--rose-deep)); color: #fff;
    box-shadow: 0 4px 12px oklch(0.75 0.12 350 / 0.5);
  }
  .btn-confirm:disabled { opacity: 0.35; box-shadow: none; }
  .confirm-label { font-size: 12px; color: var(--text-faint); text-align: center; margin-top: 8px; letter-spacing: 0.05em; }

  .name-input {
    width: 100%; font-size: 22px; font-family: var(--serif); font-weight: 700;
    color: var(--rose-deep); background: #fff; text-align: center;
    border: 1.5px solid var(--rose-border); border-radius: 16px;
    padding: 12px 14px; outline: none; letter-spacing: 0.1em;
    box-shadow: 0 2px 6px oklch(0.85 0.06 350 / 0.2) inset;
    margin-bottom: 4px;
  }
  .name-input:focus { border-color: var(--rose); }

  .toast {
    position: fixed; top: 16px; left: 50%; transform: translateX(-50%) translateY(-90px);
    background: #fff; border: 1.5px solid var(--rose-border);
    color: var(--rose-deep); font-size: 14px; font-weight: 600; padding: 10px 20px; border-radius: 999px;
    box-shadow: 0 6px 18px oklch(0.8 0.08 350 / 0.4);
    transition: transform 0.4s var(--ease); z-index: 20; pointer-events: none;
  }
  .toast.show { transform: translateX(-50%) translateY(0); }
