:root {
    --ink: #20353a;
    --muted: #66777b;
    --paper: #fffdf8;
    --sand: #f3ede1;
    --line: #ded6c8;
    --debit: #1d6f72;
    --credit: #a95735;
    --danger: #9d3d32;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: linear-gradient(135deg, #f4efe5, #eaf2ed);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
}

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

.container {
    width: min(1040px, calc(100% - 32px));
    margin: 0 auto;
    padding: 52px 0 76px;
}

header {
    margin-bottom: 28px;
}

.eyebrow {
    color: var(--debit);
    letter-spacing: .13em;
    font-size: .76rem;
    font-weight: 800;
    margin: 0 0 9px;
}

h1 {
    font-size: clamp(1.8rem, 4vw, 2.6rem);
    margin: 0;
    letter-spacing: .03em;
}

.lead {
    margin: 12px 0 0;
    color: var(--muted);
}

.entry-card, .saved-section {
    background: var(--paper);
    border: 1px solid rgba(119, 101, 67, .15);
    border-radius: 18px;
    box-shadow: 0 12px 36px rgba(61, 72, 63, .08);
    padding: 28px;
}

.saved-section {
    margin-top: 24px;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

h2 {
    font-size: 1.15rem;
    margin: 0;
}

.count {
    color: var(--muted);
    margin: 5px 0 0;
    font-size: .9rem;
}

.journal-grid {
    display: grid;
    grid-template-columns:1fr 1fr;
    gap: 20px;
    margin-top: 22px;
}

.side {
    border-radius: 12px;
    padding: 17px;
    background: #f9f8f3;
}

.side.debit {
    border-top: 4px solid var(--debit);
}

.side.credit {
    border-top: 4px solid var(--credit);
}

.side-title {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 14px;
}

.side-title span {
    font-weight: 800;
    font-size: 1.05rem;
}

.debit .side-title span {
    color: var(--debit);
}

.credit .side-title span {
    color: var(--credit);
}

small {
    color: var(--muted);
    font-size: .75rem;
}

.lines {
    display: grid;
    gap: 9px;
}

.line {
    display: grid;
    grid-template-columns:minmax(0, 1fr) 118px 30px;
    gap: 7px;
}

select, input, textarea {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 9px 10px;
    background: #fff;
    color: var(--ink);
}

input {
    text-align: right;
}

.entry-heading {
    display: block;
}

.entry-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 12px;
}

.entry-primary-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.remove-line {
    border: 0;
    border-radius: 7px;
    background: #ece7dc;
    color: #756d61;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
}

button {
    cursor: pointer;
}

.add-line, .text-button {
    border: 0;
    background: transparent;
    color: var(--debit);
    font-weight: 700;
    font-size: .88rem;
    padding: 11px 0 2px;
}

.credit .add-line {
    color: var(--credit);
}

.text-button {
    padding: 5px;
    color: var(--muted);
}

.balance-check {
    margin-top: 18px;
    text-align: center;
}

.balance-check label {
    color: var(--muted);
    font-size: .86rem;
    cursor: pointer;
}

.balance-check input {
    accent-color: var(--debit);
    vertical-align: middle;
}

.balance-message {
    min-height: 1.5em;
    text-align: center;
    color: var(--muted);
    margin: 9px 0 0;
    font-size: .92rem;
}

.balance-message.ok {
    color: var(--debit);
    font-weight: 700;
}

.balance-message.error {
    color: var(--danger);
    font-weight: 700;
}

.actions {
    display: flex;
    justify-content: center;
    margin-top: 8px;
}

.primary, .secondary, .danger {
    border: 0;
    color: white;
    border-radius: 8px;
    padding: 11px 21px;
    font-weight: 800;
}

.primary {
    background: var(--debit);
}

.primary:disabled {
    background: #98948b;
    color: #f6f4ef;
    cursor: not-allowed;
}

.secondary {
    border: 1px solid var(--debit);
    background: #fff;
    color: var(--debit);
}

.secondary:disabled {
    border-color: #d5d1c8;
    background: #e8e5dd;
    color: #98948b;
    cursor: not-allowed;
}

.active-frame {
    margin: 0;
    text-align: left;
    color: var(--muted);
    font-size: .86rem;
}

.danger {
    background: var(--danger);
    white-space: nowrap;
    font-size: .86rem;
}

.empty-state {
    border: 1px dashed var(--line);
    color: var(--muted);
    text-align: center;
    border-radius: 10px;
    padding: 26px;
    margin: 20px 0 0;
}

.saved-entries {
    display: grid;
    gap: 16px;
    margin-top: 20px;
}

.journal-frame {
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
}

.journal-frame.is-active {
    border: 2px solid var(--debit);
    box-shadow: 0 0 0 3px rgba(29, 111, 114, .12);
}

.journal-frame.is-active .frame-meta {
    background: #e6f1ee;
}

.frame-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 14px;
    background: #f6f2ea;
}

.frame-label {
    font-weight: 800;
}

.frame-count {
    margin-left: 10px;
    color: var(--muted);
    font-size: .82rem;
}

.frame-status {
    display: inline-block;
    margin-left: 10px;
    padding: 3px 7px;
    border-radius: 999px;
    background: var(--debit);
    color: #fff;
    font-size: .75rem;
    font-weight: 800;
}

.frame-entries {
    display: grid;
    gap: 12px;
    padding: 12px;
}

.journal-entry {
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.empty-frame {
    margin: 4px;
    color: var(--muted);
    text-align: center;
}

.entry-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 11px 14px;
    background: #f6f2ea;
    color: var(--muted);
    font-size: .82rem;
}

.delete-entry {
    border: 1px solid #dcb9b4;
    background: #fff8f6;
    color: var(--danger);
    padding: 5px 9px;
    border-radius: 6px;
    font-weight: 700;
}

.delete-journal {
    border: 1px solid #dcb9b4;
    background: #fff8f6;
    color: var(--danger);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: .78rem;
    font-weight: 700;
}

table {
    border-collapse: collapse;
    width: 100%;
}

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

th {
    background: #fbfaf6;
    font-size: .84rem;
}

th:nth-child(2), th:nth-child(4), td.amount-cell {
    text-align: right;
}

.debit-head {
    color: var(--debit);
}

.credit-head {
    color: var(--credit);
}

.amount-cell {
    font-variant-numeric: tabular-nums;
}

figure {
    border: thin silver solid;
    display: flex;
    flex-flow: column;
    padding: 5px;
    max-width: 205px;
    margin: auto;
}

figcaption {
    background-color: #f4efe5;
    color: #000;
    font: italic smaller sans-serif;
    padding: 2px;
    text-align: center;
}

.amzn {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    justify-content: center;
    align-items: center;
}

#amzn2 {
    width: min(1040px, calc(100% - 32px));
    margin: 0 auto;
}

.amzn > div {
    flex: 0 1 205px;
    min-width: 0;
}

.amzn figure {
    box-sizing: border-box;
    width: 100%;
}

.amzn img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
}

@media (min-width: 701px) {
    .amzn > div {
        flex-basis: calc((100% - 20px) / 5);
    }
}

@media (max-width: 700px) {
    .container {
        width: min(100% - 20px, 1040px);
        padding-top: 28px;
    }

    #amzn2 {
        width: min(100% - 20px, 1040px);
    }

    .amzn > div {
        flex-basis: calc((100% - 5px) / 2);
    }

    .entry-card, .saved-section {
        padding: 18px;
    }

    .journal-grid {
        grid-template-columns:1fr;
    }

    .section-heading {
        align-items: flex-start;
    }

    .entry-heading {
        flex-wrap: wrap;
    }

    .line {
        grid-template-columns:minmax(0, 1fr) 105px 30px;
    }

    th, td {
        padding: 9px;
        font-size: .9rem;
    }
}
