/* The phone page and the pairing page (templates phone.html, phone_pair.html).
   Made for a phone held in one hand, with gloves on: big targets, big text. */

:root {
    color-scheme: light dark;
    /* The same tokens as the notebook (base.css), copied: this page loads no other style file */
    --ph-bg: #F6F3EC;
    --ph-surface: #FCFAF5;
    --ph-text: #27241F;
    --ph-muted: #5F584E;
    --ph-border: #CDC4B4;
    --ph-primary: #2C5E54;
    --ph-primary-text: #FFFFFF;
    --ph-secondary-bg: #E3ECE7;
    --ph-secondary-text: #2C5E54;
    --ph-danger: #B23B33;
    --ph-ok: #3D7A4F;
    --ph-tab-on: #FCFAF5;
    --ph-protocol-paper: #F1F3EA;
    --ph-protocol-rule: #2C5E54;
    --ph-protocol-numeral: #2C5E54;
    --ph-num-border: #CDC4B4;
    --ph-changed-bg: #F6EBD2;
    --ph-changed-text: #5C3F08;
    --ph-alarm: #B23B33;
    --ph-clay: #B5643F;
    --ph-sunk: #EEE9DF;
    --ph-font: 'DM Sans', system-ui, -apple-system, sans-serif;
    --ph-serif: 'Newsreader', Georgia, serif;
}
@media (prefers-color-scheme: dark) {
    :root {
        --ph-bg: #1B1916;
        --ph-surface: #25221E;
        --ph-text: #ECE5D9;
        --ph-muted: #B3A99A;
        --ph-border: #4A433A;
        --ph-primary: #3F7D6E;
        --ph-primary-text: #FFFFFF;
        --ph-secondary-bg: #1F2D29;
        --ph-secondary-text: #8EC4B3;
        --ph-danger: #E3796D;
        --ph-ok: #82C495;
        --ph-tab-on: #36312B;
        --ph-protocol-paper: #20241F;
        --ph-protocol-rule: #4F8D7D;
        --ph-protocol-numeral: #8EC4B3;
        --ph-num-border: #5E564B;
        --ph-changed-bg: #33291A;
        --ph-changed-text: #F1D49A;
        --ph-alarm: #9E3A30;
        --ph-clay: #DE9A78;
        --ph-sunk: #2E2A25;
    }
}
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

.phone-body {
    margin: 0;
    min-height: 100vh;
    background: var(--ph-bg);
    color: var(--ph-text);
    font-family: var(--ph-font);
    font-size: 18px;
    line-height: 1.4;
    overflow-x: hidden;
}

.phone-main {
    max-width: 480px;
    margin: 0 auto;
    padding: max(20px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

[hidden] { display: none !important; }

/* ── Header ── */
.phone-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}
.phone-logo { display: block; flex: none; }
.phone-logo img { display: block; }
.phone-who { min-width: 0; }
.phone-who-label { font-size: 15px; color: var(--ph-muted); }
.phone-who-name {
    font-family: var(--ph-serif);
    font-size: 28px;
    font-weight: 500;
    letter-spacing: -0.3px;
    line-height: 1.15;
    overflow-wrap: anywhere;
}

/* ── Buttons ── */
.phone-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    min-height: 56px;
    padding: 12px 18px;
    border: none;
    border-radius: 10px;
    font: inherit;
    font-size: 20px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.15s ease, filter 0.15s ease, background 0.15s ease;
}
.phone-btn:active { transform: scale(0.98); filter: brightness(0.95); }
.phone-btn:focus-visible { outline: 3px solid var(--ph-primary); outline-offset: 3px; }
.phone-btn-primary { background: var(--ph-primary); color: var(--ph-primary-text); }
.phone-btn-secondary {
    background: var(--ph-secondary-bg);
    color: var(--ph-secondary-text);
    margin-top: 12px;
}
.phone-camera { min-height: 128px; font-size: 22px; flex-direction: column; gap: 8px; border-radius: 16px; }
.phone-btn[aria-disabled="true"], .phone-btn:disabled { filter: grayscale(0.6) opacity(0.6); cursor: default; }

.phone-file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}
.phone-file-input:focus-visible + .phone-btn,
.phone-btn:has(+ .phone-file-input:focus-visible),
#phone-app:has(#phone-camera-input:focus-visible) #phone-camera-btn,
#phone-app:has(#phone-library-input:focus-visible) #phone-library-btn { outline: 3px solid var(--ph-primary); outline-offset: 3px; }

/* ── Note ── */
.phone-note { margin-top: 24px; }
.phone-note-label { display: block; font-family: var(--ph-serif); font-size: 20px; font-weight: 500; margin-bottom: 8px; color: var(--ph-text); }
.phone-note-row { display: flex; gap: 8px; align-items: stretch; }
.phone-note textarea {
    flex: 1;
    min-width: 0;
    min-height: 56px;
    padding: 12px;
    border: 1px solid var(--ph-border);
    border-radius: 10px;
    background: var(--ph-surface);
    color: var(--ph-text);
    font: inherit;
    font-size: 18px;
    resize: none;
}
.phone-note textarea:focus { outline: none; border-color: var(--ph-primary); }
.phone-btn-send {
    width: auto;
    min-width: 84px;
    background: var(--ph-primary);
    color: var(--ph-primary-text);
    font-size: 18px;
}

/* ── "Keep Wildtyper one tap away": the home screen hint, shown once ── */
.phone-home-hint {
    margin-top: 28px;
    padding: 16px 16px 14px;
    border: 1px solid var(--ph-border);
    border-radius: 16px;
    background: var(--ph-surface);
}
.phone-home-hint[hidden] { display: none; }
.phone-home-hint-title { font-family: var(--ph-serif); font-size: 20px; font-weight: 500; color: var(--ph-text); margin: 0 0 6px; }
.phone-home-hint-text { margin: 0 0 8px; color: var(--ph-muted); }
.phone-home-hint-steps { margin: 0 0 14px; padding-left: 22px; color: var(--ph-text); }
.phone-home-hint-steps li { margin: 6px 0; }
.phone-home-hint-steps[hidden], .phone-home-hint-by-hand[hidden] { display: none; }
.phone-home-hint-by-hand { margin: 14px 0 4px; color: var(--ph-muted); }
#phone-home-hint-install { margin: 6px 0 2px; }
#phone-home-hint-install[hidden] { display: none; }
/* The picture of the browser's button a step talks about, drawn like a key */
.phone-home-hint-glyph {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    margin-right: 8px;
    vertical-align: -7px;
    border: 1px solid var(--ph-border);
    border-radius: 7px;
    background: var(--ph-bg);
    color: var(--ph-text);
}
/* After "Got it": one quiet line that brings the hint back */
.phone-home-hint-again {
    display: block;
    width: 100%;
    min-height: 48px;
    margin-top: 20px;
    padding: 8px;
    border: none;
    background: none;
    font: inherit;
    font-size: 16px;
    color: var(--ph-secondary-text);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}
.phone-home-hint-again[hidden] { display: none; }

/* ── What was sent ── */
.phone-sent { margin-top: 28px; }
.phone-sent-title { font-family: var(--ph-serif); font-size: 20px; font-weight: 500; color: var(--ph-text); margin: 0 0 8px; }
.phone-sent-list { list-style: none; margin: 0; padding: 0; }
.phone-sent-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 64px;
    padding: 8px 10px;
    margin-bottom: 8px;
    border: 1.5px solid var(--ph-border);
    border-radius: 12px;
    background: var(--ph-surface);
}
.phone-sent-item[data-state="failed"] { border-color: var(--ph-danger); cursor: pointer; }
.phone-sent-thumb {
    flex: none;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--ph-border);
}
.phone-sent-note-icon {
    flex: none;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ph-secondary-bg);
    color: var(--ph-secondary-text);
}
.phone-sent-text { flex: 1; min-width: 0; }
.phone-sent-name { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.phone-sent-state { font-size: 15px; color: var(--ph-muted); }
.phone-sent-item[data-state="sent"] .phone-sent-state { color: var(--ph-ok); font-weight: 600; }
.phone-sent-item[data-state="failed"] .phone-sent-state { color: var(--ph-danger); font-weight: 600; }

/* ── Disconnect ── */
.phone-link-btn {
    display: block;
    margin: 32px auto 0;
    min-height: 48px;
    padding: 10px 16px;
    border: none;
    background: none;
    color: var(--ph-muted);
    font: inherit;
    font-size: 17px;
    text-decoration: underline;
    cursor: pointer;
}

/* ── Pairing and "not connected" ── */
.phone-pair { text-align: center; padding-top: 24px; }
.phone-pair .phone-logo { margin: 0 auto 16px; width: max-content; }
.phone-title { font-family: var(--ph-serif); font-size: 28px; font-weight: 500; letter-spacing: -0.3px; margin: 0 0 8px; }
.phone-pair-name { font-family: var(--ph-serif); font-size: 30px; font-weight: 500; margin: 0 0 16px; overflow-wrap: anywhere; }
.phone-pair-name:has(+ .phone-pair-email) { margin-bottom: 4px; }
.phone-pair-email { font-size: 18px; color: var(--ph-muted); margin: 0 0 16px; overflow-wrap: anywhere; }
.phone-text { color: var(--ph-muted); margin: 0 0 24px; }
.phone-hint { color: var(--ph-muted); font-size: 16px; margin-top: 16px; }
.phone-pair-form { margin: 0; }

/* ── Waiting for Allow on the computer: the number both screens show ── */
.phone-number {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    width: max-content;
    min-width: 200px;
    margin: 0 auto;
    padding: 14px 32px 18px;
    background: var(--ph-surface);
    border: 1px solid var(--ph-border);
    border-radius: 16px;
}
.phone-number-label { font-size: 15px; color: var(--ph-muted); }
.phone-number-value {
    font-family: var(--ph-serif);
    font-size: 64px;
    font-weight: 500;
    line-height: 1.05;
    letter-spacing: 2px;
    color: var(--ph-text);
    font-variant-numeric: tabular-nums;
}
.phone-waiting-hint { margin-top: 24px; }
.phone-waiting-dot {
    display: inline-block;
    vertical-align: middle;
    margin: 0 10px 2px 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ph-primary);
    animation: phone-waiting-pulse 1.6s ease-in-out infinite;
}
@keyframes phone-waiting-pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .phone-waiting-dot { animation: none; } }

/* ── The two parts: Camera, and From your notebook ── */
.phone-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    margin-bottom: 20px;
    border-radius: 16px;
    background: var(--ph-secondary-bg);
}
.phone-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 52px;
    padding: 8px 10px;
    border: none;
    border-radius: 12px;
    background: transparent;
    color: var(--ph-secondary-text);
    font: inherit;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.phone-tab[aria-selected="true"] {
    background: var(--ph-tab-on);
    color: var(--ph-text);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.phone-tab:focus-visible { outline: 3px solid var(--ph-primary); outline-offset: 2px; }
.phone-tab-count {
    min-width: 26px;
    height: 26px;
    padding: 0 7px;
    border-radius: 13px;
    background: var(--ph-primary);
    color: var(--ph-primary-text);
    font-size: 15px;
    line-height: 26px;
    text-align: center;
}

/* ── From your notebook ── */
.phone-inbox { list-style: none; margin: 0; padding: 0; }
.phone-inbox-empty { color: var(--ph-muted); margin: 8px 4px 0; }
.phone-inbox-item {
    margin-bottom: 16px;
    padding: 14px 14px 16px;
    border: 1px solid var(--ph-border);
    border-radius: 16px;
    background: var(--ph-surface);
    box-shadow: 0 1px 2px rgba(39, 36, 31, 0.05), 0 1px 4px rgba(39, 36, 31, 0.05);
}
.phone-inbox-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.phone-inbox-untitled .phone-inbox-head { align-items: center; }
.phone-inbox-words { flex: 1; min-width: 0; }
.phone-inbox-kind {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--ph-muted);
}
.phone-inbox-title { margin: 2px 0 0; font-family: var(--ph-serif); font-size: 24px; font-weight: 500; line-height: 1.2; letter-spacing: -0.2px; overflow-wrap: anywhere; }
.phone-inbox-remove {
    flex: none;
    min-width: 48px;
    min-height: 48px;
    padding: 8px 14px;
    border: 1.5px solid var(--ph-border);
    border-radius: 12px;
    background: transparent;
    color: var(--ph-muted);
    font: inherit;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}
.phone-inbox-remove:active { background: var(--ph-bg); }
.phone-inbox-remove:focus-visible { outline: 3px solid var(--ph-primary); outline-offset: 2px; }
.phone-inbox-remove:disabled { opacity: 0.5; }
.phone-muted { color: var(--ph-muted); font-size: 16px; margin: 8px 0 0; }

/* A note: formatted text, large */
.phone-note-html { font-size: 20px; line-height: 1.5; overflow-wrap: anywhere; }
.phone-note-html > :first-child { margin-top: 0; }
.phone-note-html > :last-child { margin-bottom: 0; }
.phone-note-html a { color: var(--ph-secondary-text); }
.phone-note-html table { border-collapse: collapse; display: block; overflow-x: auto; }
.phone-note-html td, .phone-note-html th { border: 1px solid var(--ph-border); padding: 4px 8px; }

/* A protocol: numbered steps, one big number each */
.phone-steps { list-style: none; counter-reset: step; margin: 0; padding: 0; }
.phone-steps li {
    counter-increment: step;
    position: relative;
    padding: 12px 0 12px 52px;
    min-height: 40px;
    font-size: 20px;
    line-height: 1.45;
    border-top: 1px solid var(--ph-border);
}
.phone-steps li:first-child { border-top: none; }
.phone-steps li::before {
    content: counter(step);
    position: absolute;
    left: 0;
    top: 10px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--ph-secondary-bg);
    color: var(--ph-secondary-text);
    font-weight: 700;
    font-size: 19px;
    line-height: 38px;
    text-align: center;
}

/* A protocol carries the notebook's protocol signature: protocol paper, a green margin
   rule, the flask mark and "Protocol" above the serif title, green serif step numbers
   hanging in the margin. The other kinds stay plain. */
.phone-inbox-item[data-kind="protocol"] {
    --margin: 44px;
    padding-left: calc(var(--margin) + 14px);
    background:
        linear-gradient(var(--ph-protocol-rule), var(--ph-protocol-rule)) var(--margin) 0 / 1.5px 100% no-repeat,
        var(--ph-protocol-paper);
}
.phone-inbox-item[data-kind="protocol"] .phone-inbox-kind {
    position: relative;
    color: var(--ph-protocol-numeral);
}
.phone-inbox-item[data-kind="protocol"] .phone-inbox-kind::before {
    content: '';
    position: absolute;
    top: 0;
    left: calc(-14px - var(--margin) / 2 - 10px);
    width: 20px;
    height: 20px;
    background-color: var(--ph-protocol-numeral);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8.5 3h7M10 3v6.3L4.9 18.2A1.9 1.9 0 0 0 6.5 21h11a1.9 1.9 0 0 0 1.6-2.8L14 9.3V3'/%3E%3Cpath d='M7.4 15.4c1.6-.8 3.1-.2 4.6.4s3 .6 4.6-.3'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8.5 3h7M10 3v6.3L4.9 18.2A1.9 1.9 0 0 0 6.5 21h11a1.9 1.9 0 0 0 1.6-2.8L14 9.3V3'/%3E%3Cpath d='M7.4 15.4c1.6-.8 3.1-.2 4.6.4s3 .6 4.6-.3'/%3E%3C/svg%3E") center / contain no-repeat;
}
.phone-inbox-item[data-kind="protocol"] .phone-steps li { padding-left: 0; }
.phone-inbox-item[data-kind="protocol"] .phone-steps li::before {
    left: auto;
    right: calc(100% + 24px);
    top: 11px;
    width: 30px;
    height: auto;
    border-radius: 0;
    background: none;
    color: var(--ph-protocol-numeral);
    font-family: var(--ph-serif);
    font-weight: 500;
    font-size: 23px;
    line-height: 1.2;
    text-align: right;
}

/* A picture: the width of the screen, a tap shows it full size */
.phone-picture {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 10px;
    background: var(--ph-border);
    cursor: zoom-in;
}
.phone-picture:focus-visible { outline: 3px solid var(--ph-primary); outline-offset: 3px; }
.phone-caption { margin-top: 10px; font-size: 18px; }

/* A table or plate map: scrolls sideways, the first column stays in view */
.phone-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -14px;
    padding: 0 14px;
}
.phone-table { border-collapse: separate; border-spacing: 0; font-size: 18px; }
.phone-table th, .phone-table td {
    padding: 10px 12px;
    min-width: 64px;
    max-width: 260px;
    border-bottom: 1px solid var(--ph-border);
    border-right: 1px solid var(--ph-border);
    text-align: left;
    vertical-align: top;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    background: var(--ph-surface);
}
.phone-table tr:first-child > * { border-top: 1px solid var(--ph-border); }
.phone-table tr > :first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    border-left: 1px solid var(--ph-border);
    background: var(--ph-bg);
    font-weight: 600;
}
.phone-table tr:first-child > * { background: var(--ph-bg); font-weight: 700; }
.phone-plate th { text-align: center; min-width: 44px; color: var(--ph-muted); }
.phone-plate td { min-width: 64px; text-align: center; font-size: 17px; }
.phone-plate td.filled { background: var(--ph-secondary-bg); color: var(--ph-secondary-text); font-weight: 600; }
.phone-well-bottom { font-size: 15px; font-weight: 400; color: var(--ph-muted); }

/* Any other file: its name and type, "Open" for a PDF */
.phone-file { display: flex; align-items: center; gap: 12px; }
.phone-file-words { flex: 1; min-width: 0; }
.phone-file-name { font-size: 19px; font-weight: 600; overflow-wrap: anywhere; }
.phone-file .phone-muted { margin: 2px 0 0; }
.phone-open { width: auto; margin: 0; min-width: 96px; text-decoration: none; }
.phone-link-out {
    display: block;
    font-size: 19px;
    color: var(--ph-secondary-text);
    overflow-wrap: anywhere;
    padding: 8px 0;
}

/* ── A picture full size ── */
.phone-viewer {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}
.phone-viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.phone-viewer-close {
    position: absolute;
    top: max(12px, env(safe-area-inset-top));
    right: 12px;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    cursor: pointer;
    z-index: 1;
}
.phone-viewer-close:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

/* ── A protocol as a checklist (phone-checklist.js) ── */
.pc-readonly {
    margin: 0 0 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--ph-bg);
    color: var(--ph-muted);
    font-size: 16px;
}
.pc-section { margin: 16px 0 4px; font-size: 15px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ph-muted); }
.pc-steps { list-style: none; margin: 0 -6px; padding: 0; }
.pc-step { padding: 4px 0; border-top: 1px solid var(--ph-border); }
.pc-step:first-child { border-top: none; }
/* The whole row is the touch target */
.pc-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-height: 56px;
    padding: 8px 6px;
    border-radius: 12px;
    -webkit-tap-highlight-color: transparent;
}
.pc-row.is-tappable { cursor: pointer; }
.pc-row.is-tappable:active { background: var(--ph-bg); }
.pc-box {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 2.5px solid var(--ph-primary);
    border-radius: 50%;
    background: transparent;
    color: var(--ph-secondary-text);
    font: inherit;
    font-size: 19px;
    font-weight: 700;
    cursor: pointer;
}
.pc-box:disabled { border-color: var(--ph-border); color: var(--ph-muted); cursor: default; opacity: 1; }
.pc-box:focus-visible { outline: 3px solid var(--ph-primary); outline-offset: 2px; }
.pc-text { flex: 1; min-width: 0; padding-top: 7px; font-size: 20px; line-height: 1.55; overflow-wrap: anywhere; }
/* The step to do now stands out; a step that is done steps back */
.pc-step.is-current .pc-row {
    background: var(--ph-secondary-bg);
    box-shadow: inset 0 0 0 2px var(--ph-primary);
}
.pc-step.is-current .pc-box { background: var(--ph-primary); color: var(--ph-primary-text); }
.pc-step.is-current .pc-text { font-weight: 600; }
.pc-step.is-done .pc-box { background: var(--ph-primary); border-color: var(--ph-primary); color: var(--ph-primary-text); }
.pc-list[data-editable="false"] .pc-step.is-done .pc-box { background: var(--ph-border); border-color: var(--ph-border); color: var(--ph-text); }
.pc-step.is-done .pc-text { color: var(--ph-muted); }
/* Every number can be changed: a clear outline says so */
.pc-num {
    display: inline-block;
    margin: 0 1px;
    padding: 0 7px;
    min-width: 34px;
    border: 2px solid var(--ph-num-border);
    border-radius: 8px;
    background: var(--ph-surface);
    color: var(--ph-text);
    font: inherit;
    font-weight: 700;
    line-height: 1.3;
    text-align: center;
    cursor: pointer;
}
span.pc-num { border-color: transparent; cursor: default; padding: 0 4px; }
.pc-num:focus-visible { outline: 3px solid var(--ph-primary); outline-offset: 1px; }
.pc-num.is-changed { background: var(--ph-changed-bg); color: var(--ph-changed-text); border-color: var(--ph-changed-bg); }
button.pc-num.is-changed { border-color: var(--ph-changed-text); }
.pc-step.is-done .pc-num { color: inherit; }
.pc-step.is-done .pc-num.is-changed { color: var(--ph-changed-text); }
/* Under the step text, aligned with it */
.pc-under { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 0 6px 6px 62px; }
.pc-under > * { flex: 0 0 100%; }
.pc-under > .pc-add-note, .pc-under > .pc-timer:not(.is-running):not(:has(.pc-timer-record)) { flex: 0 0 auto; }
.pc-done { color: var(--ph-ok); font-size: 16px; font-weight: 600; }
.pc-done.is-pending { color: var(--ph-muted); }
.pc-was { color: var(--ph-muted); font-size: 15px; }
.pc-timer { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; }
.pc-timer-record { color: var(--ph-muted); font-size: 16px; }
.pc-timer-btn {
    display: inline-flex;
    align-items: center;
    min-height: 52px;
    padding: 8px 18px;
    border: none;
    border-radius: 12px;
    background: var(--ph-secondary-bg);
    color: var(--ph-secondary-text);
    font: inherit;
    font-size: 19px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
}
.pc-timer-btn:focus-visible { outline: 3px solid var(--ph-primary); outline-offset: 2px; }
.pc-timer-stop { background: transparent; border: 1.5px solid var(--ph-border); color: var(--ph-muted); }
.pc-timer-left { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ph-text); }
.pc-timer.is-up .pc-timer-left { color: var(--ph-danger); }
.pc-add-note, .pc-note {
    min-height: 48px;
    border-radius: 10px;
    font: inherit;
    font-size: 17px;
    text-align: left;
    cursor: pointer;
}
.pc-add-note {
    padding: 8px 12px 8px 8px;
    border: none;
    background: transparent;
    color: var(--ph-muted);
    font-weight: 600;
}
.pc-add-note::before { content: "+ "; font-weight: 700; }
.pc-note {
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-left: 4px solid var(--ph-primary);
    background: var(--ph-bg);
    color: var(--ph-text);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
div.pc-note { cursor: default; }
.pc-add-note:focus-visible, .pc-note:focus-visible { outline: 3px solid var(--ph-primary); outline-offset: 2px; }
.pc-note-form { width: 100%; }
.pc-note-field {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--ph-primary);
    border-radius: 10px;
    background: var(--ph-surface);
    color: var(--ph-text);
    font: inherit;
    font-size: 18px;
    resize: vertical;
}
.pc-note-field:focus { outline: none; }
.pc-note-buttons { display: flex; gap: 8px; margin-top: 8px; }
.pc-note-buttons .phone-btn { margin: 0; font-size: 18px; }
.pc-status { font-size: 16px; color: var(--ph-muted); }
.pc-status.is-failed {
    min-height: 48px;
    padding: 8px 14px;
    border: 2px solid var(--ph-danger);
    border-radius: 10px;
    background: transparent;
    color: var(--ph-danger);
    font: inherit;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
}
.pc-status.is-refused { color: var(--ph-danger); font-weight: 600; }
.pc-step.is-unsaved .pc-row { box-shadow: inset 0 0 0 2px var(--ph-danger); }

/* A number: the sheet from the bottom */
.pc-sheet-back { position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, 0.45); }
.pc-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 56;
    max-width: 480px;
    margin: 0 auto;
    padding: 10px 18px max(18px, env(safe-area-inset-bottom));
    border-radius: 22px 22px 0 0;
    background: var(--ph-surface);
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.25);
}
.pc-sheet-grip { width: 44px; height: 5px; margin: 0 auto 12px; border-radius: 3px; background: var(--ph-border); }
.pc-sheet-title { font-size: 22px; font-weight: 700; }
.pc-sheet-step { margin-top: 4px; color: var(--ph-muted); font-size: 16px; overflow-wrap: anywhere; }
.pc-sheet-orig { display: block; margin: 14px 0 6px; font-size: 17px; font-weight: 600; }
.pc-sheet-input {
    display: block;
    width: 100%;
    height: 68px;
    padding: 0 16px;
    border: 2px solid var(--ph-primary);
    border-radius: 14px;
    background: var(--ph-bg);
    color: var(--ph-text);
    font: inherit;
    font-size: 34px;
    font-weight: 700;
    text-align: center;
    font-variant-numeric: tabular-nums;
}
.pc-sheet-input:focus { outline: none; box-shadow: 0 0 0 3px var(--ph-secondary-bg); }
.pc-sheet-error { margin-top: 8px; color: var(--ph-danger); font-weight: 600; font-size: 16px; }
.pc-sheet .phone-btn-primary { margin-top: 14px; }
.pc-sheet .phone-link-btn { margin-top: 4px; }

/* Running timers: a bar fixed at the top */
.pc-timer-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 40;
    padding: max(8px, env(safe-area-inset-top)) 10px 8px;
    background: var(--ph-surface);
    border-bottom: 1.5px solid var(--ph-border);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}
.pc-bar-chips { display: flex; gap: 8px; max-width: 480px; margin: 0 auto; overflow-x: auto; }
.pc-bar-chip {
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 230px;
    min-height: 52px;
    padding: 4px 12px;
    border: none;
    border-radius: 12px;
    background: var(--ph-primary);
    color: var(--ph-primary-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.pc-bar-time { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.pc-bar-what { max-width: 100%; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.9; }
.pc-bar-chip.is-up { background: var(--ph-alarm); color: #fff; }
body.pc-has-bar .phone-main { padding-top: calc(max(20px, env(safe-area-inset-top)) + 84px); }

/* ── The checklist uses the phone's width ──────────────────────────────────────────
   A step's text gets nearly the whole screen: the protocol runs from edge to edge with a slim
   green rule in place of its margin column, the step number is small because the whole row
   ticks the step, the timer and the note button share one row, done steps fold to one line,
   and a slim bar with the protocol's name and progress stays at the top. */
.phone-inbox-item[data-kind="protocol"] {
    margin-left: -16px;
    margin-right: -16px;
    padding: 12px 12px 14px 11px;
    border-left: 3px solid var(--ph-protocol-rule);
    border-right: none;
    border-radius: 0;
    background: var(--ph-protocol-paper);
    box-shadow: none;
}
.phone-inbox-item[data-kind="protocol"] .phone-inbox-kind { display: flex; align-items: center; gap: 6px; }
.phone-inbox-item[data-kind="protocol"] .phone-inbox-kind::before { position: static; flex: none; width: 16px; height: 16px; }

.pc-progress {
    position: sticky;
    top: 0;
    z-index: 4;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 10px;
    margin: 0 -12px 2px -11px;
    padding: 7px 12px 6px 11px;
    background: var(--ph-protocol-paper);
    border-bottom: 1px solid var(--ph-border);
    font-size: 15px;
}
body.pc-has-bar .pc-progress { top: 84px; }
.pc-progress-title { display: none; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--ph-text); }
.pc-progress.is-stuck .pc-progress-title { display: block; }
.pc-progress-count { flex: none; color: var(--ph-muted); font-variant-numeric: tabular-nums; }
.pc-progress-track { flex: 0 0 100%; height: 3px; margin-top: 5px; border-radius: 2px; background: var(--ph-border); overflow: hidden; }
.pc-progress-fill { height: 100%; border-radius: 2px; background: var(--ph-primary); transition: width 0.25s ease; }

.pc-steps { margin: 0; }
.pc-step { padding: 2px 0; }
.pc-row { gap: 10px; min-height: 44px; padding: 8px 4px; border-radius: 10px; }
.pc-box { width: 28px; height: 28px; margin-top: 1px; border-width: 2px; font-family: var(--ph-font); font-size: 14px; letter-spacing: -0.02em; }
.pc-box svg { width: 16px; height: 16px; }
.pc-text { padding-top: 0; font-size: 19px; line-height: 1.5; }
.pc-num { position: relative; padding: 0 5px; min-width: 30px; border-width: 1.5px; border-radius: 7px; line-height: 1.25; }
/* The field looks small but is easy to hit */
button.pc-num::after { content: ''; position: absolute; inset: -9px -3px; }
.pc-under { padding: 4px 4px 6px 42px; gap: 4px 8px; }
.pc-under > .pc-done { flex: 1 1 auto; }
.pc-timer-btn { min-height: 44px; padding: 6px 14px; border-radius: 10px; font-size: 17px; }
.pc-timer-left { font-size: 26px; }

/* "Add a note": a small button at the right end of a row */
.pc-add-note {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-height: 44px;
    margin: -8px -4px -8px auto;
    padding: 0;
    color: var(--ph-muted);
}
.pc-add-note::before { content: none; }
.pc-row > .pc-add-note { margin: -8px -4px -8px 0; }
.pc-under > .pc-add-note { margin: 0 -4px 0 auto; }
.pc-add-note:active { background: var(--ph-bg); }

/* A done step, folded to one line */
.pc-step.is-folded .pc-row { align-items: center; min-height: 40px; padding: 4px 4px; }
.pc-step.is-folded .pc-box { width: 22px; height: 22px; margin: 0 3px; border-width: 0; }
.pc-step.is-folded .pc-box svg { width: 13px; height: 13px; }
.pc-step.is-folded .pc-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; line-height: 1.4; }
.pc-step.is-folded .pc-num { min-width: 0; padding: 0 1px; border: none; background: none; font-weight: 600; }
.pc-step.is-folded .pc-num.is-changed { padding: 0 4px; background: var(--ph-changed-bg); }
.pc-fold-when { flex: none; color: var(--ph-muted); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pc-fold-note { flex: none; display: inline-flex; color: var(--ph-muted); }
.pc-fold-note svg { width: 15px; height: 15px; }

/* Time is up: over everything until tapped */
.pc-alarm {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--ph-alarm);
    color: #fff;
    animation: pc-flash 1s steps(2, jump-none) infinite;
}
@keyframes pc-flash { 50% { background: #7A1420; } }
@media (prefers-reduced-motion: reduce) { .pc-alarm { animation: none; } }
.pc-alarm-box { width: 100%; max-width: 420px; text-align: center; }
.pc-alarm-title { font-size: 44px; font-weight: 800; line-height: 1.1; }
.pc-alarm-what { margin-top: 14px; font-size: 21px; line-height: 1.4; overflow-wrap: anywhere; }
.pc-alarm-late { margin-top: 10px; font-size: 18px; opacity: 0.9; }
.pc-alarm-ok { margin-top: 28px; min-height: 84px; background: #fff; color: #7A1420; font-size: 28px; font-weight: 800; }

/* Nothing moves for people who ask their system for less motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

/* The checklist in the new look: the step numerals in the serif, in the protocol's green */
.phone-inbox-item[data-kind="protocol"] .pc-box {
    border-width: 1.5px;
    border-color: var(--ph-protocol-rule);
    color: var(--ph-protocol-numeral);
    font-family: var(--ph-serif);
    font-weight: 500;
    font-size: 21px;
}
.phone-inbox-item[data-kind="protocol"] .pc-step.is-current .pc-box,
.phone-inbox-item[data-kind="protocol"] .pc-step.is-done .pc-box { color: var(--ph-primary-text); border-color: var(--ph-primary); }
.phone-inbox-item[data-kind="protocol"] .pc-list[data-editable="false"] .pc-step.is-done .pc-box { color: var(--ph-text); border-color: var(--ph-border); }
.pc-section { text-transform: none; letter-spacing: 0.02em; font-weight: 600; }

/* Under a protocol: where it was adapted from (the credit its licence requires) and what it is
   based on (phone_sends.credit_of). Quiet: smaller, muted, above a thin rule. */
.phone-credit {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--ph-border);
    font-size: 15px;
    line-height: 1.45;
    color: var(--ph-muted);
}
.phone-credit p { margin: 0 0 8px; }
.phone-credit h4 { margin: 10px 0 4px; font-size: 15px; font-weight: 600; color: var(--ph-text); }
.phone-credit ul { margin: 0; padding-left: 20px; }
.phone-credit li { margin: 0 0 4px; }
