body {
    font-family: Calibri, "Segoe UI", Tahoma, Arial, sans-serif;

    --border-color: #e3e7ee;
    --gray-100: #f3f5f8;
    --gray-500: #6b7280;
    --gray-700: #1f2937;
    --primary-100: #dbeafe;
    --primary-200: #bfdbfe;
    --primary-400: #3b82f6;
    --primary-500: #2563eb;
    --primary-600: #1d4ed8;
    --error-500: #e11d48;
    --error-100: #ffe4e6;
    --surface: #fff;
}

/*
    Josh's Custom CSS Reset
    https://www.joshwcomeau.com/css/custom-css-reset/
  */
*,
*::before,
*::after {
    box-sizing: border-box;
}

* {
    margin: 0;
}

body {
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    background-color: #f5f7fb;
    color: var(--gray-700);
}

img,
picture,
video,
canvas,
svg {
    display: block;
    max-width: 100%;
}

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

p,
h1,
h2,
h3,
h4,
h5,
h6 {
    overflow-wrap: break-word;
}

#root,
#__next {
    isolation: isolate;
}

/*
    Common components - mobile-first touch targets (min 44px)
  */
button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    border: 0;
    background-color: var(--primary-500);
    border-radius: 50px;
    color: #fff;
    padding: 10px 18px;
    cursor: pointer;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

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

button:focus-visible,
.button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 3px solid var(--primary-200);
    outline-offset: 2px;
}

/* Ensure choice buttons have visible text - override any inherited styles */
.choice-button {
    color: var(--gray-700) !important;
    background-color: var(--surface) !important;
}

/*
    Custom components
  */
.error {
    background-color: var(--error-100);
    color: var(--error-500);
    text-align: center;
    padding: 1rem;
    display: none;
}

.error.visible {
    display: block;
}

.site-header {
    background-color: var(--surface);
    border-bottom: 0;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.05);
    padding: 0.5rem 1rem 1rem;
}

.site-header__bar {
    display: grid;
    grid-template-columns: 48px 1fr 120px;
    align-items: center;
    gap: 12px;
    max-width: 900px;
    margin: 0 auto;
}

.site-header__center {
    text-align: center;
}

.site-title {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    color: inherit;
    font-size: 1.5rem;
    font-weight: 700;
}

.site-logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
    flex: 0 0 auto;
}

@media (min-width: 480px) {
    .site-title {
        font-size: 2rem;
        gap: 10px;
    }
    .site-logo {
        width: 56px;
        height: 56px;
    }
}

@media (min-width: 720px) {
    .site-title {
        font-size: 2.5rem;
    }
    .site-logo {
        width: 64px;
        height: 64px;
    }
}

.site-title__text {
    display: inline-block;
    line-height: 1;
}

.profile-chip {
    display: inline-flex;
    min-height: 44px;
    height: 44px;
    border-radius: 999px;
    align-items: center;
    justify-content: center;
    background: var(--gray-100);
    border: 1px solid var(--border-color);
    text-decoration: none;
    overflow: hidden;
    gap: 4px;
    padding: 0 8px 0 2px;
}

.profile-avatar {
    width: 34px;
    height: 34px;
    object-fit: cover;
    border-radius: 999px;
}

.profile-placeholder {
    font-size: 1.25rem;
}

.menu {
    position: relative;
    display: inline-flex;
    justify-content: flex-end;
}

.menu-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background-color: var(--surface);
    cursor: pointer;
    padding: 4px 10px;
}

.menu-arrow {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.menu-list {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 160px;
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    display: none;
    z-index: 20;
}

.menu--open .menu-list {
    display: block;
}

.menu-item {
    display: flex;
    width: 100%;
    align-items: center;
    min-height: 44px;
    gap: 8px;
    border: 0;
    background: transparent;
    text-decoration: none;
    color: inherit;
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    -webkit-tap-highlight-color: transparent;
}

.menu-item:hover {
    background-color: var(--gray-100);
}

.lang-trigger {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
    padding: 0;
    justify-content: center;
    position: relative;
}

.lang-option--active {
    background-color: var(--primary-100);
}

.profile-menu .menu-trigger {
    padding: 4px 10px 4px 4px;
}

.profile-menu .menu-list {
    left: 0;
    right: auto;
}

.lang-trigger .menu-arrow {
    position: absolute;
    bottom: 4px;
    right: 6px;
    font-size: 0.6rem;
}

#header {
    background-color: var(--surface);
    text-align: center;
    padding: 0.5rem 0 1.5rem;
}

#header h1 {
    font-size: 2.5rem;
}

h1 {
    font-size: 2rem;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.25rem;
}

.container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 0 auto;
    max-width: 680px;
    padding: 16px;
}

@media (min-width: 480px) {
    .container {
        padding: 20px;
    }
}

@supports (padding: max(0px)) {
    .container {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
}

.card {
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 16px 18px;
    background-color: var(--surface);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
}

.card> :first-child {
    margin-top: 0;
}

.card> :last-child {
    margin-bottom: 0;
}

.session-form {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.login-form {
    display: flex;
    flex-direction: row;
    gap: 6px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px 16px;
    background-color: var(--surface);
}

.login-form input {
    flex: 1;
    border: 0;
}

.status-options {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0;
}

.status-option {
    font-size: 2rem;
    width: 3rem;
    height: 3rem;
    padding: 0;
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 3rem;
    text-align: center;
    box-shadow: 0 1px 4px #0001;
    cursor: pointer;
}

.status-option:hover {
    background-color: var(--primary-100);
    box-shadow: 0 0 0 1px var(--primary-400);
}

.status-option.selected {
    box-shadow: 0 0 0 1px var(--primary-500);
    background-color: var(--primary-100);
}

.status-option.selected:hover {
    background-color: var(--primary-200);
}

.status-line {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    position: relative;
    margin-top: 15px;
}

.status-line:not(.no-line)::before {
    content: '';
    position: absolute;
    width: 2px;
    background-color: var(--border-color);
    left: 1.45rem;
    bottom: calc(100% + 2px);
    height: 15px;
}

.status-line .status {
    font-size: 2rem;
    background-color: var(--surface);
    width: 3rem;
    height: 3rem;
    border-radius: 1.5rem;
    text-align: center;
    border: 1px solid var(--border-color);
}

.status-line .desc {
    color: var(--gray-500);
}

.status-line .author {
    color: var(--gray-700);
    font-weight: 600;
    text-decoration: none;
}

.status-line .author:hover {
    text-decoration: underline;
}

.site-footer {
    display: flex;
    flex-direction: column;
    gap: 6px;
    justify-content: center;
    align-items: center;
    padding: 20px 0 40px;
    color: var(--gray-500);
    font-size: 0.95rem;
}

.site-footer__row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.site-footer__row--support {
    flex-basis: 100%;
    display: block;
    text-align: center;
    margin-top: 6px;
}

.site-footer a {
    color: var(--gray-500);
    text-decoration: none;
}

.site-footer a:hover {
    text-decoration: underline;
}

.footer-sep {
    color: var(--gray-500);
}

.button-secondary {
    background-color: var(--surface);
    color: var(--gray-700);
    border: 1px solid var(--border-color);
}

.button-secondary:hover {
    background-color: var(--gray-100);
}

.button.small {
    min-height: 36px;
    min-width: 36px;
    padding: 6px 12px;
}

@media (min-width: 720px) {
    .button.small {
        min-height: 32px;
        min-width: 32px;
        padding: 4px 10px;
    }
}

.cookie-banner {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--surface);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
    padding: 14px 20px;
    z-index: 1000;
}

.cookie-banner--hidden {
    display: none;
}

.cookie-banner__content {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cookie-banner__text {
    color: var(--gray-700);
    font-size: 0.95rem;
}

.cookie-banner__actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

@media (min-width: 720px) {
    .cookie-banner__content {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}

.signup-cta {
    text-align: center;
    text-wrap: balance;
    margin-top: 1rem;
}

/* Form styles */
.deck-form,
form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 600;
    color: var(--gray-700);
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group textarea,
.form-group select {
    min-height: 44px;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 16px;
    width: 100%;
    background-color: var(--surface);
}

.form-group textarea {
    min-height: 120px;
}

.form-group input[type="text"]:focus,
.form-group input[type="url"]:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 2px var(--primary-100);
}

.form-group textarea {
    resize: vertical;
}

.help-text {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}

.button-group {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

@media (max-width: 479px) {
    .button-group {
        gap: 0.5rem;
    }
}

.button.primary {
    background-color: var(--primary-500);
    font-weight: 600;
}

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

.button.danger {
    background-color: #dc3545;
}

.button.danger:hover {
    background-color: #c82333;
}

/* Deck cards */
.decks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.deck-card {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    background-color: var(--surface);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    position: relative;
}

.deck-card:hover {
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.12);
    transform: translateY(-2px);
}

.deck-card h3 {
    margin-top: 0;
    margin-bottom: 0.5rem;
    color: var(--gray-700);
    padding-right: 36px;
}

.deck-description {
    color: var(--gray-500);
    font-size: 0.9rem;
    margin-bottom: 1rem;
    min-height: 3em;
}

.deck-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
    align-items: center;
}

.deck-actions .button {
    flex: 1 1 auto;
    min-width: 0;
    border-radius: 12px;
    padding: 8px 14px;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}

@media (min-width: 480px) {
    .deck-actions .button {
        flex: 0 0 auto;
    }
}

.pin-button {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    border: 0;
    background: transparent;
    padding: 0;
    color: var(--gray-500);
}

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

.pin-button::before,
.pin-button::after {
    content: "";
    position: absolute;
    inset: 2px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

.pin-button::before {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M12 2c2.2 0 4 1.8 4 4 0 1.6-1 3-2.5 3.6L12 22 10.5 9.6C9 9 8 7.6 8 6c0-2.2 1.8-4 4-4z'/></svg>");
}

.pin-button::after {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'><path d='M12 2c2.2 0 4 1.8 4 4 0 1.6-1 3-2.5 3.6L12 22 10.5 9.6C9 9 8 7.6 8 6c0-2.2 1.8-4 4-4z'/></svg>");
    opacity: 0;
}

.pin-button--active {
    color: var(--primary-500);
}

.pin-button--active::after {
    opacity: 1;
}

.deck-card--placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 170px;
    border: 2px dashed var(--border-color);
    background: var(--gray-100);
    text-decoration: none;
    color: var(--gray-500);
}

.deck-card--placeholder:hover {
    border-color: var(--primary-400);
    color: var(--primary-500);
    background: var(--primary-100);
}

.deck-card__plus {
    font-size: 2rem;
    line-height: 1;
}

.deck-card__label {
    font-weight: 600;
}

.learning-search {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0.75rem 0 1.25rem;
}

.learning-search label {
    font-weight: 600;
    color: var(--gray-700);
}

.learning-search input {
    min-height: 44px;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface);
}

.share-menu .menu-trigger {
    border: 1px solid var(--border-color);
    padding: 8px 14px;
}

.learning-section {
    padding-top: 0.25rem;
}

.learning-section + .learning-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.learning-section__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.learning-section__header h3 {
    margin: 0;
}

.muted {
    color: var(--gray-500);
}

.prose {
    max-width: 100%;
}

.prose h2,
.prose h3,
.prose h4 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

.prose p,
.prose ul,
.prose ol {
    margin-top: 0.5rem;
    margin-bottom: 0.75rem;
}

.prose ul,
.prose ol {
    padding-left: 1.25rem;
}

.prose code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.95em;
}

.prose pre {
    margin: 0.75rem 0;
    padding: 0.75rem;
    background: var(--gray-100);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow-x: auto;
    max-width: 100%;
}

.prose pre code {
    display: block;
    white-space: pre;
    word-break: normal;
    overflow-wrap: normal;
}

.section {
    max-width: 900px;
    margin: 0 auto;
}

.table-wrapper {
    width: 100%;
    overflow-x: auto;
}

.deck-table,
.items-table {
    width: 100%;
    border-collapse: collapse;
}

.deck-table th,
.deck-table td,
.items-table th,
.items-table td {
    padding: 0.75rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
}

@media (max-width: 479px) {
    .deck-table th,
    .deck-table td,
    .items-table th,
    .items-table td {
        padding: 0.5rem 0.35rem;
    }
}

.deck-table th,
.items-table th {
    font-size: 0.9rem;
    color: var(--gray-500);
    font-weight: 600;
}

.list .card {
    box-shadow: none;
}

/* Better form styling */
.deck-form {
    max-width: 600px;
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group textarea {
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input[type="text"]:hover,
.form-group input[type="url"]:hover,
.form-group textarea:hover {
    border-color: var(--gray-500);
}

/* Study mode styles */
.study-item {
    margin-bottom: 1rem;
}

.study-question h2 {
    margin-top: 0;
    margin-bottom: 1rem;
}

.prompt {
    margin-bottom: 1.5rem;
}

.prompt p {
    font-size: 1.1rem;
    line-height: 1.6;
}

.multiple-choice-options {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin: 1rem 0;
}

.choice-button {
    width: 100%;
    min-height: 48px;
    padding: 1rem 1.25rem;
    text-align: left;
    background-color: var(--surface);
    color: var(--gray-700);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
    -webkit-tap-highlight-color: transparent;
}

.choice-button:hover {
    background-color: var(--primary-100);
    border-color: var(--primary-400);
}

.choice-button.selected {
    background-color: var(--primary-200);
    border-color: var(--primary-500);
    font-weight: 600;
}

.study-answer {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--border-color);
}

.study-answer h3 {
    margin-top: 0;
    color: var(--gray-700);
}

.answer-feedback {
    margin: 1rem 0;
    padding: 1rem;
    border-radius: 6px;
}

.answer-feedback.correct {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.answer-feedback.incorrect {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

#study-progress {
    text-align: center;
    font-size: 1.1rem;
    color: var(--gray-500);
}

#study-progress span {
    font-weight: 600;
    color: var(--gray-700);
}

#study-complete {
    text-align: center;
}

#study-complete h2 {
    color: var(--primary-500);
    margin-bottom: 1rem;
}

/* Study item badges: review, new, crossover */
.item-badges .badge {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-weight: 500;
}
.badge-review {
    background: var(--primary-100);
    color: var(--primary-600);
}
.badge-new {
    background: #e8f5e9;
    color: #2e7d32;
}
.badge-crossover {
    background: #fff3e0;
    color: #e65100;
}