/* ==========================================================================
   Reinschrift — "Textmarker" design
   Text-first list: +project and @place read as tokens inside the line, the
   date view is a schedule, and what is due today carries a highlighter.
   ========================================================================== */

/* Inter for text, Inter Tight for the large headings (both SIL OFL 1.1,
   variable weight, from Fontsource). Hanken Grotesk, the earlier typeface,
   stays available as a setting (html[data-font="hanken"]). */

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('fonts/inter-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('fonts/inter-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
    font-family: 'Inter Tight';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('fonts/inter-tight-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Inter Tight';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('fonts/inter-tight-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* --------------------------------------------------------------------------
   Tokens
   -------------------------------------------------------------------------- */

@font-face {
    font-family: 'Hanken Grotesk';
    font-style: normal;
    font-weight: 400 800;
    font-display: swap;
    src: url('fonts/hanken-grotesk-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Hanken Grotesk';
    font-style: normal;
    font-weight: 400 800;
    font-display: swap;
    src: url('fonts/hanken-grotesk-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
    color-scheme: light;

    --bg: #f5f7f8;
    --surface: #ffffff;
    --sunk: #eaeef1;
    --ink: #1b2230;
    --ink-2: #5b6472;
    --ink-3: #7d8591;
    --rule: #dde2e7;
    --rule-strong: #c3cad3;

    --marker: #ffe45c;
    --marker-solid: #ffe45c;
    --marker-ink: #1b2230;
    --accent: #2f5bd3;
    --accent-soft: #e6ecfb;
    --late: #b42318;
    --late-soft: #fdecea;
    --success: #1f7a4d;
    --on-success: #ffffff;

    --tok-project: #9a4b00;
    --tok-context: #2f5bd3;

    --toast-bg: #1b2230;
    --toast-ink: #f5f7f8;
    --toast-action: #ffe45c;

    --shadow-pop: 0 1px 2px rgba(27, 34, 48, 0.06), 0 8px 28px rgba(27, 34, 48, 0.14);
    --backdrop: rgba(18, 22, 29, 0.42);

    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans JP', 'Hiragino Sans', sans-serif;
    --font-display: 'Inter Tight', var(--font);

    --gutter: 30px;
    --radius: 8px;
    --radius-lg: 16px;
    --touch: 44px;

    --z-sticky: 100;
    --z-menu: 150;
    --z-modal: 300;
    --z-toast: 1000;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;

        --bg: #12161d;
        --surface: #1b212b;
        --sunk: #232a35;
        --ink: #e7eaf0;
        --ink-2: #a0a8b6;
        --ink-3: #7c8594;
        --rule: #262d38;
        --rule-strong: #384150;

        --marker: rgba(255, 214, 10, 0.30);
        --marker-solid: #d9b400;
        --marker-ink: #fff6c7;
        --accent: #8aa8ff;
        --accent-soft: #1d2a45;
        --late: #ff8a80;
        --late-soft: #3a1e1e;
        --success: #5fcf95;
        --on-success: #0d2a1b;

        --tok-project: #f0b16a;
        --tok-context: #8aa8ff;

        --toast-bg: #e7eaf0;
        --toast-ink: #12161d;
        --toast-action: #2f5bd3;

        --shadow-pop: 0 0 0 1px rgba(255, 255, 255, 0.04), 0 10px 32px rgba(0, 0, 0, 0.5);
        --backdrop: rgba(0, 0, 0, 0.6);
    }
}

/* Setting "Classic typeface": Hanken Grotesk for text and headings, with the
   tighter heading tracking it was designed with. */
:root[data-font="hanken"] {
    --font: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans JP', 'Hiragino Sans', sans-serif;
    --font-display: var(--font);
}

:root[data-font="hanken"] .app-date-day,
:root[data-font="hanken"] .login-box h1 {
    letter-spacing: -0.02em;
}

:root[data-font="hanken"] .page-header h1 {
    letter-spacing: -0.01em;
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    max-width: 640px;
    margin: 0 auto;
    padding-inline: 16px;
    padding-block: calc(12px + var(--safe-top)) calc(48px + var(--safe-bottom));
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
    min-height: 100dvh;
}

h1, h2, h3, h4, h5 {
    margin: 0;
    line-height: 1.2;
    text-wrap: balance;
}

a {
    color: var(--accent);
}

/* Prevent iOS zoom on input focus */
input, select, textarea {
    font: inherit;
    font-size: 16px;
    color: inherit;
}

button {
    font: inherit;
    color: inherit;
}

button, a, .checkbox, .todo-item {
    touch-action: manipulation;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.icon {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

[hidden] {
    display: none !important;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    background: none;
    color: var(--ink-2);
    cursor: pointer;
    text-decoration: none;
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--sunk);
    color: var(--ink);
}

.icon-btn.active {
    color: var(--ink);
    background: var(--sunk);
}

.btn-primary,
.btn-secondary,
.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: var(--touch);
    padding: 0 18px;
    border-radius: var(--radius);
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--ink);
    color: var(--bg);
    border: 1px solid var(--ink);
}

.btn-primary:hover {
    opacity: 0.88;
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: default;
}

.btn-secondary {
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--rule-strong);
}

.btn-secondary:hover {
    border-color: var(--ink);
}

.btn-danger {
    background: none;
    color: var(--late);
    border: 1px solid transparent;
}

.btn-danger:hover {
    background: var(--late-soft);
}

.btn-block {
    width: 100%;
}

/* Small bordered text buttons: postpone targets, quick dates, menu-less actions */
.chip,
.btn-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 34px;
    padding: 0 11px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font-size: 0.86rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.chip:hover,
.btn-action:hover {
    border-color: var(--ink);
}

.chip.is-quiet {
    border-color: transparent;
    background: none;
    color: var(--ink-2);
}

.chip.is-quiet:hover {
    color: var(--ink);
    background: var(--sunk);
}

.chip.is-link {
    border-color: transparent;
    background: none;
    color: var(--accent);
}

.chip.is-link:hover {
    background: var(--accent-soft);
}

/* --------------------------------------------------------------------------
   Header: today's date + tools
   -------------------------------------------------------------------------- */

.app-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-block: 10px 6px;
}

.app-date {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 2px 10px;
    margin: 0;
    flex: 1;
    min-width: 0;
    font-size: inherit;
    font-weight: inherit;
}

.app-date-day {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    line-height: 1.05;
}

.app-date-rest {
    color: var(--ink-2);
    font-weight: 500;
}

.header-icons {
    display: flex;
    gap: 2px;
    align-self: center;
}

/* --------------------------------------------------------------------------
   Add line and search line
   -------------------------------------------------------------------------- */

.add-line,
.search-line {
    display: flex;
    align-items: center;
    gap: 4px;
    border-bottom: 2px solid var(--ink);
    padding-block: 4px;
}

.search-line {
    border-bottom-color: var(--accent);
    margin-top: 10px;
}

.search-line:not(.visible) {
    display: none;
}

.add-line input,
.search-line input[type="text"] {
    flex: 1;
    min-width: 0;
    min-height: var(--touch);
    border: 0;
    background: transparent;
    outline: none;
    padding: 0;
    font-size: 1.05rem;
}

.add-line input::placeholder,
.search-line input::placeholder {
    color: var(--ink-3);
}

.add-line .icon-btn.submit-btn {
    color: var(--ink);
}

.voice-btn.recording {
    color: var(--late);
    background: var(--late-soft);
    animation: pulse 1.5s infinite;
}

.smart-btn .spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--rule-strong);
    border-top-color: var(--ink);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: none;
}

.smart-btn.loading .spinner {
    display: inline-block;
}

.smart-btn.loading .smart-icon {
    display: none;
}

.ai-filled {
    animation: marker-flash 1s ease-out;
}

.add-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 10px;
    min-height: 1.5em;
    margin: 6px 0 0;
    font-size: 0.86rem;
    color: var(--ink-2);
}

.add-preview .tok + .tok {
    margin-left: 0;
}

.add-preview b {
    font-weight: 700;
}

.duplicate-warning {
    margin-top: 6px;
    padding: 6px 10px;
    border-radius: var(--radius);
    background: var(--marker);
    color: var(--marker-ink);
    font-size: 0.9rem;
}

/* --------------------------------------------------------------------------
   View tabs + filter menu
   -------------------------------------------------------------------------- */

.view-bar {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-top: 14px;
    border-bottom: 1px solid var(--rule);
}

.view-tabs {
    display: flex;
    gap: 18px;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.view-tabs::-webkit-scrollbar {
    display: none;
}

.view-tab {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 0 9px;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    color: var(--ink-2);
    font-weight: 600;
    font-size: 0.95rem;
    text-decoration: none;
    white-space: nowrap;
}

.view-tab:hover {
    color: var(--ink);
}

.view-tab.active {
    color: var(--ink);
    border-bottom-color: var(--ink);
}

.view-bar .menu {
    margin-bottom: 2px;
}

/* <details> menus: group actions and filters */
.menu {
    position: relative;
}

.menu > summary {
    list-style: none;
}

.menu > summary::-webkit-details-marker {
    display: none;
}

.menu.has-active > summary {
    color: var(--ink);
    background: var(--marker);
}

.menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: var(--z-menu);
    min-width: 220px;
    padding: 6px;
    border: 1px solid var(--rule);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow-pop);
    display: grid;
}

.menu-heading {
    padding: 6px 10px 2px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--ink-2);
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    padding: 0 10px;
    border: 0;
    border-radius: var(--radius);
    background: none;
    color: var(--ink);
    font-size: 0.93rem;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    width: 100%;
}

.menu-item:hover {
    background: var(--sunk);
}

.menu-item .icon {
    color: var(--ink-2);
}

.menu-divider {
    height: 1px;
    margin: 4px 6px;
    background: var(--rule);
}

/* Toggle entries in the filter menu: a drawn checkbox reflects aria-checked */
.menu-item[role="menuitemcheckbox"]::before {
    content: '';
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    border: 2px solid var(--ink);
    border-radius: 5px;
}

.menu-item[role="menuitemcheckbox"][aria-checked="true"]::before {
    background: var(--ink) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") center / 12px no-repeat;
}

@media (prefers-color-scheme: dark) {
    .menu-item[role="menuitemcheckbox"][aria-checked="true"]::before {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2312161d' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
    }
}

/* Filter panel (inside the filter menu) */
.filter-panel {
    width: min(320px, calc(100vw - 32px));
    max-height: min(70vh, 560px);
    overflow-y: auto;
    padding: 14px;
    gap: 0;
}

.filter-panel .form-group {
    margin-bottom: 10px;
}

.filter-panel select {
    width: 100%;
    min-height: 40px;
    padding: 6px 10px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--ink);
}

.filter-group {
    margin: 10px 0 0;
    padding: 10px 0 0;
    border: 0;
    border-top: 1px solid var(--rule);
}

.filter-group legend {
    /* float takes the legend off the border line */
    float: left;
    width: 100%;
    padding: 0;
    margin-bottom: 4px;
}

.filter-options {
    clear: both;
}

.filter-panel .check-row.is-compact .check-label {
    font-weight: 500;
}

.filter-options {
    display: grid;
    max-height: 190px;
    overflow-y: auto;
}

.check-row.is-compact {
    margin-bottom: 0;
    padding-block: 5px;
}

.check-row input:disabled + .check-label {
    color: var(--ink-3);
}

.filter-panel > .check-row:last-of-type {
    margin-top: 10px;
    padding-top: 12px;
    border-top: 1px solid var(--rule);
}

.filter-panel [data-filter-reset] {
    margin-top: 10px;
    min-height: 40px;
}

.filter-menu > summary {
    position: relative;
}

.filter-count {
    position: absolute;
    top: 3px;
    right: 3px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--ink);
    color: var(--bg);
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}

/* Active filters above the list */
.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 12px;
}

.filter-chip {
    background: var(--marker);
    border-color: transparent;
    color: var(--marker-ink);
}

.filter-chip:hover {
    border-color: var(--ink);
}

.list-empty .btn-secondary {
    margin-top: 10px;
}

/* --------------------------------------------------------------------------
   List: sections
   -------------------------------------------------------------------------- */

.todo-list {
    padding: 0;
    margin-top: 4px;
}

.todo-list[aria-busy="true"] {
    opacity: 0.6;
    transition: opacity 0.15s;
}

.section-group + .section-group,
.todo-rows + .section-header,
.section-header + .todo-rows + .section-header {
    margin-top: 6px;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 18px;
    padding-bottom: 2px;
    min-height: 44px;
}

.section-title {
    flex: 1;
    min-width: 0;
    font-size: 1rem;
    font-weight: 800;
    overflow-wrap: anywhere;
}

.section-count {
    margin-left: 6px;
    font-weight: 500;
    color: var(--ink-3);
}

.section-header.is-overdue .section-title {
    color: var(--late);
}

.section-header .icon-btn {
    width: 36px;
    height: 36px;
}

.section-items {
    min-height: 12px;
}

/* --------------------------------------------------------------------------
   List: rows
   -------------------------------------------------------------------------- */

.todo-item {
    position: relative;
    display: grid;
    grid-template-columns: var(--gutter) 32px minmax(0, 1fr);
    column-gap: 8px;
    align-items: start;
    padding-block: 6px;
    border-bottom: 1px solid var(--rule);
    background: var(--bg);
    overflow: hidden;
}

.is-schedule {
    --gutter: 46px;
}

.gutter {
    display: grid;
    justify-items: end;
    align-content: start;
    padding-top: 7px;
    font-size: 0.85rem;
    line-height: 1.25;
    color: var(--ink-2);
    font-variant-numeric: tabular-nums;
    min-height: 32px;
}

.gutter-day {
    font-weight: 600;
}

.gutter .is-late {
    color: var(--late);
    font-weight: 700;
}

.checkbox {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    color: transparent;
}

.checkbox .box {
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border: 2px solid var(--ink);
    border-radius: 5px;
    transition: background 0.12s;
}

.checkbox:hover .box {
    background: var(--sunk);
}

.todo-item.done .checkbox .box {
    background: var(--ink);
    color: var(--bg);
}

.content {
    min-width: 0;
    padding-block: 5px;
    cursor: pointer;
    border-radius: 4px;
    overflow-wrap: anywhere;
}

.content .title {
    margin-right: 4px;
}

.todo-item.done .title {
    text-decoration: line-through;
    color: var(--ink-3);
}

.todo-item.done .tok {
    opacity: 0.7;
}

/* The highlighter: open todos due today or earlier */
.title mark {
    background: linear-gradient(transparent 10%, var(--marker) 10%, var(--marker) 90%, transparent 90%);
    color: var(--marker-ink);
    padding: 0 0.15em;
    margin: 0 -0.15em;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
}

.todo-item.done .title mark {
    background: none;
    color: inherit;
}

/* Shared list: no schedule or drag handle, so no gutter */
.todo-item.share-todo {
    grid-template-columns: 32px minmax(0, 1fr);
}

.share-todo .content {
    cursor: default;
}

/* Inline metadata tokens, as they appear in the Markdown line */
.tok {
    font-size: 0.87rem;
    white-space: nowrap;
    color: var(--ink-2);
}

.tok + .tok {
    margin-left: 6px;
}

.tok.project {
    color: var(--tok-project);
}

.tok.context {
    color: var(--tok-context);
}

.tok.due {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.tok.due.is-late {
    color: var(--late);
}

.tok.due.is-today {
    color: var(--ink);
}

.tok .icon {
    vertical-align: -2px;
}

/* Expanded row: note + actions under the text */
.todo-details {
    grid-column: 3;
    display: grid;
    gap: 8px;
    padding: 2px 0 8px;
}

.todo-details .note {
    margin: 0;
    padding-left: 10px;
    border-left: 2px solid var(--rule-strong);
    color: var(--ink-2);
    font-size: 0.92rem;
    white-space: pre-line;
}

.todo-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.todo-actions .push-end {
    margin-left: auto;
}

.content[aria-expanded="true"] .title {
    font-weight: 600;
}

/* Keyboard navigation (j/k) */
.todo-item.kbd-selected {
    background: var(--accent-soft);
}

/* Pending server write */
.todo-item.is-pending,
.myday-pending {
    opacity: 0.45;
    pointer-events: none;
    transition: opacity 0.15s;
}

/* Newly added or improved todo */
.todo-item.pulse {
    animation: marker-flash 1.8s ease-out;
}

/* --------------------------------------------------------------------------
   Swipe (mobile): right completes, left moves to tomorrow
   -------------------------------------------------------------------------- */

.todo-item::before,
.todo-item::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 88px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}

.todo-item::before {
    left: 0;
    background: var(--success);
}

.todo-item::after {
    right: 0;
    background: var(--marker-solid);
}

.todo-item.swiping-right::before,
.todo-item.swiping-left::after {
    opacity: 1;
}

.swipe-indicator {
    position: absolute;
    top: 50%;
    z-index: 1;
    transform: translateY(-50%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}

.swipe-indicator-left {
    left: 20px;
    color: var(--on-success);
}

.swipe-indicator-right {
    right: 20px;
    color: #1b2230;
}

.todo-item.swiping-right .swipe-indicator-left,
.todo-item.swiping-left .swipe-indicator-right {
    opacity: 1;
}

.haptic-feedback {
    animation: haptic 0.1s ease;
}

/* --------------------------------------------------------------------------
   Drag and drop between groups (topic/place views)
   -------------------------------------------------------------------------- */

.drag-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 32px;
    color: var(--ink-3);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    opacity: 0.55;
}

.todo-item:hover .drag-handle {
    opacity: 1;
}

.gutter:has(.drag-handle) {
    padding-top: 0;
}

.drag-handle:active {
    cursor: grabbing;
}

.drag-ghost {
    opacity: 0.3;
}

.drag-clone {
    position: fixed;
    z-index: var(--z-toast);
    pointer-events: none;
    opacity: 0.95;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-pop);
}

.drag-over {
    border-radius: var(--radius);
    background: var(--accent-soft);
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
}

/* --------------------------------------------------------------------------
   Empty states and My Day
   -------------------------------------------------------------------------- */

.list-empty,
.myday-empty {
    padding: 32px 8px;
    text-align: center;
    color: var(--ink-2);
}

.myday-empty-icon {
    display: inline-flex;
    margin-bottom: 8px;
    padding: 10px;
    border-radius: 50%;
    background: var(--marker);
    color: var(--marker-ink);
}

.myday-empty p {
    margin: 0;
}

.myday-picker {
    margin-top: 28px;
    padding-top: 6px;
    border-top: 2px solid var(--ink);
}

.myday-picker-title {
    padding-block: 12px 0;
    font-size: 1.15rem;
    font-weight: 800;
}

.myday-picker-section h4 {
    padding-top: 16px;
    font-size: 1rem;
    font-weight: 800;
}

.myday-picker-group {
    padding-top: 12px;
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--ink-2);
}

.myday-picker-empty {
    color: var(--ink-2);
}

.myday-picker-item {
    display: grid;
    grid-template-columns: var(--gutter) 32px minmax(0, 1fr);
    column-gap: 8px;
    align-items: start;
    padding-block: 6px;
    border-bottom: 1px dashed var(--rule-strong);
}

.myday-add-btn {
    grid-column: 2;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    background: none;
    color: var(--ink);
    cursor: pointer;
}

.myday-add-btn:hover {
    background: var(--marker);
    color: var(--marker-ink);
}

/* --------------------------------------------------------------------------
   Modals (bottom sheet on phones)
   -------------------------------------------------------------------------- */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    overflow: auto;
    background: var(--backdrop);
    padding: 48px 16px;
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    padding: 22px 22px 24px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-pop);
}

.modal-content.is-narrow {
    max-width: 400px;
}

.modal-content.is-wide {
    max-width: 800px;
}

.modal-content > h2 {
    margin: 0 44px 18px 0;
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 800;
}

.modal .close {
    position: absolute;
    top: 14px;
    right: 14px;
}

@media screen and (max-width: 600px) {
    .modal[style*="display: block"],
    .modal.visible {
        display: flex;
        align-items: flex-end;
        padding: 0;
    }

    .modal-content {
        max-width: none;
        max-height: 92vh;
        max-height: 92dvh;
        overflow-y: auto;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        padding-bottom: calc(24px + var(--safe-bottom));
        animation: slideUp 0.25s ease-out;
    }

    .modal-content::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        margin: -8px auto 14px;
        border-radius: 2px;
        background: var(--rule-strong);
    }
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */

.form-group {
    display: grid;
    gap: 6px;
    margin-bottom: 16px;
}

.form-group > label,
.field-label {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--ink-2);
}

.text-input,
.modal input[type="text"],
.modal input[type="password"],
.modal input[type="number"],
.modal input[type="date"],
.modal input[type="datetime-local"],
.modal textarea,
.modal select,
.page-form input[type="text"],
.page-form input[type="password"],
.page-form input[type="datetime-local"],
.page-form textarea,
.page-form select {
    width: 100%;
    min-height: var(--touch);
    padding: 9px 12px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--ink);
    outline: none;
}

.modal textarea,
.page-form textarea {
    resize: vertical;
    line-height: 1.45;
}

.modal input:focus,
.modal textarea:focus,
.modal select:focus,
.page-form input:focus,
.page-form textarea:focus,
.page-form select:focus,
.text-input:focus {
    border-color: var(--ink);
}

.quick-dates {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* A checkbox with its label and optional help text */
.check-row {
    display: grid;
    grid-template-columns: 22px 1fr;
    column-gap: 10px;
    row-gap: 2px;
    align-items: start;
    margin-bottom: 16px;
    cursor: pointer;
}

.check-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 3px 0 0;
    accent-color: var(--ink);
}

.check-row .check-label {
    font-weight: 600;
}

.check-row .help {
    grid-column: 2;
    margin: 0;
    font-size: 0.88rem;
    color: var(--ink-2);
}

.help {
    margin: 0;
    font-size: 0.88rem;
    color: var(--ink-2);
}

.buttons {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 22px;
}

.buttons .push-end {
    margin-left: auto;
}

#comment-section {
    display: none;
    margin-top: 12px;
    padding: 14px;
    border-radius: var(--radius);
    background: var(--sunk);
}

/* Project/context suggestion dropdowns in the edit modal */
.suggestion-input-wrapper {
    position: relative;
    display: flex;
}

.suggestion-input-wrapper input {
    flex: 1;
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

.suggestion-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: var(--touch);
    padding: 0 12px;
    border: 1px solid var(--rule-strong);
    border-left: 0;
    border-radius: 0 var(--radius) var(--radius) 0;
    background: var(--sunk);
    color: var(--ink-2);
    cursor: pointer;
}

.suggestion-btn:hover {
    color: var(--ink);
}

.suggestion-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: var(--z-menu);
    max-height: 220px;
    overflow-y: auto;
    padding: 4px;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-pop);
}

.suggestion-dropdown.visible {
    display: block;
}

.suggestion-item {
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--ink);
}

.suggestion-item:hover {
    background: var(--sunk);
}

/* Title autocomplete */
.autocomplete-dropdown {
    position: fixed;
    z-index: var(--z-toast);
    max-height: 280px;
    overflow-y: auto;
    margin: 0;
    padding: 4px;
    list-style: none;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-pop);
}

.autocomplete-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 4px 2px 10px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--ink);
}

.autocomplete-item:hover,
.autocomplete-item.active {
    background: var(--sunk);
}

.autocomplete-title {
    flex: 1;
    padding: 6px 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.autocomplete-copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--ink-3);
    cursor: pointer;
}

.autocomplete-copy-btn:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.autocomplete-section-header {
    padding: 8px 10px 4px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--ink-2);
    cursor: default;
}

/* Keyboard shortcuts */
.shortcut-list {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 8px 16px;
    margin: 0;
}

.shortcut-list dt {
    text-align: right;
}

.shortcut-list dd {
    margin: 0;
}

kbd {
    display: inline-block;
    min-width: 1.6em;
    padding: 1px 6px;
    border: 1px solid var(--rule-strong);
    border-bottom-width: 2px;
    border-radius: 5px;
    background: var(--bg);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    text-align: center;
}

/* Settings */
.settings-section + .settings-section {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--rule);
}

.lang-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.lang-link.active {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--bg);
}

.app-info {
    margin: 0;
    font-size: 0.85rem;
    color: var(--ink-2);
}

.app-info a {
    color: inherit;
}

/* --------------------------------------------------------------------------
   Bulk selection
   -------------------------------------------------------------------------- */

.bulk-bar {
    position: sticky;
    top: var(--safe-top);
    z-index: var(--z-sticky);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding: 8px;
    border-radius: 12px;
    background: var(--ink);
    color: var(--bg);
}

.bulk-count {
    padding: 0 6px;
    font-size: 0.9rem;
    font-weight: 700;
    white-space: nowrap;
}

.bulk-actions {
    display: flex;
    flex-wrap: wrap;
    flex: 1;
    align-items: center;
    gap: 4px;
}

.bulk-actions button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    padding: 0 10px;
    border: 0;
    border-radius: var(--radius);
    background: none;
    color: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
}

.bulk-actions button:hover:not(:disabled) {
    background: rgba(127, 127, 127, 0.25);
}

.bulk-actions button:disabled {
    opacity: 0.4;
    cursor: default;
}

.bulk-actions .bulk-danger {
    color: var(--late-soft);
}

.bulk-separator {
    width: 1px;
    height: 22px;
    margin: 0 2px;
    background: currentColor;
    opacity: 0.3;
}

.bulk-cancel.icon-btn {
    margin-left: auto;
    color: inherit;
}

.bulk-cancel.icon-btn:hover {
    background: rgba(127, 127, 127, 0.25);
    color: inherit;
}

.todo-item.selected {
    background: var(--accent-soft);
}

.todo-item.selected .checkbox .box {
    border-color: var(--accent);
}

body.select-mode .todo-item .drag-handle,
body.select-mode .todo-item .swipe-indicator {
    display: none;
}

body.select-mode .todo-item,
body.select-mode .todo-item .content,
body.select-mode .todo-item .checkbox {
    cursor: pointer;
}

@media screen and (max-width: 480px) {
    .bulk-bar {
        position: fixed;
        top: auto;
        left: 8px;
        right: 8px;
        bottom: calc(8px + var(--safe-bottom));
        margin: 0;
        box-shadow: var(--shadow-pop);
    }

    .bulk-actions .bulk-label {
        display: none;
    }
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */

.footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px 16px;
    margin-top: 40px;
    padding-top: 14px;
    border-top: 1px solid var(--rule);
    font-size: 0.85rem;
    color: var(--ink-3);
}

.footer a {
    color: inherit;
}

/* --------------------------------------------------------------------------
   Toasts
   -------------------------------------------------------------------------- */

.add-toast,
.undo-toast {
    position: fixed;
    left: 50%;
    z-index: var(--z-toast);
    max-width: calc(100vw - 32px);
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--toast-bg);
    color: var(--toast-ink);
    box-shadow: var(--shadow-pop);
    font-size: 0.92rem;
    opacity: 0;
    transition: opacity 0.25s, transform 0.25s;
}

.add-toast {
    top: calc(16px + var(--safe-top));
    transform: translateX(-50%) translateY(-12px);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    pointer-events: none;
}

.undo-toast {
    bottom: calc(24px + var(--safe-bottom));
    transform: translateX(-50%) translateY(12px);
    display: flex;
    align-items: center;
    gap: 14px;
}

.add-toast.visible,
.undo-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.undo-toast.is-error {
    background: var(--late);
    color: #ffffff;
}

.undo-toast-message {
    flex: 1;
}

.undo-toast-btn {
    padding: 4px 6px;
    border: 0;
    background: none;
    color: var(--toast-action);
    font-weight: 700;
    cursor: pointer;
}

/* --------------------------------------------------------------------------
   Share dialog (built by share.js)
   -------------------------------------------------------------------------- */

.share-dialog {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.share-dialog.hidden {
    display: none;
}

.share-dialog-backdrop {
    position: absolute;
    inset: 0;
    background: var(--backdrop);
}

.share-dialog-box {
    position: relative;
    z-index: 1;
    width: min(100%, 480px);
    padding: 22px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-pop);
}

.share-dialog-title {
    margin: 0 0 8px;
    font-size: 1.2rem;
    font-weight: 800;
}

.share-dialog-hint,
.share-dialog-expiry {
    margin: 0 0 14px;
    font-size: 0.9rem;
    color: var(--ink-2);
}

.share-dialog-link-row,
.share-dialog-ttl-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
}

.share-dialog-link,
.share-dialog-ttl {
    flex: 1;
    min-width: 0;
    min-height: 40px;
    padding: 6px 10px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--ink);
    font-size: 0.9rem;
}

.share-dialog-ttl-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--ink-2);
}

.share-dialog-error {
    margin: 0 0 14px;
    padding: 8px 10px;
    border-radius: var(--radius);
    background: var(--late-soft);
    color: var(--late);
    font-size: 0.88rem;
}

.share-dialog-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.share-dialog-link-row.hidden,
.share-dialog-ttl-row.hidden,
.share-dialog-expiry.hidden,
.share-dialog-error.hidden,
.share-dialog-actions button.hidden {
    display: none;
}

/* --------------------------------------------------------------------------
   Standalone pages: login, error, edit, shared list
   -------------------------------------------------------------------------- */

.page-header {
    padding-block: 18px 12px;
}

.page-header h1 {
    font-family: var(--font-display);
    font-size: 1.6rem;
    font-weight: 800;
}

.page-header .page-sub {
    margin: 4px 0 0;
    color: var(--ink-2);
}

.page-form {
    display: grid;
    gap: 0;
}

.login-page {
    display: grid;
    place-items: center;
    min-height: 80vh;
    min-height: 80dvh;
}

.login-box {
    width: min(100%, 360px);
}

.login-box h1 {
    margin-bottom: 4px;
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.01em;
}

.login-box .page-sub {
    margin: 0 0 22px;
    color: var(--ink-2);
}

.login-divider {
    margin: 18px 0;
    border: 0;
    border-top: 1px solid var(--rule);
}

.flash {
    margin-bottom: 14px;
    padding: 8px 12px;
    border-radius: var(--radius);
    background: var(--late-soft);
    color: var(--late);
}

.error-message {
    margin: 12px 0 20px;
    font-size: 1.1rem;
    color: var(--late);
}

.share-scope-tag.project {
    color: var(--tok-project);
}

.share-scope-tag.context {
    color: var(--tok-context);
}

.share-todo.completing {
    opacity: 0.4;
    transition: opacity 0.3s;
}

.share-error {
    display: none;
    margin: 8px 0;
    padding: 8px 12px;
    border-radius: var(--radius);
    background: var(--late-soft);
    color: var(--late);
}

.share-add-form {
    margin-top: 20px;
}

.share-footer {
    margin-top: 32px;
    text-align: center;
    font-size: 0.82rem;
    color: var(--ink-3);
}

/* --------------------------------------------------------------------------
   AI debug panel
   -------------------------------------------------------------------------- */

.ai-debug-info-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin-bottom: 14px;
    padding: 10px 12px;
    border-radius: var(--radius);
    background: var(--sunk);
    font-size: 0.9rem;
}

.ai-debug-error {
    display: none;
    margin-bottom: 14px;
    padding: 10px 12px;
    border-radius: var(--radius);
    background: var(--late-soft);
    color: var(--late);
}

.ai-debug-details {
    margin-bottom: 12px;
}

.ai-debug-details summary {
    padding: 6px 0;
    font-weight: 700;
    cursor: pointer;
}

.ai-debug-pre {
    margin: 0;
    padding: 10px 12px;
    border-radius: var(--radius);
    background: var(--sunk);
    color: var(--ink);
    font-size: 0.85rem;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-x: auto;
}

.ai-debug-pre.is-scroll {
    max-height: 300px;
    overflow-y: auto;
}

.ai-debug-pre.ai-debug-success {
    border-left: 3px solid var(--success);
}

.ai-debug-pre.ai-debug-rejected {
    border-left: 3px solid var(--late);
}

.ai-debug-pre.ai-debug-empty {
    color: var(--ink-3);
}

.ai-debug-status-ok {
    color: var(--success);
}

.ai-debug-status-rejected {
    color: var(--late);
}

/* --------------------------------------------------------------------------
   Pull to refresh
   -------------------------------------------------------------------------- */

.pull-to-refresh {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: var(--z-sticky);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: calc(56px + var(--safe-top));
    padding-top: var(--safe-top);
    background: var(--bg);
    color: var(--ink-2);
    font-size: 0.9rem;
    transform: translateY(-100%);
    transition: transform 0.2s;
}

.pull-to-refresh.visible {
    transform: translateY(0);
}

.pull-to-refresh.refreshing .spinner-icon {
    animation: spin 0.8s linear infinite;
}

.pull-to-refresh .spinner-icon {
    display: inline-flex;
    color: var(--ink);
}

/* --------------------------------------------------------------------------
   Motion
   -------------------------------------------------------------------------- */

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    50% { opacity: 0.5; }
}

@keyframes haptic {
    50% { transform: scale(0.98); }
}

@keyframes marker-flash {
    0%, 30% { background-color: var(--marker); }
    100% { background-color: transparent; }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
