:root {
    --bg: #0f1115;
    --bg2: #1b212c;
    --card: rgba(18, 22, 29, 0.8);
    --line: rgba(255, 255, 255, 0.16);
    --text: #ece8dd;
    --sub: #b9b3a6;
    --accent: #d15f34;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
    background: radial-gradient(circle at 15% 15%, #2c3442, transparent 40%), linear-gradient(150deg, var(--bg), var(--bg2));
}

.bg-noise {
    position: fixed;
    inset: 0;
    background-image: repeating-radial-gradient(circle at 0 0, transparent 0, rgba(255, 255, 255, 0.03) 1px, transparent 2px);
    pointer-events: none;
}

.page-wrap {
    position: relative;
    max-width: 920px;
    margin: 0 auto;
    padding: 2rem 1rem 4rem;
}

.hero h1 {
    margin: 0;
    font-size: clamp(2rem, 6vw, 3.6rem);
    letter-spacing: 0.06em;
}

.eyebrow {
    margin: 0;
    color: var(--sub);
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.8rem;
}

.meta {
    color: var(--sub);
}

.diary {
    margin-top: 1.5rem;
    padding: 1.5rem;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--card);
    line-height: 1.9;
    font-size: 1.05rem;
}

.diary span[data-post-id] {
    border-bottom: 1px dashed var(--accent);
    cursor: help;
}

.composer {
    margin-top: 1.5rem;
    padding: 1.25rem;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: var(--card);
}

.demo-tools {
    margin-top: 1.5rem;
    padding: 1.25rem;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: var(--card);
}

.demo-note {
    margin: 0.2rem 0 0.8rem;
    color: var(--sub);
}

label {
    display: block;
    margin-top: 0.8rem;
    margin-bottom: 0.3rem;
    color: var(--sub);
}

input,
textarea {
    width: 100%;
    background: rgba(5, 8, 12, 0.5);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 10px;
    padding: 0.75rem;
    font: inherit;
}

textarea {
    min-height: 90px;
    resize: vertical;
}

button {
    margin-top: 0.9rem;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(120deg, #de8650, var(--accent));
    color: #fff;
    padding: 0.7rem 1.15rem;
    font-weight: 700;
    cursor: pointer;
}

.post-message {
    min-height: 1.4rem;
    color: var(--sub);
}

.hover-card {
    position: fixed;
    max-width: min(320px, calc(100vw - 1rem));
    padding: 0.8rem;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: rgba(8, 10, 15, 0.95);
    color: #f4ede3;
    z-index: 10;
}

.hover-title {
    margin: 0 0 0.4rem;
    font-size: 0.8rem;
    color: var(--sub);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
}

.modal.is-open {
    opacity: 1;
    pointer-events: auto;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}

.modal-panel {
    position: relative;
    width: min(740px, 100%);
    max-height: 80vh;
    overflow: auto;
    padding: 1.1rem;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: rgba(9, 11, 16, 0.96);
}

.modal-panel h2 {
    margin-top: 0;
    margin-bottom: 0.4rem;
}

.modal-meta {
    margin: 0 0 0.9rem;
    color: var(--sub);
}

.modal-text {
    white-space: pre-wrap;
    line-height: 1.85;
    border-top: 1px solid var(--line);
    padding-top: 0.9rem;
}

@media (max-width: 640px) {
    .page-wrap {
        padding: 1.25rem 0.8rem 3rem;
    }

    .diary,
    .composer,
    .demo-tools {
        padding: 1rem;
    }

    .modal-panel {
        max-height: 85vh;
    }

    .reader-head-actions {
        width: 100%;
    }

    .reader-nav-btn,
    .reader-other-btn {
        width: auto;
    }

    .diary-paper {
        padding: 1.1rem 0.95rem;
    }

    .reader-sticky {
        top: 0.35rem;
        padding: 0.5rem;
    }

    .home-modal-panel .modal-text {
        font-size: 0.95rem;
        line-height: 1.72;
    }
}

body.home {
    position: relative;
    overflow-x: hidden;
    color: #23201a;
    background:
        radial-gradient(120% 92% at 50% 50%, rgba(247, 246, 242, 0.96) 0%, rgba(234, 231, 224, 0.9) 36%, rgba(208, 202, 191, 0.88) 65%, rgba(167, 158, 145, 0.86) 100%),
        radial-gradient(88% 70% at 50% 50%, rgba(0, 0, 0, 0) 45%, rgba(66, 59, 51, 0.26) 100%);
}

body.home::before,
body.home::after {
    content: "";
    position: fixed;
    inset: -12vmax;
    pointer-events: none;
}

body.home::before {
    z-index: 0;
    background: radial-gradient(closest-side at 50% 52%, rgba(255, 255, 255, 0) 30%, rgba(98, 90, 80, 0.19) 100%);
}

body.home::after {
    z-index: 0;
    opacity: 0.42;
    filter: blur(24px);
    background:
        radial-gradient(46vmax 32vmax at 10% 18%, rgba(187, 184, 178, 0.38), rgba(187, 184, 178, 0) 62%),
        radial-gradient(52vmax 35vmax at 88% 82%, rgba(158, 152, 143, 0.34), rgba(158, 152, 143, 0) 66%);
    animation: fog-drift 16s ease-in-out infinite alternate;
}

body.home .bg-noise {
    z-index: 1;
    opacity: 0.55;
    background-image: repeating-linear-gradient(0deg, rgba(20, 16, 14, 0.03) 0, rgba(20, 16, 14, 0.03) 1px, transparent 2px, transparent 4px);
}

.home-wrap {
    position: relative;
    z-index: 2;
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding-top: 3rem;
}

.home-wrap.reader-mode {
    place-items: start;
    max-width: 980px;
    padding-top: 1.2rem;
}

.home-card {
    position: relative;
    width: min(760px, 100%);
    padding: 1rem 1.2rem;
    text-align: center;
}

.home-subtitle {
    margin: 0;
    font-size: 0.88rem;
    letter-spacing: 0.06em;
    color: #61584b;
}

.home-ruby {
    margin: 0.5rem 0 0;
    font-size: 0.8rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: #8d6b62;
}

.home-ruby-ai {
    color: #ff2525;
}

.home-title {
    margin: 0.15rem 0 0;
    font-size: clamp(2rem, 7vw, 4rem);
    letter-spacing: 0.08em;
}

.home-copy {
    margin: 0.8rem 0 0;
    color: #4e4538;
}

.home-actions {
    margin-top: 1.5rem;
    display: grid;
    gap: 0.65rem;
    justify-items: center;
}

.home-btn {
    display: block;
    width: min(460px, 100%);
    text-align: center;
    text-decoration: none;
    color: #2c241f;
    border: 1px solid rgba(48, 39, 31, 0.25);
    border-radius: 999px;
    padding: 0.8rem 1rem;
    font-weight: 700;
    background: linear-gradient(140deg, rgba(255, 255, 255, 0.95), rgba(232, 228, 220, 0.95));
    transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.home-btn-action {
    margin-top: 0;
    font: inherit;
    cursor: pointer;
}

.home-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(174, 57, 46, 0.55);
    box-shadow: 0 8px 18px rgba(71, 31, 31, 0.14);
}

.home-note {
    margin: 1rem auto 0;
    font-size: 0.85rem;
    color: #6f6658;
}

.reader-view {
    width: min(880px, 100%);
}

.reader-sticky {
    position: sticky;
    top: 0.55rem;
    z-index: 22;
    margin-bottom: 0.9rem;
    padding: 0.55rem;
    border: 1px solid rgba(80, 69, 56, 0.22);
    border-radius: 12px;
    background: rgba(246, 240, 229, 0.82);
    backdrop-filter: blur(6px);
}

.reader-head {
    display: grid;
    gap: 0.45rem;
    margin-bottom: 0.55rem;
}

.reader-head-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.7rem;
}

.reader-back {
    margin-top: 0;
    padding: 0.55rem 0.95rem;
    border-radius: 999px;
    border: 1px solid rgba(53, 45, 40, 0.32);
    background: rgba(255, 255, 255, 0.66);
    color: #2e2721;
    font-weight: 700;
}

.reader-meta {
    margin: 0;
    font-size: 0.9rem;
    color: #514741;
}

.reader-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
    margin: 0;
}

.reader-nav-btn,
.reader-other-btn {
    margin-top: 0;
    padding: 0.48rem 0.9rem;
    border-radius: 999px;
    border: 1px solid rgba(53, 45, 40, 0.32);
    background: rgba(255, 255, 255, 0.66);
    color: #2e2721;
    font-weight: 700;
}

.reader-nav-btn:disabled,
.reader-other-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.reader-nav-btn {
    width: 100%;
}

.diary-paper {
    position: relative;
    padding: 1.5rem 1.2rem;
    border-radius: 10px;
    border: 1px solid rgba(68, 57, 44, 0.28);
    background:
        radial-gradient(130% 88% at 10% 12%, rgba(126, 98, 70, 0.16), rgba(126, 98, 70, 0) 44%),
        radial-gradient(95% 72% at 92% 88%, rgba(80, 67, 54, 0.14), rgba(80, 67, 54, 0) 52%),
        linear-gradient(180deg, #efe6d5, #ddd0bc);
    box-shadow: inset 0 0 36px rgba(63, 49, 35, 0.23), 0 10px 30px rgba(37, 26, 18, 0.12);
    color: #2b2118;
    line-height: 1.95;
    font-size: 1.04rem;
}

.diary-paper::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-radius: 10px;
    background: repeating-linear-gradient(180deg, rgba(95, 74, 52, 0.06) 0, rgba(95, 74, 52, 0.06) 1px, transparent 2px, transparent 5px);
    mix-blend-mode: multiply;
    opacity: 0.52;
}

.diary-paper > * {
    position: relative;
    z-index: 1;
}

.diary-paper span[data-post-id] {
    border-bottom: 1px dashed rgba(120, 53, 35, 0.8);
}

.reader-epilogue {
    margin-top: 1.4rem;
    padding-top: 0.6rem;
    border-top: 1px solid rgba(87, 70, 52, 0.4);
    font-size: 0.95rem;
    font-style: italic;
    color: #4e3f31;
}

.source-overlay {
    position: fixed;
    z-index: 130;
    left: 0;
    top: 0;
    max-width: min(360px, calc(100vw - 1rem));
    padding: 0.7rem 0.8rem;
    border-radius: 9px;
    border: 1px solid rgba(188, 40, 40, 0.62);
    background: linear-gradient(160deg, rgba(14, 8, 10, 0.97), rgba(8, 8, 10, 0.97));
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.52);
    pointer-events: none;
}

.source-overlay[hidden] {
    display: none;
}

.source-overlay-text {
    margin: 0;
    white-space: pre-wrap;
    color: #ff5b5b;
    font-weight: 600;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.85), 0 0 8px rgba(126, 16, 16, 0.35);
    line-height: 1.6;
}

.source-overlay-author {
    margin: 0.45rem 0 0;
    color: #f4f4f4;
    font-size: 0.88rem;
}

.source-overlay.mobile-open {
    left: 50%;
    right: auto;
    top: auto;
    bottom: 1rem;
    transform: translateX(-50%);
    width: min(92vw, 420px);
    pointer-events: auto;
}

.home-modal-panel {
    background: rgba(236, 240, 245, 0.96);
    color: #1c2430;
    border-color: rgba(86, 104, 124, 0.35);
}

.home-modal-panel .modal-meta {
    color: #4d6076;
}

.home-modal-panel .modal-text {
    border-top-color: rgba(83, 101, 124, 0.35);
}

.modal-survey {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
    padding: 1rem 0 0.5rem;
}

.survey-qr {
    display: block;
    border-radius: 4px;
}

.survey-link {
    display: inline-block;
    padding: 0.55rem 1.4rem;
    background: #3a4a5c;
    color: #c8d8e8;
    border-radius: 4px;
    text-decoration: none;
    font-size: 0.95rem;
    transition: background 0.2s;
}

.survey-link:hover {
    background: #4d6076;
}

.modal-actions {
    display: grid;
    gap: 0.55rem;
    margin-top: 0.9rem;
}

.modal-actions label {
    margin: 0;
    color: #4d6076;
}

.modal-actions input {
    background: rgba(245, 248, 252, 0.88);
    border-color: rgba(86, 104, 124, 0.35);
    color: #1c2430;
}

.modal-actions textarea {
    min-height: 96px;
    background: rgba(245, 248, 252, 0.88);
    border: 1px solid rgba(86, 104, 124, 0.35);
    color: #1c2430;
}

.modal-actions button {
    margin-top: 0.2rem;
}

.modal-helper {
    margin: 0.1rem 0 0;
    font-size: 0.86rem;
    color: #4d6076;
}

.reader-set-choices {
    display: grid;
    gap: 0.55rem;
    margin-top: 0.8rem;
}

.reader-set-choice-btn {
    width: 100%;
    margin-top: 0;
    text-align: left;
    background: rgba(245, 248, 252, 0.92);
    color: #1f2a37;
    border: 1px solid rgba(86, 104, 124, 0.35);
    padding: 0.7rem 0.9rem;
}

.reader-set-choice-btn[aria-current="true"] {
    border-color: rgba(50, 84, 120, 0.7);
    background: rgba(225, 235, 247, 0.98);
}

.modal-loading {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    color: #4d6076;
    font-size: 0.92rem;
}

.modal-loading[hidden] {
    display: none;
}

.post-message.is-success {
    color: #2f5f41;
}

.post-message.is-error {
    color: #a83535;
}

.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(96, 113, 132, 0.25);
    border-top-color: #3b5876;
    animation: spin 0.85s linear infinite;
}

.global-loading {
    position: fixed;
    inset: 0;
    z-index: 120;
    display: grid;
    place-items: center;
}

.global-loading[hidden] {
    display: none;
}

.global-loading-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 12, 16, 0.68);
}

.global-loading-content {
    position: relative;
    z-index: 1;
    display: grid;
    justify-items: center;
    gap: 0.5rem;
    padding: 0;
    border: 0;
    background: transparent;
    color: #eef3f8;
    text-align: center;
}

.global-loading-content p {
    margin: 0;
}

.global-spinner {
    width: 22px;
    height: 22px;
    border-width: 3px;
    border-color: rgba(227, 236, 248, 0.28);
    border-top-color: #d9e5f4;
}


.glitch-dot {
    position: fixed;
    right: 22px;
    top: 22px;
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: #8d140f;
    box-shadow: 0 0 8px rgba(141, 20, 15, 0.6);
    animation: glitch-blink 4.8s steps(1, end) infinite;
}

@keyframes glitch-blink {
    0%, 84%, 100% {
        opacity: 0;
        transform: translate(0, 0);
    }

    85% {
        opacity: 0.8;
        transform: translate(-2px, 1px);
    }

    86% {
        opacity: 0.2;
        transform: translate(1px, -1px);
    }

    87% {
        opacity: 0.95;
        transform: translate(-1px, 0);
    }

    88% {
        opacity: 0;
        transform: translate(0, 0);
    }
}

@keyframes fog-drift {
    0% {
        transform: translate(-1.2%, -0.8%);
    }

    100% {
        transform: translate(1.2%, 0.8%);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    body.home::after {
        animation: none;
    }

    .glitch-dot {
        animation: none;
        opacity: 0.15;
    }

    .spinner {
        animation: none;
    }
}
