:root {
    /* Color Palette (Dark Theme) */
    --bg-color: #0f111a;
    --bg-surface: #12141d;
    /* さらに一段階暗くして視認性を最適化 */
    --bg-elevated: #282c3f;
    --text-primary: #f0f2f5;
    --text-secondary: #a0a6b5;
    --text-muted: #6b7280;

    --primary-color: #6366f1;
    /* Indigo */
    --primary-hover: #4f46e5;
    --danger-color: #ef4444;
    --success-color: #10b981;
    --warning-color: #f59e0b;

    --border-color: #374151;
    --border-radius: 12px;
    --transition-speed: 0.15s;

    /* Shadows - reduced */
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.15);

    /* Member Colors */
    --c-saamon: rgba(56, 189, 248, 1);
    --c-jimoreon: rgba(74, 222, 128, 1);
    --c-sanmiritoru: rgba(244, 114, 182, 1);
    --c-zumashii: rgba(161, 98, 7, 1);
    --c-nikuiniku: rgba(248, 113, 113, 1);
    --c-team: rgba(156, 163, 175, 1);

    --z-index-sidebar: 200;
    --z-index-modal: 1000;
    --z-index-overlay: 1500;
}

/* Group Item with Icon Edit */
.group-nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
    position: relative;
    cursor: pointer;
}

.group-nav-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.group-nav-item.active {
    background-color: var(--primary-color);
    color: white;
}

.group-edit-trigger {
    margin-left: auto;
    opacity: 0;
    transition: opacity 0.2s;
    font-size: 1.1rem;
    padding: 2px 5px;
    border-radius: 4px;
}

.group-nav-item:hover .group-edit-trigger {
    opacity: 0.6;
}

.group-edit-trigger:hover {
    opacity: 1 !important;
    background: rgba(255, 255, 255, 0.1);
}

.nav-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 1rem 0.75rem;
    opacity: 0.8;
}

.nav-divider-subtle {
    height: 1px;
    background-color: var(--border-color);
    margin: 0.5rem 0.75rem;
    opacity: 0.2;
}

.form-select {
    width: 100%;
    padding: 0.5rem;
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
}

.form-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Import Options */
.import-option-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem;
    border-bottom: 1px solid var(--border-color);
}

.import-option-item:last-child {
    border-bottom: none;
}

.import-option-item label {
    font-size: 0.9rem;
    cursor: pointer;
    flex-grow: 1;
}

.import-option-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary-color);
}

.import-section-header {
    font-size: 0.75rem;
    font-weight: bold;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.2);
    padding: 0.4rem 0.6rem;
    margin-top: 0.5rem;
    border-radius: 4px;
}


* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
}

/* Utilities */
.hidden {
    display: none !important;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 1rem;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* Overlay & Login */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s;
}

.overlay:not(.active) {
    opacity: 0;
    pointer-events: none;
}

.login-card {
    background-color: var(--bg-surface);
    padding: 2.5rem;
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.login-card h1 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}

.badge {
    background-color: var(--primary-color);
    color: white;
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 9999px;
    font-weight: 600;
    text-transform: uppercase;
    margin-left: 10px
}

.input-group,
.member-select-group {
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

input[type="text"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 0.75rem 1rem;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 16px;
    /* iOS auto-zoom prevention */
    transition: var(--transition-speed);
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: background-color var(--transition-speed);
}

.primary-btn {
    width: 100%;
    padding: 0.75rem 1.5rem;
    background-color: var(--primary-color);
    color: white;
    font-size: 1rem;
}

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

.ghost-btn {
    padding: 0.75rem 1.5rem;
    background-color: transparent;
    color: var(--text-secondary);
}

.ghost-btn:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.error-msg {
    color: var(--danger-color);
    font-size: 0.85rem;
    margin-top: 1rem;
    text-align: center;
    min-height: 1.2rem;
}

/* Sidebar */
.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

.sidebar {
    width: 260px;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.logo-circle {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary-color), #818cf8);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background-color: var(--bg-elevated);
    border-radius: var(--border-radius);
    margin-bottom: 2rem;
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
    font-size: 0.9rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.nav-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0 0.75rem;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    text-decoration: none;
    color: var(--text-secondary);
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.95rem;
    margin-bottom: 0.15rem;
    transition: background-color var(--transition-speed);
    border: 1px solid transparent;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.nav-item.active {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    position: relative;
    font-weight: 600;
}

.color-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.nav-item.drag-over {
    background-color: rgba(99, 102, 241, 0.15);
    border: 1px dashed var(--primary-color);
}

.sidebar-footer {
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    margin-top: 1rem;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-color);
    overflow: hidden;
}

.top-header {
    padding: 1.5rem 2.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.header-title h1 {
    font-size: 1.8rem;
    font-weight: 700;
}

.subtitle {
    color: var(--text-secondary);
    margin-top: 0.25rem;
    font-size: 0.95rem;
}

/* Board Area - Row Based */
.board-container {
    flex: 1;
    padding: 1.5rem 2.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.group-row {
    background-color: transparent;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.group-row-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
}

.group-row-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.group-row-actions button {
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
    background-color: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.group-row-actions button:hover {
    background-color: var(--bg-elevated);
    color: var(--text-primary);
}

.cards-scroller {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-bottom: 1rem;
    padding-top: 0.5rem;
    /* hide items beyond 10 by default via JS class toggle, or we can just let JS handle the DOM. We'll use CSS for now */
}

/* default state: hide items after the 10th (not counting the 'new' card, we'll manage this in JS for better control, so just layout here) */
.cards-scroller:not(.show-all) .memo-card:nth-child(n+11):not(.card-new) {
    display: none;
}

.group-row.expanded .cards-scroller {
    /* override any grid/wrap from before, it's always a list now */
    display: flex;
    flex-direction: column;
}

.group-row.expanded .cards-scroller .memo-card {
    display: flex;
    /* force show all */
}

/* Memo List Item - Unified view and edit */
.memo-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.4rem 0.8rem;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 1rem;
    position: relative;
    width: 100%;
    /* Take full width of container */
    transition: transform 0.1s, box-shadow 0.1s, border-color 0.1s;
}

.archive-checkbox-container {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.archive-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.archive-bulk-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Zebra striping for readability */
.memo-card:nth-child(even):not(.card-new) {
    background-image: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4));
}

.card-index {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--text-muted);
    min-width: 2rem;
    text-align: right;
    padding-right: 0.8rem;
    border-right: 1px solid var(--border-color);
    flex-shrink: 0;
}

.card-saamon {
    border-left: 4px solid var(--c-saamon);
    background: color-mix(in srgb, var(--c-saamon) 2%, var(--bg-surface));
}

.card-jimoreon {
    border-left: 4px solid var(--c-jimoreon);
    background: color-mix(in srgb, var(--c-jimoreon) 2%, var(--bg-surface));
}

.card-sanmiritoru {
    border-left: 4px solid var(--c-sanmiritoru);
    background: color-mix(in srgb, var(--c-sanmiritoru) 2%, var(--bg-surface));
}

.card-zumashii {
    border-left: 4px solid var(--c-zumashii);
    background: color-mix(in srgb, var(--c-zumashii) 2%, var(--bg-surface));
}

.card-nikuiniku {
    border-left: 4px solid var(--c-nikuiniku);
    background: color-mix(in srgb, var(--c-nikuiniku) 2%, var(--bg-surface));
}

.card-team {
    border-left: 4px solid var(--c-team);
    background: color-mix(in srgb, var(--c-team) 3%, var(--bg-surface));
}

.card-new {
    border: 2px dashed var(--border-color);
    background-color: transparent;
    cursor: pointer;
    justify-content: center;
    align-items: center;
    color: var(--text-muted);
    opacity: 0.7;
    padding: 0.1rem 0;
    /* 極力薄くする */
    min-height: 24px;
    /* 通常のテキストアイテムの高さに合わせる */
}

.card-new:hover {
    border-color: var(--text-secondary);
    color: var(--text-primary);
    opacity: 1;
}

.memo-card.view-mode {
    cursor: pointer;
}

.memo-card.view-mode:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    border-right-color: var(--text-muted);
}

@keyframes slideIn {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ---------------------------------
   YMM Style Global Input Bar
--------------------------------- */
/* Expand toggle (hidden by default on desktop, shown on mobile) */
.ymm-expand-toggle {
    display: none;
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--bg-surface);
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}

.ymm-expand-toggle:hover {
    color: var(--text-primary);
}

.ymm-input-body {
    display: contents;
    /* On desktop, acts as if wrapper doesn't exist */
}

.ymm-input-bar {
    display: flex;
    align-items: flex-start;
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    padding: 12px 2.5rem;
    gap: 12px;
    box-shadow: 0 -4px 6px -2px rgba(0, 0, 0, 0.15);
    z-index: 10;
    flex-shrink: 0;
}

.ymm-group-select-wrapper {
    display: flex;
    align-items: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    height: 48px;
    padding-left: 10px;
    flex-shrink: 0;
    min-width: 200px;
    transition: var(--transition-speed);
}

.ymm-group-select-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.ymm-user-indicator {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    margin-right: 10px;
    background-color: var(--primary-color);
}

.ymm-select {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    cursor: pointer;
    font-family: inherit;
    padding: 0 10px 0 0;
    height: 100%;
    width: 100%;
}

.ymm-select option {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.ymm-textarea-wrapper {
    display: flex;
    align-items: flex-start;
    flex-grow: 1;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    min-height: 48px;
    transition: var(--transition-speed);
}

.ymm-textarea-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.ymm-pen-icon {
    padding: 14px 12px;
    font-size: 1rem;
    color: var(--text-muted);
    user-select: none;
}

.ymm-textarea {
    flex-grow: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 12px 12px 12px 0;
    font-size: 1rem;
    line-height: 1.5;
    min-height: 48px;
    max-height: 300px;
    resize: none;
    outline: none;
    font-family: inherit;
    overflow-y: hidden;
}

.ymm-textarea::placeholder {
    color: var(--text-muted);
}

.ymm-btn {
    background: var(--primary-color);
    border: none;
    color: white;
    padding: 0 24px;
    height: 48px;
    line-height: 48px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background-color var(--transition-speed);
    flex-shrink: 0;
}

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

.ymm-btn:active {
    transform: scale(0.98);
}

.memo-card.dragging {
    opacity: 0.4;
}

/* Seamless Inline Editing (WYSIWYG) */
.card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1 1 50%;
    min-width: 150px;
}

/* View Title matches Input Title perfectly */
.card-title,
input[type="text"].inline-input-title {
    font-size: 0.95rem;
    /* 少し小さめに */
    font-weight: 500;
    line-height: 1.4;
    color: var(--text-primary);
    white-space: normal;
    /* 折り返しを有効化 */
    word-break: break-all;
    font-family: inherit;
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    width: 100%;
    box-shadow: none;
    border-radius: 0;
}

input[type="text"].inline-input-title::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

input[type="text"].inline-input-title:focus {
    outline: none;
    border: none;
    box-shadow: none;
    background: transparent;
    padding: 0;
}

.card-badges {
    display: flex;
    gap: 0.4rem;
    position: static;
    flex-shrink: 0;
}

.status-badge {
    font-size: 0.6rem;
    padding: 0.15rem 0.3rem;
    border-radius: 4px;
    font-weight: 600;
    border: 1px solid transparent;
    letter-spacing: 0.05em;
}

.badge-private {
    background-color: rgba(239, 68, 68, 0.15);
    color: var(--danger-color);
    border-color: rgba(239, 68, 68, 0.3);
}

.badge-archived {
    background-color: rgba(107, 114, 128, 0.2);
    color: var(--text-secondary);
    border-color: rgba(107, 114, 128, 0.3);
}

/* View Content matches Textarea exactly */
.card-content,
textarea.inline-input-content {
    color: var(--text-secondary);
    font-size: 0.8rem;
    /* 詳細情報等のサイズを最小化 */
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    font-family: inherit;
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    width: 100%;
    resize: none;
    box-shadow: none;
    border-radius: 0;
    display: block;
}

textarea.inline-input-content {
    min-height: 1.4em;
    height: 1.4em;
    font-size: 0.8rem;
    overflow-y: hidden;
    /* visible to prevent jumping if multi-line is matched by code */
    white-space: nowrap;
}

textarea.inline-input-content::placeholder {
    color: var(--text-muted);
}

textarea.inline-input-content:focus {
    outline: none;
    border: none;
    box-shadow: none;
    background: transparent;
    padding: 0;
    color: var(--text-primary);
}

.card-footer {
    display: flex;
    justify-content: flex-end;
    /* 右寄せによりコンパクトに */
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: none;
    /* 線を消してリストの一部としてなじませる */
    padding-top: 0;
    height: auto;
    gap: 0.5rem;
    flex-shrink: 0;
}

.author-info {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-right: 0;
    /* 左寄せに戻したい場合はこれで離れる */
}

.duplicate-warning-icon {
    font-size: 0.8rem;
    cursor: pointer;
    background: rgba(239, 68, 68, 0.15);
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.2s;
}

.duplicate-warning-icon:hover {
    transform: scale(1.1);
    background: rgba(239, 68, 68, 0.3);
}

.author-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.6rem;
    font-weight: bold;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
}

/* Edit mode specific (toggle, buttons) */
.inline-edit-form {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 1rem;
    height: 100%;
    width: 100%;
}

.inline-edit-form .card-header {
    padding-right: 0;
}

/* Lock icon toggle switch miniature - placed in footer or header */
.mini-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    margin-right: 5px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background-color var(--transition-speed);
}

.mini-toggle:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.mini-toggle input {
    display: none;
}

.lock-icon {
    font-size: 1.2rem;
    opacity: 0.3;
    filter: grayscale(100%);
    transition: all var(--transition-speed);
}

.mini-toggle input:checked+.lock-icon {
    opacity: 1;
    filter: grayscale(0%);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}

.small-btn {
    padding: 0.4rem 0.8rem;
    /* 少し広げた */
    font-size: 0.85rem;
    /* 少し大きくした */
    border-radius: 4px;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    /* 文字が縦にならないように固定 */
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-archive {
    background-color: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

.btn-archive:hover {
    background-color: rgba(245, 158, 11, 0.2);
}

.btn-restore {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    text-align: center;
    grid-column: 1 / -1;
    width: 100%;
}

.empty-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    transition: opacity 0.2s;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-card {
    background-color: var(--bg-surface);
    width: 100%;
    max-width: 500px;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.2rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    line-height: 1;
    padding: 0.2rem;
}

.close-btn:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 0 0 12px 12px;
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* --- Responsive Design --- */
.mobile-header {
    display: none;
    height: 40px;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 0 0.75rem;
    align-items: center;
    gap: 0.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.mobile-logo {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.mobile-only {
    display: none;
}

.sidebar-mask {
    z-index: var(--z-index-overlay) !important;
    background-color: rgba(0, 0, 0, 0.7) !important;
}

@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }

    .mobile-only {
        display: block;
    }

    .app-layout {
        display: block;
        overflow-x: hidden;
        width: 100vw;
        max-width: 100vw;
    }

    html {
        overflow-x: hidden;
    }

    body {
        overflow-x: hidden;
        width: 100%;
        max-width: 100vw;
        touch-action: pan-y;
        overscroll-behavior-x: none;
    }

    .main-content {
        overflow-x: hidden;
        max-width: 100vw;
    }

    .board-container {
        overflow-x: hidden;
    }

    .memo-card {
        max-width: 100%;
        overflow: hidden;
        word-break: break-word;
    }

    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: var(--z-index-sidebar);
        transition: left 0.3s ease;
        background-color: var(--bg-surface);
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
    }

    .sidebar.open {
        left: 0;
    }

    /* --- Mobile: Header compact --- */
    .top-header {
        padding: 0.75rem 1rem;
    }

    .header-title h1 {
        font-size: 1.15rem;
    }

    .subtitle {
        font-size: 0.8rem;
        display: none;
        /* Hide subtitle on mobile to save space */
    }

    /* --- Mobile: Board area --- */
    .board-container {
        padding: 0.75rem;
        gap: 1.25rem;
    }

    .group-row {
        gap: 0.4rem;
    }

    .group-row-header {
        padding-bottom: 0.4rem;
    }

    .group-row-title {
        font-size: 1rem;
    }

    .group-row-actions button {
        font-size: 0.7rem;
        padding: 0.3rem 0.6rem;
    }

    .cards-scroller {
        gap: 0.35rem;
        padding-bottom: 0.5rem;
        padding-top: 0.25rem;
    }

    /* --- Mobile: Memo card optimization --- */
    .memo-card {
        padding: 0.5rem 0.6rem;
        gap: 0.5rem;
        border-radius: 8px;
        font-size: 0.9rem;
        max-width: 100%;
        overflow: hidden;
        box-sizing: border-box;
    }

    .card-index {
        display: none;
    }

    /* Hide author name, keep only avatar icon */
    .author-info span {
        display: none;
    }

    .author-info {
        flex-shrink: 0;
    }

    .card-footer {
        flex-shrink: 0;
        max-width: 100%;
        overflow: hidden;
    }

    .card-header {
        min-width: 0;
        overflow: hidden;
    }

    .card-title {
        white-space: normal;
        word-break: break-all;
    }

    .memo-card .inline-input-title,
    .memo-card .card-title-text {
        font-size: 0.9rem;
    }

    .memo-card .card-author-badge {
        font-size: 0.7rem;
        padding: 0.15rem 0.4rem;
    }

    .card-new {
        min-height: 36px;
        font-size: 0.85rem;
    }

    /* --- Mobile: Hide input bar entirely --- */
    .ymm-input-bar {
        display: none !important;
    }

    .ymm-input-bar.expanded .ymm-expand-toggle {
        border-bottom: 1px solid var(--border-color);
    }

    .ymm-group-select-wrapper {
        min-width: unset;
        width: 100%;
        height: 36px;
    }

    .ymm-textarea-wrapper {
        width: 100%;
        min-height: 36px;
    }

    .ymm-textarea {
        min-height: 36px;
        font-size: 0.9rem;
    }

    .ymm-btn {
        width: 100%;
        height: 38px;
        line-height: 38px;
        font-size: 0.9rem;
    }

    .ymm-pen-icon {
        padding: 8px 8px;
    }

    /* --- Mobile: Main content layout --- */
    .main-content {
        height: calc(100vh - 40px);
        /* Subtract thin mobile header */
        overflow: hidden;
    }

    .board-grid {
        grid-template-columns: 1fr !important;
    }

    .modal-content,
    .modal-card {
        width: 95% !important;
        margin: 10px auto;
    }

    .login-card {
        width: 90% !important;
        margin: 20px auto;
    }
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 150;
}

.sidebar-overlay.hidden {
    display: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.app-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.app-logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
}