.note-app button {
    font-family: "Ciname", sans-serif;
}

/* ---------------------------------------------------------------
   Shell — clay page, safe-area aware
--------------------------------------------------------------- */
body.game-page {
    min-height: 100dvh;
    overflow-x: hidden;
    background:
        radial-gradient(circle at 16% 8%, rgba(124, 58, 237, 0.28), transparent 34rem),
        radial-gradient(circle at 84% 16%, rgba(16, 185, 129, 0.22), transparent 30rem),
        linear-gradient(145deg, #0b1022, var(--bg));
    color: var(--text);
}

body.game-page.light-theme {
    background:
        radial-gradient(circle at 16% 8%, rgba(167, 139, 250, 0.3), transparent 34rem),
        radial-gradient(circle at 84% 16%, rgba(52, 211, 153, 0.3), transparent 30rem),
        linear-gradient(145deg, #ecfdf5, #eef2ff);
}

.note-app {
    width: min(94vw, 840px);
    margin-inline: auto;
    padding: 6px 14px calc(22px + env(safe-area-inset-bottom));
    min-height: calc(100vh - 100px);
    min-height: calc(100svh - 100px);
    display: flex;
    flex-direction: column;
    animation: noteFadeIn 0.4s ease;
}

@keyframes noteFadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.note-loading {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    color: var(--muted);
}

/* ---------------------------------------------------------------
   Hero
--------------------------------------------------------------- */
.note-hero {
    text-align: center;
    padding: 26px 16px 22px;
    display: grid;
    justify-items: center;
    gap: 10px;
}

.note-hero-icon {
    display: inline-grid;
    place-items: center;
    width: 78px;
    height: 78px;
    border-radius: 26px;
    background: linear-gradient(145deg, rgba(52, 211, 153, 0.22), rgba(5, 150, 105, 0.08));
    border: 2px solid rgba(255, 255, 255, 0.1);
    color: #34d399;
    box-shadow:
        inset 3px 3px 8px rgba(255, 255, 255, 0.1),
        inset -3px -3px 12px rgba(0, 0, 0, 0.3),
        0 10px 26px rgba(16, 185, 129, 0.22);
    font-size: 2.5rem;
    line-height: 1;
    animation: noteFloat 3s ease-in-out infinite;
}

.note-hero-icon svg {
    width: 40px;
    height: 40px;
}

@keyframes noteFloat {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-7px); }
}

body.light-theme .note-hero-icon {
    color: #059669;
    border-color: rgba(5, 150, 105, 0.2);
    box-shadow:
        inset 3px 3px 8px rgba(255, 255, 255, 0.7),
        inset -3px -3px 12px rgba(5, 150, 105, 0.12),
        0 10px 26px rgba(5, 150, 105, 0.18);
}

.note-hero h1 {
    margin: 0;
    font-size: clamp(1.7rem, 6vw, 2.25rem);
    background: linear-gradient(135deg, #34d399, #059669);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 16px rgba(16, 185, 129, 0.25));
}

.note-hero p {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
}

/* ---------------------------------------------------------------
   Notebook card — paper sheet
--------------------------------------------------------------- */
.note-card {
    background: var(--bg-soft);
    border: 2px solid rgba(255, 255, 255, 0.08);
    border-radius: 30px;
    box-shadow:
        inset 2px 2px 8px rgba(255, 255, 255, 0.07),
        inset -3px -3px 12px rgba(0, 0, 0, 0.28),
        var(--shadow);
    overflow: hidden;
    position: relative;
    transition: box-shadow 0.3s;
    display: flex;
    flex-direction: column;
}

body.light-theme .note-card {
    border-color: rgba(5, 150, 105, 0.14);
    box-shadow:
        inset 2px 2px 8px rgba(255, 255, 255, 0.6),
        inset -3px -3px 12px rgba(5, 150, 105, 0.08),
        var(--shadow);
}

.note-card:focus-within {
    box-shadow:
        inset 2px 2px 8px rgba(255, 255, 255, 0.07),
        inset -3px -3px 12px rgba(0, 0, 0, 0.28),
        0 0 0 3px rgba(52, 211, 153, 0.18),
        0 18px 50px rgba(16, 185, 129, 0.12);
}

body.light-theme .note-card:focus-within {
    box-shadow:
        inset 2px 2px 8px rgba(255, 255, 255, 0.6),
        inset -3px -3px 12px rgba(5, 150, 105, 0.08),
        0 0 0 3px rgba(52, 211, 153, 0.3),
        0 18px 50px rgba(5, 150, 105, 0.12);
}

/* Margin line (RTL paper) */
.note-card::before {
    content: "";
    position: absolute;
    top: 64px;
    right: 42px;
    bottom: 16px;
    width: 2px;
    background: linear-gradient(to bottom, rgba(16, 185, 129, 0.16), transparent 80%);
    pointer-events: none;
    border-radius: 2px;
    z-index: 1;
}

/* ---------------------------------------------------------------
   Card header
--------------------------------------------------------------- */
.note-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 14px 18px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    position: relative;
    z-index: 0;
}

body.light-theme .note-card-header {
    border-bottom-color: rgba(5, 150, 105, 0.1);
}

.note-card-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    min-width: 0;
}

.note-card-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-inline-start: auto;
}

.note-word-count {
    font-size: 0.8rem;
    color: var(--muted);
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, 0.06);
    padding: 5px 14px;
    border-radius: 999px;
    white-space: nowrap;
    display: inline-flex;
    align-items: baseline;
    gap: 3px;
    direction: rtl;
    font-variant-numeric: tabular-nums;
    box-shadow:
        inset 1px 1px 4px rgba(255, 255, 255, 0.06),
        inset -1px -1px 5px rgba(0, 0, 0, 0.2);
}

body.light-theme .note-word-count {
    border-color: rgba(5, 150, 105, 0.12);
}

.note-last-saved {
    font-size: 0.74rem;
    color: var(--muted);
    opacity: 0.75;
    white-space: nowrap;
    display: inline-flex;
    align-items: baseline;
    gap: 2px;
    direction: rtl;
}

.note-last-saved .num {
    font-variant-numeric: tabular-nums;
    color: #34d399;
    font-weight: 600;
}

body.light-theme .note-last-saved .num {
    color: #059669;
}

/* ---------------------------------------------------------------
   Writing area
--------------------------------------------------------------- */
.note-textarea-wrap {
    padding: 14px 16px 12px 14px;
    position: relative;
    flex: 1;
    display: flex;
}

.note-textarea {
    width: 100%;
    min-height: 300px;
    padding: 0 0 0 8px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 1.12rem;
    line-height: 2.1;
    resize: vertical;
    font-family: "Nazanin", sans-serif;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
    scrollbar-width: thin;
    scrollbar-color: var(--panel) transparent;
}

.note-textarea::-webkit-scrollbar { width: 6px; }
.note-textarea::-webkit-scrollbar-track { background: transparent; }
.note-textarea::-webkit-scrollbar-thumb { background: var(--panel); border-radius: 4px; }
.note-textarea::-webkit-scrollbar-thumb:hover { background: var(--muted); }

.note-textarea:focus,
.note-textarea:focus-visible {
    outline: none;
}

.note-textarea::placeholder {
    color: var(--muted);
    opacity: 0.3;
}

/* Empty state watermark */
.note-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    opacity: 0.55;
    cursor: text;
    z-index: 0;
    pointer-events: none;
    border-radius: 24px;
    user-select: none;
    transition: opacity 0.4s ease;
    padding: 20px;
}

.note-empty.hidden {
    opacity: 0;
    pointer-events: none;
}

.note-textarea-wrap:focus-within .note-empty:not(.hidden) {
    opacity: 0.28;
}

.note-empty-icon {
    display: inline-grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border-radius: 22px;
    background: var(--panel);
    border: 2px solid rgba(255, 255, 255, 0.08);
    font-size: 2rem;
    line-height: 1;
    box-shadow:
        inset 2px 2px 6px rgba(255, 255, 255, 0.06),
        inset -2px -2px 8px rgba(0, 0, 0, 0.22);
    color: var(--muted);
    animation: noteFloat 3.4s ease-in-out infinite;
}

body.light-theme .note-empty-icon {
    border-color: rgba(5, 150, 105, 0.14);
}

.note-empty-icon svg {
    width: 30px;
    height: 30px;
}

.note-empty p {
    color: var(--muted);
    font-size: 0.95rem;
    margin: 0;
}

/* ---------------------------------------------------------------
   Footer
--------------------------------------------------------------- */
.note-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 18px calc(16px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

body.light-theme .note-footer {
    border-top-color: rgba(5, 150, 105, 0.1);
}

.note-char-progress {
    flex: 1;
    min-width: 140px;
}

.note-char-track {
    height: 8px;
    border-radius: 999px;
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, 0.06);
    overflow: hidden;
    box-shadow:
        inset 1px 1px 4px rgba(0, 0, 0, 0.3),
        inset -1px -1px 3px rgba(255, 255, 255, 0.05);
}

body.light-theme .note-char-track {
    border-color: rgba(5, 150, 105, 0.12);
    box-shadow:
        inset 1px 1px 4px rgba(5, 150, 105, 0.12),
        inset -1px -1px 3px rgba(255, 255, 255, 0.6);
}

.note-char-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #34d399, #059669);
    transition: width 0.35s ease;
}

.note-char-fill.warn {
    background: linear-gradient(90deg, #f59e0b, #ef4444);
}

.note-char-fill.danger {
    background: #ef4444;
}

.note-char-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--muted);
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}

.note-char-label .over {
    color: var(--danger);
    font-weight: 700;
}

.note-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.note-save-status {
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: opacity 0.3s;
    white-space: nowrap;
    min-width: 96px;
    justify-content: flex-end;
}

.note-save-status .spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.14);
    border-top-color: #34d399;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.note-save-status.saved {
    color: #22c55e;
}

.note-save-status.error {
    color: var(--danger);
}

.note-save-status.idle {
    color: var(--muted);
}

.note-hint {
    font-size: 0.7rem;
    color: var(--muted);
    opacity: 0.45;
    direction: ltr;
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 999px;
    padding: 3px 10px;
}

/* ---------------------------------------------------------------
   Buttons
--------------------------------------------------------------- */
.note-btn {
    background: linear-gradient(135deg, #34d399, #059669);
    color: #fff;
    border: none;
    padding: 10px 24px;
    border-radius: 14px;
    font-size: 0.92rem;
    cursor: pointer;
    font-family: "Ciname", sans-serif;
    min-width: 96px;
    white-space: nowrap;
    min-height: 46px;
    box-shadow:
        inset 2px 2px 6px rgba(255, 255, 255, 0.3),
        inset -2px -3px 8px rgba(0, 0, 0, 0.25),
        0 8px 18px rgba(5, 150, 105, 0.28);
    transition: transform 0.16s ease, filter 0.16s ease, box-shadow 0.16s ease;
    touch-action: manipulation;
}

.note-btn:hover {
    filter: brightness(1.07);
    transform: translateY(-1px);
}

.note-btn:active {
    transform: translateY(1px) scale(0.97);
    box-shadow:
        inset 3px 3px 8px rgba(0, 0, 0, 0.28),
        inset -2px -2px 6px rgba(255, 255, 255, 0.14),
        0 3px 8px rgba(5, 150, 105, 0.2);
}

.note-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    filter: none;
    box-shadow: none;
}

.note-btn:focus-visible,
.note-btn-ghost:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}

.note-btn-ghost {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--muted);
    padding: 8px 14px;
    border-radius: 12px;
    font-size: 0.82rem;
    cursor: pointer;
    font-family: "Nazanin", sans-serif;
    min-height: 44px;
    transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.16s ease;
    opacity: 0.85;
}

.note-btn-ghost:hover {
    background: rgba(52, 211, 153, 0.12);
    border-color: rgba(52, 211, 153, 0.3);
    color: #34d399;
    opacity: 1;
}

body.light-theme .note-btn-ghost:hover {
    color: #059669;
    border-color: rgba(5, 150, 105, 0.3);
    background: rgba(52, 211, 153, 0.1);
}

.note-btn-ghost:active {
    transform: translateY(1px) scale(0.97);
}

/* ---------------------------------------------------------------
   Share modal (base .modal-backdrop handles overlay)
--------------------------------------------------------------- */
.modal-backdrop {
    z-index: 999;
}

.share-modal .modal-close {
    background: none;
    border: none;
    box-shadow: none;
    color: var(--muted);
}

.share-modal .modal-close:hover {
    color: var(--danger);
}

/* ---------------------------------------------------------------
   Tablet ≥ 641px
--------------------------------------------------------------- */
@media (min-width: 641px) {
    .note-app {
        padding: 12px 16px calc(26px + env(safe-area-inset-bottom));
    }

    .note-hero {
        padding: 34px 16px 26px;
    }

    .note-hero-icon {
        width: 88px;
        height: 88px;
        border-radius: 30px;
    }

    .note-hero-icon svg {
        width: 44px;
        height: 44px;
    }

    .note-card-header {
        padding: 16px 26px 12px;
    }

    .note-textarea-wrap {
        padding: 18px 26px 14px 22px;
    }

    .note-textarea {
        min-height: 380px;
        font-size: 1.18rem;
    }

    .note-footer {
        padding: 14px 26px calc(18px + env(safe-area-inset-bottom));
    }

    .note-card::before {
        right: 46px;
    }
}

/* ---------------------------------------------------------------
   Desktop ≥ 1024px
--------------------------------------------------------------- */
@media (min-width: 1024px) {
    .note-app {
        width: min(90vw, 880px);
    }

    .note-textarea {
        min-height: 420px;
    }
}

/* ---------------------------------------------------------------
   Landscape phones (≤ 1023px, landscape)
--------------------------------------------------------------- */
@media (orientation: landscape) and (max-width: 1023px) {
    .note-hero {
        padding: 14px 16px 12px;
        gap: 6px;
    }

    .note-hero-icon {
        width: 58px;
        height: 58px;
        border-radius: 20px;
    }

    .note-hero-icon svg {
        width: 30px;
        height: 30px;
    }

    .note-hero h1 {
        font-size: 1.5rem;
    }

    .note-textarea {
        min-height: 220px;
    }

    .note-app {
        min-height: auto;
    }
}

/* ---------------------------------------------------------------
   Short portrait phones (≤ 1023px, portrait, ≤ 700px tall)
--------------------------------------------------------------- */
@media (max-width: 1023px) and (orientation: portrait) and (max-height: 700px) {
    .note-hero {
        padding: 12px 16px 10px;
        gap: 6px;
    }

    .note-hero-icon {
        width: 56px;
        height: 56px;
        border-radius: 19px;
    }

    .note-hero-icon svg {
        width: 28px;
        height: 28px;
    }

    .note-hero h1 {
        font-size: 1.45rem;
    }

    .note-hero p {
        font-size: 0.85rem;
    }

    .note-textarea {
        min-height: 210px;
        line-height: 2;
        font-size: 1.05rem;
    }

    .note-card-header {
        padding: 10px 14px 8px;
    }

    .note-footer {
        padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
    }

    .note-actions {
        width: 100%;
        justify-content: space-between;
    }

    .note-hint {
        display: none;
    }
}

/* ---------------------------------------------------------------
   Reduced motion
--------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .note-app,
    .note-hero-icon,
    .note-empty-icon,
    .note-char-fill,
    .note-card {
        animation: none;
        transition: none;
    }
}