:root {
    --bg: #080705;
    --surface: rgba(24, 20, 13, .94);
    --surface-strong: #1e180f;
    --ink: #fff6df;
    --muted: #c8b98d;
    --line: rgba(214, 170, 82, .34);
    --primary: #d6aa52;
    --primary-dark: #b98222;
    --gold: #f0cc78;
    --danger: #d65b4a;
    --soft-green: rgba(35, 122, 86, .18);
    --soft-gold: rgba(214, 170, 82, .18);
    --soft-red: rgba(214, 91, 74, .16);
    --shadow: 0 18px 42px rgba(0, 0, 0, .46);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    overflow-x: hidden;
    background:
        linear-gradient(135deg, rgba(214, 170, 82, .10) 0 1px, transparent 1px 24px),
        linear-gradient(45deg, rgba(214, 170, 82, .06) 0 1px, transparent 1px 24px),
        var(--bg);
    color: var(--ink);
    font-family: "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
    line-height: 1.6;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: .22;
    background-image:
        repeating-linear-gradient(90deg, transparent 0 30px, rgba(240, 204, 120, .12) 30px 31px, transparent 31px 62px),
        repeating-linear-gradient(0deg, transparent 0 30px, rgba(240, 204, 120, .08) 30px 31px, transparent 31px 62px);
    mask-image: linear-gradient(to bottom, #000, rgba(0, 0, 0, .7), transparent 92%);
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px clamp(16px, 4vw, 40px);
    background: rgba(10, 8, 5, .92);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .34);
    backdrop-filter: blur(14px);
}

.brand {
    color: var(--gold);
    font-weight: 900;
    white-space: nowrap;
    text-shadow: 0 1px 18px rgba(240, 204, 120, .18);
}

.topbar nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px 16px;
    font-size: 14px;
}

.topbar nav a {
    color: #f2d48b;
}

.page-shell {
    width: min(1180px, calc(100% - 28px));
    margin: 0 auto;
    padding: 28px 0 56px;
}

.toolbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

h1,
h2 {
    margin: 0;
    color: #fff2c2;
    line-height: 1.25;
    letter-spacing: 0;
}

h1 {
    font-size: clamp(25px, 3vw, 38px);
}

h2 {
    font-size: 20px;
}

p {
    margin: 8px 0 0;
    color: #d8c99b;
}

.panel {
    margin-bottom: 18px;
    padding: clamp(16px, 2.6vw, 26px);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.panel,
.pdf-heading,
.auth-panel {
    background-image:
        linear-gradient(135deg, rgba(240, 204, 120, .08), transparent 34%),
        linear-gradient(45deg, rgba(255, 255, 255, .035), transparent 42%);
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

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

.form-grid.filters {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

label {
    display: grid;
    gap: 7px;
    color: #ead59a;
    font-size: 14px;
}

label small {
    color: #c8b98d;
    line-height: 1.5;
}

label.wide {
    grid-column: 1 / -1;
}

.check-row {
    display: flex;
    grid-template-columns: none;
    align-items: center;
    gap: 10px;
    min-height: 44px;
}

.check-row input {
    width: 18px;
    min-height: 18px;
}

input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: rgba(6, 5, 3, .72);
    color: var(--ink);
    font: inherit;
}

input::placeholder,
textarea::placeholder {
    color: rgba(255, 246, 223, .44);
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: 3px solid rgba(214, 170, 82, .2);
    border-color: var(--primary);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.table-actions {
    flex-wrap: nowrap;
}

.table-actions form {
    margin: 0;
}

.form-panel .actions,
.filter-panel .actions {
    margin-top: 18px;
}

button,
.button {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    padding: 9px 16px;
    border: 1px solid var(--primary);
    border-radius: 7px;
    background: linear-gradient(180deg, #f0cc78, #b98222);
    color: #130f08;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
}

button:hover,
.button:hover {
    background: linear-gradient(180deg, #ffd98a, #c99028);
    text-decoration: none;
}

.secondary {
    background: rgba(255, 246, 223, .05);
    color: #f0cc78;
}

.secondary:hover {
    background: rgba(240, 204, 120, .14);
    color: #ffe3a3;
}

.small {
    min-height: 34px;
    padding: 6px 12px;
    font-size: 14px;
}

.danger {
    border-color: var(--danger);
    background: var(--danger);
}

.danger:hover {
    background: #8f1d15;
}

.danger-zone {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-color: rgba(214, 91, 74, .42);
}

.pdf-content {
    background: transparent;
}

.pdf-heading {
    margin-bottom: 18px;
    padding: clamp(16px, 2.6vw, 26px);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.pdf-heading h1 {
    font-size: 28px;
}

.pdf-export-clone {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 99999;
    width: 980px;
    max-width: 980px;
    padding: 18px;
    background: #080705;
    color: var(--ink);
    pointer-events: none;
}

body.pdf-exporting > *:not(.pdf-export-clone) {
    filter: blur(1px);
}

.pdf-export-clone .panel,
.pdf-export-clone .pdf-heading {
    box-shadow: none;
    break-inside: avoid;
    page-break-inside: avoid;
}

.pdf-export-clone .topbar,
.pdf-export-clone .toolbar,
.pdf-export-clone .danger-zone {
    display: none !important;
}

.pdf-export-clone .chart-wrap {
    overflow: visible;
}

.pdf-export-clone .aspect-chart {
    width: 100%;
    min-width: 0;
}

button:disabled,
.button[aria-disabled="true"] {
    cursor: wait;
    opacity: .65;
}

.flash {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 7px;
    border: 1px solid var(--line);
    background: var(--soft-green);
    color: #b9f0d5;
}

.flash.error {
    background: var(--soft-red);
    color: var(--danger);
    border-color: rgba(214, 91, 74, .42);
}

.notice {
    padding: 11px 13px;
    border-radius: 7px;
    background: var(--soft-gold);
    color: #f2d48b;
}

.info-grid > div,
.classification > div,
.stat-box {
    min-width: 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: rgba(8, 7, 5, .5);
}

.info-grid span,
.classification span,
.stat-box span {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.info-grid strong,
.classification strong,
.stat-box strong {
    display: block;
    margin-top: 4px;
    overflow-wrap: anywhere;
    font-size: 18px;
}

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

.stat-box strong {
    font-size: 36px;
}

.rows-table {
    display: grid;
    gap: 12px;
}

.rows-table > div {
    display: grid;
    grid-template-columns: 82px 1fr;
    align-items: center;
    gap: 12px;
}

.number-row {
    display: grid;
    grid-template-columns: repeat(12, minmax(34px, 1fr));
    gap: 6px;
}

.number-row span {
    display: inline-flex;
    min-width: 0;
    min-height: 34px;
    align-items: center;
    justify-content: center;
    padding: 0 2px;
    border-radius: 7px;
    background: rgba(240, 204, 120, .1);
    border: 1px solid rgba(240, 204, 120, .16);
    color: var(--ink);
    font-size: 16px;
    font-weight: 800;
}

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

.chart-wrap {
    width: 100%;
    margin-bottom: 18px;
    overflow-x: hidden;
    padding: 2px 2px 8px;
}

.aspect-chart {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: auto;
}

.chart-shell {
    fill: url(#chartFrameGradient);
    filter: url(#chartSoftShadow);
}

.chart-bg {
    fill: #110e09;
    stroke: #d6aa52;
    stroke-width: 2;
}

.chart-band {
    opacity: .64;
}

.chart-band.heaven {
    fill: rgba(45, 150, 105, .36);
}

.chart-band.human {
    fill: rgba(214, 170, 82, .32);
}

.chart-band.hell {
    fill: rgba(214, 91, 74, .26);
}

.chart-grid {
    stroke: rgba(255, 246, 223, .18);
    stroke-width: 1;
    vector-effect: non-scaling-stroke;
}

.chart-axis {
    stroke: #f0cc78;
    stroke-width: 2.2;
    vector-effect: non-scaling-stroke;
}

.chart-axis.soft {
    stroke: rgba(240, 204, 120, .56);
    stroke-width: 1.6;
}

.chart-band-line {
    stroke: rgba(240, 204, 120, .62);
    stroke-width: 1.8;
    vector-effect: non-scaling-stroke;
}

.chart-line-shadow {
    fill: none;
    stroke: rgba(0, 0, 0, .6);
    stroke-width: 8;
    stroke-linejoin: round;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
}

.chart-line {
    fill: none;
    stroke: url(#chartLineGradient);
    stroke-width: 4.2;
    stroke-linejoin: round;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
}

.chart-point-glow {
    opacity: .22;
}

.chart-point-glow.level-天堂 {
    fill: #29a36f;
}

.chart-point-glow.level-人間 {
    fill: #b7791f;
}

.chart-point-glow.level-地獄 {
    fill: #b42318;
}

.chart-point {
    stroke: #fff6df;
    stroke-width: 3.2;
    vector-effect: non-scaling-stroke;
}

.chart-point.level-天堂 {
    fill: #29a36f;
}

.chart-point.level-人間 {
    fill: #d6aa52;
}

.chart-point.level-地獄 {
    fill: #d65b4a;
}

.chart-y-label,
.chart-x-label,
.chart-zone,
.chart-point-label {
    fill: #fff2c2;
    font-family: "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
}

.chart-y-label {
    font-size: 17px;
    font-weight: 800;
    text-anchor: middle;
}

.chart-x-label {
    font-size: 18px;
    font-weight: 700;
    text-anchor: middle;
}

.chart-zone {
    font-size: 24px;
    font-weight: 800;
}

.chart-zone.heaven {
    fill: #65d49f;
}

.chart-zone.human {
    fill: #9a6418;
}

.chart-zone.hell {
    fill: #9f2f24;
}

.chart-point-label {
    font-size: 16px;
    font-weight: 900;
    text-anchor: middle;
    paint-order: stroke;
    stroke: #110e09;
    stroke-width: 5px;
    stroke-linejoin: round;
}

.aspect-card {
    min-width: 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(8, 7, 5, .48);
}

.aspect-card > div {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.aspect-card span {
    color: #efdba3;
    font-weight: 700;
}

.aspect-card strong {
    color: #fff2c2;
    font-size: 24px;
}

.aspect-card p,
.animal-grid p {
    color: #f6e7bf;
}

.aspect-card b {
    display: inline-flex;
    margin-top: 8px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 13px;
}

.level-天堂 b {
    background: var(--soft-green);
    color: #aaf0cf;
}

.level-人間 b {
    background: var(--soft-gold);
    color: #f0cc78;
}

.level-地獄 b {
    background: var(--soft-red);
    color: var(--danger);
}

.classification,
.animal-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.animal-grid article {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(8, 7, 5, .48);
}

.animal-grid span,
.animal-grid small {
    display: block;
    color: #d8c99b;
}

.animal-grid strong {
    display: block;
    margin: 4px 0;
    color: var(--primary);
    font-size: 28px;
}

.reading-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    margin: 0;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid rgba(240, 204, 120, .18);
    background: rgba(5, 4, 3, .72);
    color: #fff6df;
    font: 15px/1.75 "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    min-width: 820px;
    border-collapse: collapse;
}

th,
td {
    padding: 11px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: #efdba3;
    font-size: 13px;
    font-weight: 700;
}

td {
    color: #f6e7bf;
}

tbody tr:hover {
    background: rgba(240, 204, 120, .06);
}

.auth-wrap {
    display: grid;
    min-height: 62vh;
    place-items: center;
}

.auth-panel {
    width: min(420px, 100%);
    display: grid;
    gap: 16px;
}

@media (max-width: 920px) {
    .toolbar,
    .danger-zone {
        align-items: stretch;
        flex-direction: column;
    }

    .form-grid,
    .form-grid.filters,
    .info-grid,
    .stats-grid,
    .aspect-grid,
    .classification,
    .animal-grid {
        grid-template-columns: 1fr;
    }

    .number-row {
        grid-template-columns: repeat(12, minmax(0, 1fr));
        gap: 5px;
    }
}

@media (max-width: 560px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar nav {
        justify-content: flex-start;
    }

    .page-shell {
        width: min(100% - 20px, 1180px);
        padding-top: 18px;
    }

    .panel {
        padding: 14px;
    }

    .chart-wrap {
        margin-left: -6px;
        margin-right: -6px;
        padding-left: 0;
        padding-right: 0;
    }

    .rows-table > div {
        grid-template-columns: 1fr;
    }

    .number-row {
        grid-template-columns: repeat(12, minmax(0, 1fr));
        gap: 4px;
    }

    .number-row span {
        min-height: 30px;
        border-radius: 6px;
        font-size: 14px;
    }

    button,
    .button {
        width: 100%;
    }
}

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

    .topbar,
    .no-print,
    .section-title button {
        display: none !important;
    }

    .page-shell {
        width: 100%;
        padding: 0;
    }

    .panel {
        break-inside: avoid;
        box-shadow: none;
    }

    .chart-wrap {
        overflow: visible;
    }

    .aspect-chart {
        min-width: 0;
    }

    .chart-shell {
        filter: none;
    }

    .chart-point-glow,
    .chart-line-shadow {
        display: none;
    }
}
