:root {
    --ink: #18313a;
    --muted: #687b82;
    --line: #d9e5e7;
    --paper: #ffffff;
    --sky: #f2fafb;
    --mint: #d9f4ea;
    --teal: #177c70;
    --teal-dark: #10584f;
    --yellow: #ffd85a;
    --yellow-soft: #fff3b5;
    --coral: #ff8a72;
    --coral-soft: #ffe2db;
    --shadow: 0 16px 38px rgba(33, 76, 83, .11);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
    margin: 0;
    color: var(--ink);
    background: var(--sky);
    font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
    letter-spacing: 0;
}
button, input { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
svg { width: 19px; height: 19px; stroke-width: 2; }

.eyebrow {
    margin: 0 0 7px;
    color: var(--teal);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
}

.btn, .icon-btn, .today-btn {
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: transform .16s ease, background .16s ease, border-color .16s ease;
}
.btn:active, .icon-btn:active, .today-btn:active { transform: translateY(1px); }
.btn { padding: 0 18px; font-weight: 800; }
.btn-primary { color: #fff; background: var(--teal); border-color: var(--teal); }
.btn-primary:hover { background: var(--teal-dark); }
.btn-muted { color: var(--muted); background: #fff; }
.icon-btn { width: 44px; padding: 0; color: var(--ink); background: #fff; }
.icon-btn:hover, .today-btn:hover { border-color: var(--teal); color: var(--teal); }
.today-btn { padding: 0 15px; background: #fff; font-weight: 700; }

.flash {
    padding: 12px 14px;
    border: 1px solid #a9dfcd;
    border-radius: 8px;
    color: #125c51;
    background: #e7f8f2;
    font-weight: 700;
}
.flash.error { color: #9a3e32; border-color: #ffc1b5; background: #fff0ec; }
.flash.floating { margin-bottom: 16px; }

/* Login */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px;
    background: #fff9dc;
}
.login-shell {
    width: min(900px, 100%);
    min-height: 560px;
    display: grid;
    grid-template-columns: 1.1fr .9fr;
    overflow: hidden;
    border: 1px solid #e4deb9;
    border-radius: 8px;
    background: var(--paper);
    box-shadow: var(--shadow);
}
.login-copy {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 52px;
    overflow: hidden;
    background: var(--yellow);
}
.login-copy h1 { margin: 0 0 16px; font-size: 48px; line-height: 1.13; }
.login-copy > p:last-child { margin: 0; color: #516066; font-weight: 700; }
.login-panel { align-self: center; padding: 48px; }
.panel-heading { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.panel-heading h2 { margin: 0 0 4px; font-size: 25px; }
.panel-heading p { margin: 0; color: var(--muted); font-size: 14px; }
.mini-star { color: var(--coral); font-size: 34px; }
.form-stack { display: grid; gap: 18px; margin-top: 18px; }
.form-stack label, .note-field { display: grid; gap: 7px; }
.form-stack label span, .note-field span { font-size: 13px; font-weight: 800; }
input {
    width: 100%;
    min-height: 48px;
    padding: 0 14px;
    border: 1px solid #cbdadd;
    border-radius: 8px;
    color: var(--ink);
    background: #fff;
    outline: none;
}
input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(23, 124, 112, .12); }
.form-stack .btn { margin-top: 4px; }

/* Star character */
.mascot-wrap { position: relative; width: 190px; height: 165px; flex: 0 0 auto; }
.mascot {
    position: absolute;
    inset: 12px 22px 8px;
    background: var(--yellow);
    clip-path: polygon(50% 0%, 61% 34%, 97% 35%, 68% 56%, 79% 92%, 50% 71%, 20% 92%, 31% 56%, 3% 35%, 39% 34%);
    filter: drop-shadow(0 10px 0 rgba(255, 138, 114, .22));
    animation: float 3.4s ease-in-out infinite;
}
.mascot-large { width: 220px; height: 220px; inset: auto auto 280px 135px; opacity: .96; }
.login-copy .mascot { background: #fff4bd; }
.eye { position: absolute; top: 43%; width: 9px; height: 13px; border-radius: 50%; background: var(--ink); z-index: 1; }
.eye-left { left: 41%; }
.eye-right { right: 41%; }
.smile {
    position: absolute;
    left: 45%; top: 51%;
    width: 11%; height: 8%;
    border-bottom: 3px solid var(--ink);
    border-radius: 0 0 50% 50%;
    z-index: 1;
}
.orbit { position: absolute; color: var(--coral); font-size: 24px; animation: twinkle 2s ease-in-out infinite; }
.orbit-one { top: 2px; right: 12px; }
.orbit-two { left: 3px; bottom: 8px; color: var(--teal); animation-delay: .7s; }
@keyframes float { 50% { transform: translateY(-7px) rotate(2deg); } }
@keyframes twinkle { 50% { transform: scale(.72); opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .mascot, .orbit { animation: none; } }

/* App */
.app-header { position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); }
.header-inner { width: min(980px, calc(100% - 32px)); height: 70px; margin: auto; display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 900; }
.brand-star { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 8px; color: var(--ink); background: var(--yellow); }
.header-actions { display: flex; align-items: center; gap: 9px; }
.account { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 14px; font-weight: 700; }
.header-actions form { margin: 0; }
.app-shell { width: min(980px, calc(100% - 32px)); margin: 28px auto 64px; }

.settlement-hero {
    min-height: 250px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 28px;
    padding: 36px 48px;
    overflow: hidden;
    border: 1px solid #ead993;
    border-radius: 8px;
    background: #fff4bd;
}
.hero-copy { min-width: 0; }
.hero-topline { min-height: 28px; display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.status-pill { padding: 6px 10px; border-radius: 999px; color: #96502f; background: #ffe0bd; font-size: 12px; font-weight: 900; }
.status-pill.paid { color: #12685d; background: var(--mint); }
.countdown { color: var(--muted); font-size: 13px; font-weight: 700; }
.settlement-hero h1 { margin: 0 0 12px; font-size: 34px; line-height: 1.2; }
.settlement-hero h1 span { color: var(--teal-dark); font-size: 48px; }
.formula { margin: 0; color: #67747a; font-size: 14px; }

.metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    margin: 16px 0 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
}
.metrics > div { min-width: 0; padding: 22px 24px; border-right: 1px solid var(--line); }
.metrics > div:last-child { border-right: 0; }
.metrics span { display: block; margin-bottom: 9px; color: var(--muted); font-size: 13px; }
.metrics strong { font-size: 25px; }
.metrics small { color: var(--muted); font-size: 13px; font-weight: 600; }

.calendar-section { margin-top: 8px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 16px; }
.section-heading h2 { margin: 0; font-size: 27px; }
.cycle-nav { display: flex; gap: 8px; }
.legend { display: flex; gap: 18px; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.leave-dot { background: var(--coral); }
.today-dot { border: 2px solid var(--teal); background: #fff; }
.calendar { overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 12px 30px rgba(37, 78, 84, .07); }
.weekdays, .calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.weekdays { border-bottom: 1px solid var(--line); background: #fbfdfd; }
.weekdays span { padding: 13px 4px; color: var(--muted); font-size: 12px; text-align: center; }
.day {
    position: relative;
    min-width: 0;
    height: 104px;
    padding: 12px;
    border: 0;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    color: var(--ink);
    background: #fff;
    text-align: left;
    cursor: pointer;
}
.day:nth-child(7n) { border-right: 0; }
.day:hover:not(:disabled) { background: #f7fcfa; }
.day.outside { color: #b6c1c4; background: #f6f8f8; cursor: default; }
.day.is-leave { background: var(--coral-soft); }
.day.is-today { box-shadow: inset 0 0 0 2px var(--teal); }
.day-number { position: relative; z-index: 1; display: inline-grid; place-items: center; width: 28px; height: 28px; font-weight: 800; }
.day.is-leave .day-number { color: #fff; border-radius: 50%; background: var(--coral); }
.day small { color: var(--muted); font-size: 11px; }
.day-star { position: absolute; right: 11px; bottom: 24px; color: var(--coral); font-size: 24px; }
.day em { position: absolute; right: 10px; bottom: 8px; color: #a54a3e; font-size: 11px; font-style: normal; font-weight: 800; }

.settle-bar {
    margin-top: 22px;
    padding: 20px 22px;
    border: 1px solid var(--line);
    border-left: 5px solid var(--yellow);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    background: #fff;
}
.settle-bar > div { display: grid; gap: 5px; }
.settle-bar span { color: var(--muted); font-size: 12px; }
.settle-bar strong { font-size: 16px; }

/* Dialog */
dialog { padding: 0; border: 0; border-radius: 8px; color: var(--ink); background: #fff; box-shadow: 0 24px 80px rgba(20, 54, 59, .25); }
dialog::backdrop { background: rgba(24, 49, 58, .48); backdrop-filter: blur(3px); }
.day-dialog { width: min(440px, calc(100% - 28px)); }
.dialog-form { position: relative; display: grid; gap: 18px; padding: 30px; }
.dialog-form h2 { margin: -10px 0 2px; font-size: 27px; }
.dialog-close { position: absolute; right: 14px; top: 14px; }
.dialog-star { color: var(--yellow); font-size: 40px; line-height: 1; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { min-height: 54px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; display: flex; align-items: center; justify-content: center; gap: 7px; cursor: pointer; font-size: 14px; font-weight: 800; }
.segmented input:checked + span { border-color: var(--teal); color: var(--teal-dark); background: var(--mint); box-shadow: inset 0 0 0 1px var(--teal); }

@media (max-width: 720px) {
    .login-page { display: block; padding: 0; background: #fff; }
    .login-shell { min-height: 100vh; grid-template-columns: 1fr; border: 0; border-radius: 0; box-shadow: none; }
    .login-copy { min-height: 300px; padding: 32px 28px; }
    .login-copy h1 { font-size: 38px; }
    .mascot-large { width: 150px; height: 150px; inset: 18px 15px auto auto; }
    .login-panel { width: 100%; padding: 34px 28px 44px; }

    .header-inner, .app-shell { width: min(100% - 28px, 980px); }
    .header-inner { height: 64px; }
    .brand { font-size: 16px; }
    .brand-star { width: 36px; height: 36px; }
    .account { display: none; }
    .app-shell { margin-top: 14px; margin-bottom: 34px; }
    .settlement-hero { min-height: 246px; padding: 24px 22px; align-items: flex-start; }
    .mascot-wrap { width: 92px; height: 92px; margin: 10px -8px 0 0; }
    .mascot { inset: 5px; }
    .orbit { font-size: 17px; }
    .settlement-hero h1 { font-size: 24px; }
    .settlement-hero h1 span { display: block; margin-top: 4px; font-size: 38px; white-space: nowrap; }
    .formula { max-width: 220px; font-size: 12px; line-height: 1.6; }
    .hero-topline { align-items: flex-start; flex-direction: column; gap: 7px; margin-bottom: 14px; }
    .metrics { grid-template-columns: 1fr 1fr; margin-bottom: 34px; }
    .metrics > div { padding: 17px 18px; border-bottom: 1px solid var(--line); }
    .metrics > div:nth-child(2n) { border-right: 0; }
    .metrics > div:nth-last-child(-n+2) { border-bottom: 0; }
    .metrics strong { font-size: 22px; }
    .section-heading { align-items: center; }
    .section-heading h2 { font-size: 24px; }
    .day { height: 68px; padding: 6px 4px; text-align: center; }
    .day-number { width: 25px; height: 25px; font-size: 13px; }
    .day small { display: block; margin-top: 1px; }
    .day-star { right: 5px; bottom: 6px; font-size: 14px; }
    .day em { display: none; }
    .settle-bar { align-items: stretch; flex-direction: column; }
    .settle-bar .btn { width: 100%; }
}

@media (max-width: 370px) {
    .header-inner, .app-shell { width: calc(100% - 20px); }
    .settlement-hero { padding: 21px 17px; }
    .mascot-wrap { width: 72px; height: 76px; }
    .settlement-hero h1 span { font-size: 33px; }
    .cycle-nav { gap: 5px; }
    .today-btn { padding: 0 11px; }
    .day { height: 62px; }
}
