:root {
    color-scheme: light;
    --color-background: #f2f3f9;
    --color-surface: #fff;
    --color-surface-muted: #eeedf8;
    --color-text: #202036;
    --color-text-muted: #595c74;
    --color-border: #dedfeb;
    --color-control-border: #8588a0;
    --color-primary: #5946ce;
    --color-primary-hover: #4938b4;
    --color-accent-text: #5340be;
    --color-focus: #6855dc;
    --color-danger: #a12a45;
    --color-danger-soft: #fce8ed;
    --color-header: rgb(250 250 255 / 92%);
    --color-glow: rgb(152 124 244 / 15%);
    --shadow-soft: 0 12px 32px rgb(35 28 91 / 8%);
    --radius-small: 9px;
    --radius-medium: 16px;
    --radius-large: 20px;
    --content-width: 1040px;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --color-background: #141421;
    --color-surface: #1e1e30;
    --color-surface-muted: #2a2841;
    --color-text: #f0effc;
    --color-text-muted: #b3b2cc;
    --color-border: #38374f;
    --color-control-border: #8886a5;
    --color-primary: #6953dc;
    --color-primary-hover: #5a43cd;
    --color-accent-text: #c3b6ff;
    --color-focus: #b7a6ff;
    --color-danger: #ffacbd;
    --color-danger-soft: #432236;
    --color-header: rgb(23 23 37 / 92%);
    --color-glow: rgb(122 94 233 / 18%);
    --shadow-soft: 0 12px 36px rgb(0 0 0 / 19%);
}

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

html {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--color-background);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--color-text);
    background:
        radial-gradient(ellipse at 50% 0%, var(--color-glow), transparent 39rem) no-repeat,
        var(--color-background);
}

button,
input,
textarea {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button {
    cursor: pointer;
}

.container {
    width: min(calc(100% - 40px), var(--content-width));
    margin-inline: auto;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-header);
    backdrop-filter: blur(14px);
}

.header-content {
    display: flex;
    min-height: 64px;
    align-items: center;
    gap: 14px;
}

.auth-actions {
    min-width: 0;
    margin-inline-start: auto;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    flex: none;
}

.theme-toggle[aria-pressed="true"] {
    color: var(--color-accent-text);
    background: var(--color-surface-muted);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--color-text);
    font-size: 1.05rem;
    font-weight: 750;
    letter-spacing: -0.02em;
    text-decoration: none;
    flex: none;
}

.brand-mark {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 10px;
    color: white;
    background: var(--color-primary);
}

.button-group,
.user-actions,
.welcome-actions,
.modal-footer {
    display: flex;
    align-items: center;
    gap: 10px;
}

.button {
    min-height: 42px;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-small);
    font-weight: 700;
    line-height: 1.2;
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.button:hover {
    transform: translateY(-1px);
}

.button:disabled {
    cursor: wait;
    opacity: 0.65;
    transform: none;
}

:is(button, a, input, textarea, summary):focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 3px;
}

.button-primary {
    color: white;
    background: var(--color-primary);
}

.button-primary:hover {
    background: var(--color-primary-hover);
}

.button-secondary {
    border-color: var(--color-border);
    color: var(--color-text);
    background: transparent;
}

.button-secondary:hover {
    background: var(--color-surface-muted);
}

.button-text {
    padding-inline: 8px;
    color: var(--color-accent-text);
    background: transparent;
}

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

.button-large {
    min-height: 50px;
    padding-inline: 24px;
}

.button-full {
    width: 100%;
    margin-top: 8px;
}

.page-content {
    max-width: 760px;
    padding-block: clamp(30px, 6vw, 68px) 72px;
}

.welcome-panel {
    padding: clamp(24px, 6vw, 52px);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-large);
    background: var(--color-surface);
    box-shadow: var(--shadow-soft);
}

.auth-state-panel {
    display: flex;
    min-height: 48vh;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    text-align: center;
}

.auth-state-panel h1 {
    max-width: 680px;
    margin-bottom: 12px;
    font-size: clamp(2.2rem, 6vw, 4.2rem);
}

.auth-state-panel .welcome-copy {
    margin-bottom: 18px;
    white-space: pre-line;
}

h1,
h2,
p {
    overflow-wrap: break-word;
}

h1,
h2 {
    margin-top: 0;
    letter-spacing: -0.045em;
}

h1 {
    max-width: 760px;
    margin-bottom: 16px;
    font-size: clamp(2rem, 5vw, 3.15rem);
    font-weight: 750;
    line-height: 1.08;
}

h2 {
    margin-bottom: 10px;
    font-size: 1.5rem;
}

.welcome-copy {
    max-width: 650px;
    margin: 0 0 24px;
    color: var(--color-text-muted);
    font-size: 1rem;
    line-height: 1.55;
}

.tasks-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    margin-bottom: 20px;
}

.tasks-header h1 {
    margin: 0;
}

#report-modal {
    width: min(calc(100% - 32px), 620px);
}

#report-modal-title {
    padding-inline-end: 44px;
}

.report-date {
    margin: 0 0 16px;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.report-text {
    max-height: min(55dvh, 26rem);
    overflow-y: auto;
    padding: 16px;
    border-radius: var(--radius-small);
    background: var(--color-surface-muted);
    line-height: 1.6;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.user-email {
    overflow: hidden;
    color: var(--color-text-muted);
    font-size: 0.92rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.create-task-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px 10px;
    padding: 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-medium);
    background: var(--color-surface);
    box-shadow: var(--shadow-soft);
}

.create-task-details {
    grid-column: 1 / -1;
}

.create-task-details summary {
    width: fit-content;
    margin-inline-start: 4px;
    padding: 4px 8px;
    color: var(--color-accent-text);
    font-size: 0.875rem;
    cursor: pointer;
}

.create-task-details textarea {
    min-height: 68px;
    margin-top: 6px;
}

input,
textarea {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-small);
    color: var(--color-text);
    background: var(--color-surface);
}

input::placeholder,
textarea::placeholder {
    color: var(--color-text-muted);
    opacity: 1;
}

input {
    min-height: 46px;
    padding: 10px 13px;
}

textarea {
    min-height: 120px;
    padding: 12px 13px;
    line-height: 1.5;
    resize: vertical;
}

.create-task-form input {
    border-color: transparent;
    background: transparent;
}

.task-groups {
    margin-top: 22px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-medium);
    background: var(--color-surface);
    box-shadow: var(--shadow-soft);
}

.task-list-section {
    padding: 4px 12px 10px;
}

.completed-tasks {
    padding-bottom: 4px;
    border-top: 1px solid var(--color-border);
}

.completed-tasks[open] {
    padding-bottom: 10px;
}

.list-heading {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 48px;
    padding-inline: 10px;
    font-weight: 700;
}

summary.list-heading {
    border-radius: var(--radius-small);
    cursor: pointer;
    list-style: none;
}

summary.list-heading::-webkit-details-marker {
    display: none;
}

summary.list-heading:hover {
    background: var(--color-surface-muted);
}

summary.list-heading::before {
    width: 7px;
    height: 7px;
    margin-inline-end: 3px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    content: "";
    transform: rotate(-45deg);
}

.completed-tasks[open] > summary::before {
    transform: rotate(45deg);
}

.list-heading h2 {
    margin: 0;
    font-size: 1rem;
    letter-spacing: 0;
}

.count-badge {
    display: grid;
    min-width: 22px;
    min-height: 22px;
    padding: 0 6px;
    place-items: center;
    border-radius: 999px;
    color: var(--color-accent-text);
    font-size: 0.8rem;
    font-weight: 800;
    background: var(--color-surface-muted);
}

.task-list {
    display: grid;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
    grid-template-columns: minmax(0, 1fr);
}

.task-row {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    align-items: center;
    min-height: 50px;
    border-radius: var(--radius-small);
}

.task-row:hover,
.task-row:focus-within {
    background: var(--color-surface-muted);
}

.task-status {
    display: grid;
    width: 36px;
    height: 40px;
    place-items: center;
    justify-self: center;
    padding: 0;
    border: 0;
    border-radius: var(--radius-small);
    color: white;
    background: transparent;
}

.task-status::before {
    display: grid;
    width: 19px;
    height: 19px;
    place-items: center;
    border: 1px solid var(--color-control-border);
    border-radius: 5px;
    content: "";
    font-size: 0.75rem;
    line-height: 1;
}

.task-status:hover::before {
    border-color: var(--color-focus);
}

.task-status[aria-checked="true"]::before {
    border-color: transparent;
    background: var(--color-primary);
    content: "✓";
}

.task-status[aria-disabled="true"] {
    cursor: wait;
    opacity: 0.65;
}

.task-card {
    display: grid;
    gap: 3px;
    width: 100%;
    min-height: 44px;
    align-content: center;
    padding: 7px 12px 7px 4px;
    grid-template-columns: minmax(0, 1fr);
    border: 0;
    border-radius: var(--radius-small);
    text-align: left;
    color: var(--color-text);
    background: transparent;
}

.task-card-title {
    font-weight: 650;
    line-height: 1.35;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.task-card-description {
    display: -webkit-box;
    overflow: hidden;
    overflow-wrap: anywhere;
    color: var(--color-text-muted);
    font-size: 0.86rem;
    line-height: 1.45;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.is-completed .task-card {
    color: var(--color-text-muted);
}

.is-completed .task-card-title {
    text-decoration: line-through;
}

.empty-state {
    margin: 6px 0;
    padding: 4px 10px 10px;
    color: var(--color-text-muted);
    font-size: 0.9rem;
    line-height: 1.55;
}

.loading-state,
.error-state {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 120px;
    margin-top: 28px;
    color: var(--color-text-muted);
}

.error-state {
    flex-direction: column;
    color: var(--color-danger);
}

.error-state p {
    margin: 0;
}

.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 700ms linear infinite;
}

.modal {
    width: min(calc(100% - 32px), 480px);
    max-height: calc(100vh - 32px);
    padding: 0;
    border: 0;
    border-radius: var(--radius-large);
    color: var(--color-text);
    background: transparent;
    box-shadow: var(--shadow-soft);
}

.modal::backdrop {
    background: rgb(13 12 25 / 60%);
    backdrop-filter: blur(4px);
}

.modal-card {
    position: relative;
    padding: 34px;
    background: var(--color-surface);
}

.modal-card-wide {
    width: 100%;
}

#task-modal {
    width: min(calc(100% - 32px), 620px);
}

.modal-close {
    position: absolute;
    top: 18px;
    right: 18px;
    display: grid;
    width: 36px;
    height: 36px;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: 50%;
    color: var(--color-text-muted);
    font-size: 1.6rem;
    line-height: 1;
    background: var(--color-surface-muted);
}

.modal-copy {
    margin: 0 0 24px;
    color: var(--color-text-muted);
    line-height: 1.55;
}

.stacked-form {
    display: grid;
    gap: 9px;
}

.stacked-form label:not(.checkbox-field) {
    margin-top: 8px;
    font-size: 0.9rem;
    font-weight: 750;
}

.field-hint,
.save-status {
    margin: 0;
    color: var(--color-text-muted);
    font-size: 0.78rem;
}

.save-status[data-state="saving"] {
    color: var(--color-accent-text);
}

.save-status[data-state="error"] {
    color: var(--color-danger);
}

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    font-weight: 650;
}

.checkbox-field input {
    width: 20px;
    min-height: 20px;
    accent-color: var(--color-primary);
}

.modal-footer {
    justify-content: space-between;
    margin-top: 18px;
}

.form-message {
    margin: 5px 0 0;
    font-size: 0.88rem;
    line-height: 1.45;
}

.form-message-error {
    color: var(--color-danger);
    white-space: pre-line;
}

.app-notice {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 30;
    max-width: min(380px, calc(100% - 40px));
    padding: 14px 18px;
    border-radius: var(--radius-small);
    color: var(--color-surface);
    background: var(--color-text);
    box-shadow: var(--shadow-soft);
}

.is-hidden,
[hidden] {
    display: none !important;
}

.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;
}

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

@media (max-width: 760px) {
    .container {
        width: min(calc(100% - 28px), var(--content-width));
    }

    .button-group .button {
        padding-inline: 13px;
    }
}

@media (max-width: 520px) {
    .brand span:last-child,
    .user-email,
    .theme-toggle span:last-child {
        display: none;
    }

    .header-content {
        gap: 8px;
    }

    .theme-toggle {
        width: 42px;
        justify-content: center;
        padding-inline: 0;
    }

    .welcome-actions,
    .modal-footer {
        align-items: stretch;
        flex-direction: column;
    }

    .welcome-actions .button,
    .modal-footer .button {
        width: 100%;
    }

    .modal-card {
        padding: 30px 22px 24px;
    }
}

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