:root {
  --bg: #f6efe8;
  --bg-soft: #fbf8f4;
  --paper: rgba(255, 252, 248, 0.88);
  --card: rgba(255, 255, 255, 0.78);
  --line: rgba(121, 78, 54, 0.12);
  --text: #3c2a22;
  --muted: #7a6257;
  --primary: #9f2f2f;
  --primary-dark: #7c2020;
  --gold: #d7a14a;
  --green: #2f7d62;
  --blue: #3a6ea5;
  --danger: #b84343;
  --shadow: 0 20px 40px rgba(115, 72, 48, 0.12);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(215, 161, 74, 0.22), transparent 28%),
    radial-gradient(circle at top right, rgba(159, 47, 47, 0.18), transparent 26%),
    linear-gradient(180deg, #fbf6f1 0%, #f3e7dc 100%);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body {
  padding: 20px;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: none;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

button:active {
  transform: scale(0.98);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  border-radius: 14px;
  padding: 16px 18px;
  color: var(--text);
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(159, 47, 47, 0.4);
  box-shadow: 0 0 0 4px rgba(159, 47, 47, 0.12);
}

textarea {
  resize: vertical;
  min-height: 110px;
}

.app-shell {
  max-width: 1600px;
  margin: 0 auto;
  display: grid;
  gap: 20px;
}

.hero-card,
.panel {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: var(--paper);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.hero-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 28px 32px;
  border-radius: var(--radius-xl);
  background:
    linear-gradient(135deg, rgba(159, 47, 47, 0.92), rgba(122, 47, 37, 0.88)),
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.16), transparent 30%);
  color: #fffaf5;
}

.hero-card::after,
.panel::after {
  content: "";
  position: absolute;
  inset: auto -40px -80px auto;
  width: 180px;
  height: 180px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.16), transparent 70%);
  pointer-events: none;
}

.eyebrow,
.panel-tag {
  margin: 0 0 8px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.78rem;
  opacity: 0.82;
}

.hero-card h1,
.panel h2 {
  margin: 0;
  font-family: "Noto Serif SC", serif;
}

.hero-card h1 {
  font-size: clamp(2rem, 3vw, 3rem);
}

.hero-desc {
  margin: 14px 0 0;
  max-width: 760px;
  line-height: 1.7;
  color: rgba(255, 250, 245, 0.88);
}

.hero-actions,
.header-actions,
.handwriting-actions,
.textarea-actions,
.compact-actions,
.ledger-card-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn,
.mini-btn {
  min-height: 52px;
  padding: 0 18px;
  border-radius: 14px;
  font-weight: 600;
}

.primary-btn {
  background: linear-gradient(135deg, #f4c56c, #d7993d);
  color: #532f07;
  box-shadow: 0 10px 25px rgba(215, 161, 74, 0.28);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.16);
  color: #fffaf5;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.ghost-btn {
  background: rgba(159, 47, 47, 0.08);
  color: var(--primary-dark);
}

.danger-btn {
  background: rgba(184, 67, 67, 0.14);
  color: var(--danger);
}

.mini-btn {
  min-height: 46px;
  background: rgba(159, 47, 47, 0.08);
  color: var(--primary-dark);
  padding: 0 14px;
  white-space: nowrap;
}

.large-btn {
  min-height: 60px;
  font-size: 1.05rem;
}

.small-btn {
  min-height: 40px;
  padding: 0 12px;
  border-radius: 10px;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 0.9fr);
  gap: 20px;
  align-items: start;
}

.lower-grid {
  align-items: start;
}

.sidebar-stack {
  display: grid;
  gap: 20px;
}

.panel {
  border-radius: var(--radius-lg);
  padding: 24px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.panel-header h2 {
  font-size: 1.5rem;
}

.compact-ledger-header {
  align-items: center;
}

.gift-form,
.form-grid,
.field {
  display: grid;
  gap: 14px;
}

.two-columns {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field span {
  font-weight: 600;
  color: var(--muted);
}

.input-with-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.segmented-control label {
  position: relative;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  inset: 0;
}

.segmented-control span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  font-weight: 700;
  color: var(--muted);
}

.segmented-control input:checked + span {
  background: linear-gradient(135deg, rgba(159, 47, 47, 0.9), rgba(126, 43, 34, 0.95));
  color: #fff7f0;
  border-color: transparent;
  box-shadow: 0 10px 24px rgba(159, 47, 47, 0.24);
}

.textarea-wrap {
  display: grid;
  gap: 10px;
}

.handwriting-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  border-radius: 18px;
  border: 1px dashed rgba(159, 47, 47, 0.28);
  background: rgba(255, 248, 242, 0.85);
}

.handwriting-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.handwriting-head p,
.hint-text {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

#handwritingCanvas {
  width: 100%;
  height: 280px;
  border-radius: 18px;
  background:
    linear-gradient(transparent 95%, rgba(159, 47, 47, 0.08) 96%),
    linear-gradient(90deg, transparent 95%, rgba(159, 47, 47, 0.05) 96%),
    #fff;
  background-size: 100% 40px, 40px 100%, auto;
  border: 1px solid rgba(159, 47, 47, 0.14);
  touch-action: none;
}

.hidden {
  display: none;
}

.form-actions {
  margin-top: 8px;
}

.top-ledger-panel {
  background:
    linear-gradient(180deg, rgba(255, 248, 243, 0.98), rgba(251, 241, 233, 0.95));
}

.ledger-panel {
  padding-bottom: 16px;
}

.ledger-header-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}

.ledger-pagination {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-indicator {
  min-width: 96px;
  text-align: center;
  font-weight: 700;
  color: var(--primary-dark);
}

.compact-search-toolbar {
  flex: 0 0 300px;
  width: 300px;
  max-width: 32%;
  justify-content: flex-end;
}

.ledger-toolbar {
  display: flex;
  justify-content: flex-end;
}

.ledger-cards {
  display: grid;
  grid-template-columns: repeat(12, minmax(88px, 1fr));
  gap: 10px;
  overflow-x: auto;
  padding: 8px 2px 6px;
}

.ledger-card {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  min-height: 590px;
  min-width: 88px;
  padding: 12px 6px 12px;
  border-radius: 18px;
  border: 1.5px solid rgba(214, 113, 113, 0.4);
  background:
    linear-gradient(180deg, rgba(255, 247, 245, 0.98), rgba(255, 241, 238, 0.96));
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.55);
}

.ledger-card::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 14px;
  border: 1px solid rgba(211, 117, 117, 0.28);
  pointer-events: none;
}

.ledger-card-placeholder {
  opacity: 1;
}

.ledger-card-placeholder .placeholder-text {
  opacity: 0;
}

.ledger-card-head {
  display: grid;
  gap: 8px;
  justify-items: center;
  position: relative;
  z-index: 1;
}

.ledger-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
  background: rgba(159, 47, 47, 0.12);
  color: var(--primary-dark);
}

.ledger-writing-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: 1fr 1.25fr;
  gap: 12px;
  min-height: 470px;
}

.writing-row {
  border-radius: 16px;
  border: 1px solid rgba(214, 113, 113, 0.34);
  background: rgba(255, 255, 255, 0.72);
  padding: 12px 6px;
  display: grid;
}

.name-row {
  min-height: 180px;
}

.amount-row {
  min-height: 250px;
}

.writing-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.writing-cell::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: rgba(214, 113, 113, 0.18);
  transform: translateX(-50%);
}

.amount-cell {
  flex-direction: column;
  gap: 12px;
}

.slip-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  text-align: center;
  font-family: "Noto Serif SC", serif;
  color: #2d2019;
  position: relative;
  z-index: 1;
}

.vertical-text {
  writing-mode: vertical-rl;
  text-orientation: upright;
  line-height: 1.32;
  letter-spacing: 0.12em;
  font-size: 1.42rem;
  font-weight: 700;
}

.name-row .slip-value {
  min-height: 144px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
}

.name-row .slip-value span {
  display: block;
  line-height: 1;
}

.name-row .slip-value.name-two-chars::before {
  content: "";
  display: block;
  height: 1.5rem;
}

.amount-upper {
  font-size: 1.42rem;
  color: #5f1f1f;
}

.amount-number {
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  font-size: 1.18rem;
  font-weight: 700;
  letter-spacing: 0;
  color: #8a5a11;
}

.compact-number {
  margin-top: 0;
}

.placeholder-text {
  color: transparent;
}

.ledger-card-actions {
  display: flex;
  justify-content: center;
  position: relative;
  z-index: 1;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  padding: 18px;
  border-radius: 20px;
  color: #fff;
  display: grid;
  gap: 8px;
}

.stat-card span {
  opacity: 0.86;
}

.stat-card strong {
  font-size: 1.8rem;
}

.accent-red { background: linear-gradient(135deg, #a33131, #7e2323); }
.accent-gold { background: linear-gradient(135deg, #d9a247, #b67f2c); }
.accent-green { background: linear-gradient(135deg, #2f8c69, #21664b); }
.accent-blue { background: linear-gradient(135deg, #4679b2, #2d537e); }

.feature-list {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 12px;
  color: var(--muted);
  line-height: 1.7;
}

.capability-notice {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255, 248, 232, 0.9);
  color: #8f5b17;
  line-height: 1.6;
  min-height: 56px;
}

@media (max-width: 1180px) {
  .main-grid {
    grid-template-columns: 1fr;
  }

  .hero-card,
  .panel-header,
  .handwriting-head {
    flex-direction: column;
    align-items: stretch;
  }

  .compact-search-toolbar {
    width: 100%;
    max-width: 100%;
    flex: 1 1 auto;
  }

  .ledger-cards {
    grid-template-columns: repeat(8, minmax(88px, 1fr));
  }
}

@media (max-width: 820px) {
  body {
    padding: 12px;
  }

  .panel,
  .hero-card {
    padding: 18px;
    border-radius: 20px;
  }

  .two-columns,
  .stats-grid,
  .segmented-control {
    grid-template-columns: 1fr;
  }

  .input-with-action {
    grid-template-columns: 1fr;
  }

  .hero-actions,
  .textarea-actions,
  .handwriting-actions,
  .compact-actions,
  .ledger-card-actions {
    flex-direction: column;
  }

  .primary-btn,
  .secondary-btn,
  .ghost-btn,
  .danger-btn,
  .mini-btn {
    width: 100%;
  }

  .ledger-cards {
    grid-template-columns: repeat(6, minmax(78px, 1fr));
  }

  .ledger-card {
    min-height: 540px;
    min-width: 78px;
  }

  .vertical-text {
    font-size: 0.98rem;
  }
}

@media print {
  body {
    padding: 0;
    background: #fff;
  }

  .hero-card,
  .input-panel,
  .helper-panel,
  .sidebar-stack,
  .ledger-card-actions,
  .compact-search-toolbar {
    display: none !important;
  }

  .app-shell,
  .ledger-panel {
    max-width: none;
    margin: 0;
    box-shadow: none;
  }

  .panel {
    border: none;
    background: #fff;
    box-shadow: none;
    padding: 0;
  }

  .ledger-cards {
    grid-template-columns: repeat(8, 1fr);
    gap: 8px;
    overflow: visible;
  }

  .ledger-card {
    break-inside: avoid;
    min-height: 520px;
    box-shadow: none;
  }
}
