:root {
    color-scheme: light;
    --bg: #f4f7fb;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --text: #172033;
    --muted: #657287;
    --line: #dce3ee;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --accent: #b4b4b4;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --shadow: 0 18px 50px rgba(23, 32, 51, 0.12);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    min-height: 100vh;
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.10), transparent 28%),
    linear-gradient(315deg, rgba(245, 158, 11, 0.16), transparent 30%),
    var(--bg);
}

.app {
    width: calc(100% - 32px);
    margin: 0 auto;
    padding: 36px 0 48px;
}

header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

h1 {
    margin: 0;
    font-size: clamp(2.4rem, 7vw, 4.8rem);
    line-height: 0.95;
    letter-spacing: 0;
}

.subtitle {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 1.08rem;
}

.header-tools {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
    max-width: 520px;
}

.code-pill,
.count {
    min-height: 40px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.78);
    color: var(--muted);
    font-weight: 700;
    box-shadow: 0 8px 24px rgba(23, 32, 51, 0.06);
}

.code-pill {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    user-select: none;
    transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease, border-color 140ms ease;
}

.code-pill:hover {
    transform: translateY(-1px);
    background: #ffffff;
    border-color: var(--primary);
    box-shadow: 0 8px 18px rgba(23, 32, 51, 0.08);
}

.code-pill:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.32);
    outline-offset: 2px;
}

.code-pill-label {
    color: var(--muted);
    font-weight: 600;
}

.code-pill strong {
    color: var(--text);
}

.code-action-btn {
    padding: 0 12px;
    font-weight: 600;
    font-size: 0.9rem;
}

.composer {
    display: grid;
    gap: 14px;
    margin-bottom: 24px;
    padding: 16px;
    border: 1px solid rgba(220, 227, 238, 0.9);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.84);
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px);
}

.search-input {
    width: 100%;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.84);
    padding: 0 12px;
    font: inherit;
}

.composer.is-editing {
    border-color: rgba(37, 99, 235, 0.52);
    box-shadow: 0 18px 50px rgba(37, 99, 235, 0.16);
}

textarea,
.code-input, .search-input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel-soft);
    color: var(--text);
    font: inherit;
    outline: none;
    transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

textarea {
    min-height: 58px;
    max-height: 260px;
    resize: none;
    overflow-y: hidden;
    padding: 14px 15px;
    line-height: 1.5;
}

.code-input {
    height: 48px;
    padding: 0 14px;
    font-weight: 700;
}

textarea:focus,
.code-input:focus, .search-input:focus {
    border-color: var(--primary);
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.14);
}

textarea::placeholder,
.code-input::placeholder {
    color: #8a97aa;
}

.composer-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.composer-image {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 12px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel-soft);
}

.composer-image img {
    width: 100%;
    max-height: 260px;
    border-radius: 6px;
    object-fit: contain;
    background: #ffffff;
}

.composer-error {
    margin: 0;
    color: #991b1b;
    font-size: 0.92rem;
    font-weight: 650;
}

button {
    min-height: 40px;
    border: 0;
    border-radius: var(--radius);
    padding: 0 8px;
    cursor: pointer;
    font: inherit;
    font-weight: 500;
    transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease, color 140ms ease;
}

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

button:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.32);
    outline-offset: 2px;
}

.primary-button {
    background: var(--primary);
    color: #ffffff;
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.24);
}

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

.ghost-button {
    border: 1px solid var(--line);
    background: #ffffff;
    color: var(--text);
}

.ghost-button:hover {
    background: #f8fafc;
    box-shadow: 0 8px 18px rgba(23, 32, 51, 0.08);
}

.danger-button {
    border: 1px solid #fecaca;
    background: var(--danger-bg);
    color: var(--danger);
}

.danger-button:hover {
    background: #fee2e2;
    box-shadow: 0 8px 18px rgba(220, 38, 38, 0.12);
}

.icon-button {
    min-width: 36px;
    min-height: 36px;
    padding: 0;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--line);
    background: #fff;
}

.notes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 8px;
}

.note-card {
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 14px;
    min-height: 180px;
    padding: 16px;
    border: 1px solid rgba(220, 227, 238, 0.88);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.86);
    box-shadow: 0 10px 30px rgba(23, 32, 51, 0.05);
    backdrop-filter: blur(10px);
}

.note-text {
    line-height: 1.6;
    word-break: break-word;
    font-size: 0.96rem;
}

.markdown-body {
    word-break: break-word;
    overflow-wrap: anywhere;
}

.markdown-body>*:first-child {
    margin-top: 0;
}

.markdown-body>*:last-child {
    margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    margin: 1rem 0 0.5rem;
    line-height: 1.25;
}

.markdown-body h1 {
    font-size: 1.5rem;
}

.markdown-body h2 {
    font-size: 1.3rem;
}

.markdown-body h3 {
    font-size: 1.15rem;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote {
    margin: 0.6rem 0;
}

.markdown-body ul,
.markdown-body ol {
    padding-left: 1.4rem;
}

.markdown-body li+li {
    margin-top: 0.25rem;
}

.markdown-body a {
    color: var(--primary);
    text-decoration: underline;
}

.markdown-body code {
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    background: #eef2f6;
    font-size: 0.88em;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.markdown-body pre {
    overflow-x: auto;
    padding: 12px;
    border-radius: 6px;
    background: #111827;
    color: #f9fafb;
}

.markdown-body pre code {
    padding: 0;
    background: transparent;
    color: inherit;
}

.markdown-body blockquote {
    margin-left: 0;
    margin-right: 0;
    padding-left: 12px;
    border-left: 3px solid var(--accent);
    color: var(--muted);
}

.markdown-body hr {
    height: 1px;
    margin: 1rem 0;
    border: 0;
    background: var(--line);
}

.task-list-item {
    list-style: none;
}

.task-list-item input {
    margin: 0 0.5rem 0 -1.3rem;
    vertical-align: middle;
}

.note-image {
    width: 100%;
    max-height: 280px;
    border: 1px solid var(--line);
    border-radius: 6px;
    object-fit: contain;
    background: var(--panel-soft);
}

.note-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    align-self: end;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.note-date {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 650;
}

.note-actions {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.empty,
.error {
    grid-column: 1 / -1;
    padding: 28px 18px;
    border: 1px dashed #b8c4d6;
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.7);
    color: var(--muted);
    text-align: center;
}

.error {
    border-color: #fecaca;
    background: #fff5f5;
    color: #991b1b;
}

.code-gate {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(244, 247, 251, 0.78);
    backdrop-filter: blur(14px);
}

.code-card {
    width: min(440px, 100%);
    display: grid;
    gap: 14px;
    padding: 22px;
    border: 1px solid rgba(220, 227, 238, 0.95);
    border-radius: var(--radius);
    background: #ffffff;
    box-shadow: var(--shadow);
}

.code-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.code-card-header h2 {
    margin: 0;
    font-size: 1.45rem;
    letter-spacing: 0;
}

.code-card p {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
    line-height: 1.5;
}

.current-code-badge {
    padding: 10px 14px;
    border-radius: var(--radius);
    background: var(--panel-soft);
    border: 1px solid var(--line);
    font-size: 0.95rem;
    color: var(--muted);
}

.current-code-badge strong {
    color: var(--primary);
    word-break: break-all;
}

.code-card-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.note-modal {
    width: calc(100% - 32px);
    max-height: min(84vh, 760px);
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
}

.note-modal::backdrop {
    background: rgba(23, 32, 51, 0.36);
    backdrop-filter: blur(8px);
}

.note-modal-panel {
    display: grid;
    gap: 16px;
    max-height: inherit;
    padding: 18px;
    border: 1px solid rgba(220, 227, 238, 0.95);
    border-radius: var(--radius);
    background: #ffffff;
    box-shadow: var(--shadow);
}

.note-modal-header,
.note-modal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.note-modal-header h2 {
    margin: 0;
    font-size: 1.28rem;
    letter-spacing: 0;
}

.note-modal-date {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 650;
}

.note-modal-text {
    max-height: min(56vh, 520px);
    margin: 0;
    overflow: auto;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel-soft);
    overflow-wrap: anywhere;
    line-height: 1.6;
}

.note-modal-image {
    width: 100%;
    max-height: min(48vh, 480px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    object-fit: contain;
    background: var(--panel-soft);
}

.note-modal-actions {
    justify-content: flex-end;
}

.undo-toast {
    position: fixed;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow);
    max-width: calc(100% - 32px);
    font-weight: 500;
}

@media (max-width: 640px) {
    .app {
    width: min(100% - 20px, 980px);
    padding-top: 22px;
    }

    header {
    align-items: flex-start;
    flex-direction: column;
    }

    .composer-actions,
    .note-footer,
    .primary-button {
    width: 100%;
    }

    .composer-actions,
    .note-footer {
    align-items: stretch;
    flex-direction: column;
    }

    .composer-actions button {
    width: 100%;
    }

    .composer {
    padding: 12px;
    }

    .composer-image {
    grid-template-columns: 1fr;
    }

    .composer-image button {
    width: 100%;
    }

    .note-actions {
    width: 100%;
    }

    .note-actions button {
    flex: 1;
    }

    .note-modal-header,
    .note-modal-actions {
    align-items: stretch;
    flex-direction: column;
    }

    .note-modal-actions button {
    width: 100%;
    }

    .code-card-actions {
        flex-direction: column;
    }

    .code-card-actions button {
        width: 100%;
    }
}

.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
}

.header-tools,
.composer-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.search-wrap {
  flex: 1;
  display: flex;
  justify-content: center;
}

.search-input {
  width: 100%;
  max-width: 500px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid #ddd;
}
