:root {
    --brand-green: #25d366;
    --brand-green-dark: #128c7e;
    --header-bg: #075e54;
    --screen-bg: #f0f2f5;
    --header-row-bg: #e8eaed;
    --panel-bg: #ffffff;
    --divider: #dadce0;
    --hint: #9aa0a6;
    --text: #212121;
    --muted: #5f6368;
    --digit-bg: #eceff1;
    --cm-bg: #eca235;
    --mp-bg: #7cb342;
    --cp-bg: #29b6f6;
    --br-bg: #fdd835;
    --sp-bg: #ff8a65;
    --dp-bg: #ff7043;
    --star-bg: #00acc1;
    --dash-bg: #546e7a;
    --prefix: #26c6da;
    --suffix: #4fb816;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--screen-bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

body {
    min-width: 320px;
}

button,
input,
select {
    font: inherit;
}

.app-shell {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    background: var(--screen-bg);
}

.topbar {
    position: relative;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 48px;
    padding: calc(env(safe-area-inset-top, 0px) + 6px) 10px 6px;
    background: var(--header-bg);
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
}

.topbar h1 {
    flex: 1 1 auto;
    min-width: 90px;
    margin: 0;
    font-size: 18px;
    line-height: 1.1;
    letter-spacing: 0;
}

.font-select,
.text-action,
.settings-button {
    flex: 0 0 auto;
    min-height: 28px;
    border: 0;
    border-radius: 6px;
    background: rgba(255, 255, 255, .14);
    color: #fff;
    font-weight: 700;
}

.font-select {
    width: 42px;
    padding: 3px;
}

.font-select option {
    color: #212121;
}

.text-action {
    padding: 4px 9px;
    white-space: nowrap;
}

.text-action.danger {
    color: #ff6b6b;
}

.expand-toggle {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    white-space: nowrap;
}

.expand-toggle input {
    width: 16px;
    height: 16px;
    accent-color: #fff;
}

.settings-button {
    width: 32px;
    font-size: 18px;
}

.settings-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 8px;
    width: 220px;
    padding: 4px;
    border-radius: 4px;
    background: #fff;
    color: #212121;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .24);
}

.settings-panel strong {
    display: block;
    padding: 10px 12px 7px;
    border-bottom: 1px solid #e0e0e0;
    color: var(--header-bg);
    font-size: 13px;
    letter-spacing: 0;
    text-transform: uppercase;
}

.settings-panel label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 48px;
    padding: 0 10px 0 12px;
    border-bottom: 1px solid #f0f0f0;
}

.settings-panel input {
    width: 18px;
    height: 18px;
    accent-color: var(--brand-green-dark);
}

.list-area {
    display: flex;
    flex: 1 1 auto;
    min-height: 80px;
    overflow: hidden;
    flex-direction: column;
}

.list-header,
.entry-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(78px, 1fr) 44px;
}

.list-header {
    flex: 0 0 30px;
    background: var(--header-row-bg);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.list-header span,
.entry-row span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    border-right: 1px solid var(--divider);
}

.entry-list {
    flex: 1 1 auto;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.entry-row {
    min-height: 40px;
    border-bottom: 1px solid var(--divider);
    background: #fff;
}

.entry-row .num,
.entry-row .amt {
    padding: 4px 6px;
    overflow-wrap: anywhere;
    text-align: center;
    font-family: Consolas, "Courier New", monospace;
}

.entry-row .amt {
    color: var(--brand-green-dark);
    font-weight: 700;
}

.delete-row {
    display: grid;
    place-items: center;
    width: 44px;
    border: 0;
    background: transparent;
    color: #e53935;
    font-size: 18px;
    font-weight: 700;
}

.empty-list {
    display: grid;
    height: 100%;
    place-items: center;
    color: #7a8088;
    font-size: 13px;
}

.totals-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 36px;
    padding: 0 10px;
    background: #1c1c2e;
    color: #b0b0c8;
    font-size: 12px;
}

.totals-row strong {
    color: #ffd700;
}

.bottom-panel {
    flex: 0 0 auto;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--panel-bg);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, .16);
}

.input-row {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(80px, 1fr);
    gap: 4px;
    padding: 6px 8px 4px;
}

.input-row input {
    width: 100%;
    height: 38px;
    min-width: 0;
    border: 1px solid #cfd8dc;
    border-radius: 6px;
    background: #fff;
    color: #000;
    padding: 8px;
    font-size: 15px;
}

.input-row input::placeholder {
    color: var(--hint);
}

.keyboard {
    padding: 0 4px;
}

.key-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 3px;
    height: 40px;
    margin-top: 3px;
}

.key {
    width: 100%;
    min-width: 0;
    min-height: 40px;
    border: 0;
    border-radius: 6px;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    overflow-wrap: anywhere;
    line-height: 1.05;
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .18);
    touch-action: manipulation;
}

.key:active,
.enter-button:active,
.share-button:active {
    transform: translateY(1px);
    filter: brightness(.96);
}

.key-digit {
    background: var(--digit-bg);
    color: var(--text);
    font-size: 20px;
}

.key-cm { background: var(--cm-bg); }
.key-mp { background: var(--mp-bg); }
.key-cp { background: var(--cp-bg); }
.key-br { background: var(--br-bg); color: #111; }
.key-sp { background: var(--sp-bg); }
.key-dp { background: var(--dp-bg); }
.key-star { background: var(--star-bg); }
.key-dash { background: var(--dash-bg); color: #fff; }

.key.prefix-active,
.key.pending-active {
    background: var(--prefix);
}

.key.suffix-active {
    background: var(--suffix);
}

.action-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    height: 52px;
    padding: 4px 6px 6px;
}

.share-button,
.enter-button {
    border: 0;
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
}

.share-button {
    background: var(--brand-green);
}

.enter-button {
    background: linear-gradient(#128c7e, #075e54);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
    z-index: 50;
    max-width: min(92vw, 420px);
    padding: 9px 12px;
    border-radius: 18px;
    background: rgba(33, 33, 33, .94);
    color: #fff;
    opacity: 0;
    transform: translate(-50%, 12px);
    transition: opacity .18s ease, transform .18s ease;
    pointer-events: none;
    text-align: center;
    font-size: 13px;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

[hidden] {
    display: none !important;
}

@media (max-width: 430px) {
    .topbar {
        padding-left: 8px;
        padding-right: 6px;
        gap: 4px;
    }

    .topbar h1 {
        font-size: 16px;
    }

    .text-action {
        padding-left: 6px;
        padding-right: 6px;
        font-size: 12px;
    }

    .expand-toggle {
        font-size: 10px;
    }

    .key {
        font-size: 12px;
    }
}

@media (min-width: 760px) {
    body {
        display: grid;
        place-items: center;
        background: #dfe5e8;
    }

    .app-shell {
        width: min(430px, 100vw);
        min-height: min(920px, 100dvh);
        max-height: 100dvh;
        border-left: 1px solid rgba(0, 0, 0, .12);
        border-right: 1px solid rgba(0, 0, 0, .12);
    }
}
