/*
Theme Name: Cotonoha Garden
Description: 小説投稿サイト「コトノハガーデン」用テーマ
Version: 1.0.0
Author: Custom
*/

/* --- 1. 変数定義 (Design Tokens) --- */
:root {
    /* Colors */
    --c-bg: #FBFAF7;
    --c-surface: #FFFFFF;
    --c-text: #0B1220;
    --c-muted: #5B6575;
    --c-line: #E7E3DD;
    --c-leaf: #2F7D5D;     /* Main */
    --c-leaf-hover: #25664a;
    --c-petal: #D78AAE;    /* Sub */
    --c-night: #24324A;    /* Accent */
    --c-light: #FFF2D7;
    --c-label-nerumae: #5163B7;
    --c-label-kurage: #2AA7B6;

    /* Fonts */
    --font-sans: "Noto Sans JP", sans-serif;
    --font-serif: "Shippori Mincho", serif;

    /* Layout */
    --w-max: 1200px;
    --header-height: 64px;
}

/* --- 2. Base --- */
body {
    background-color: var(--c-bg);
    color: var(--c-text);
    font-family: var(--font-sans);
    line-height: 1.6;
    margin: 0;
    /* 紙の質感を出すノイズ画像（Data URI） */
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.04'/%3E%3C/svg%3E");
}

a {
    text-decoration: none;
    color: inherit;
    transition: 0.3s;
}

ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* --- 3. Layout Utilities --- */
.l-container {
    max-width: var(--w-max);
    margin: 0 auto;
    padding: 0 1.5rem;
}

.l-main-grid {
    display: grid;
    gap: 3rem;
    padding-top: 4rem;
    padding-bottom: 4rem;
}

@media (min-width: 768px) {
    .l-main-grid {
        grid-template-columns: 8fr 4fr; /* メイン 8 : サイド 4 */
    }
}

/* --- 4. Components --- */
/* Button */
.c-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 2rem;
    border-radius: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}
.c-btn--primary {
    background-color: var(--c-leaf);
    color: #fff;
    box-shadow: 0 4px 15px rgba(47, 125, 93, 0.2);
}
.c-btn--primary:hover {
    background-color: var(--c-leaf-hover);
    transform: translateY(-2px);
}
.c-btn--outline {
    border: 1px solid var(--c-leaf);
    color: var(--c-leaf);
}
.c-btn--outline:hover {
    background-color: rgba(47, 125, 93, 0.05);
}

/* Section Title with Deco */
.c-heading {
    position: relative;
    padding-left: 1.5rem;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    border-bottom: 1px solid var(--c-line);
    padding-bottom: 0.5rem;
}
.c-heading h2 {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--c-night);
    margin: 0;
}
.c-heading::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-60%);
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%232F7D5D'%3E%3Cpath d='M2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2C6.48,2 2,6.48 2,12M12,13H11V18H10V16H8V14H10V13C10,11 10.25,9.45 11.2,8.1C10.74,7.86 10.21,7.74 9.68,7.76C12.11,7.66 12.83,9.77 12.92,10.65C12.95,10.24 13.06,9.11 13.96,8.18C14.15,9.26 14.07,10.5 13.5,11.53L13.5,13H12Z' /%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: contain;
}

/* Card Style */
.c-card {
    background: var(--c-surface);
    border: 1px solid var(--c-line);
    border-radius: 1.25rem;
    padding: 1.5rem;
    box-shadow: 0 4px 20px -2px rgba(11, 18, 32, 0.05);
    transition: transform 0.3s, box-shadow 0.3s;
}
.c-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 25px -5px rgba(11, 18, 32, 0.1);
}

/* Label Badge */
.c-badge {
    font-size: 0.625rem;
    padding: 0.125rem 0.5rem;
    border-radius: 99px;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.c-badge--nerumae {
    background-color: #EAEFF9;
    color: var(--c-label-nerumae);
}
.c-badge--kurage {
    background-color: #E0F2F1;
    color: var(--c-label-kurage);
}

/* --- 5. Header & Nav --- */
.l-header {
    position: fixed;
    top: 0;
    width: 100%;
    height: var(--header-height);
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(4px);
    border-bottom: 1px solid var(--c-line);
    z-index: 100;
    display: flex;
    align-items: center;
}
.l-header__inner {
    width: 100%;
    max-width: var(--w-max);
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.l-header__logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--c-leaf);
}
.l-header__logo-text {
    font-family: var(--font-serif);
    font-size: 1.25rem;
    color: var(--c-night);
    line-height: 1;
}
.l-header__nav {
    display: none;
}
@media (min-width: 768px) {
    .l-header__nav {
        display: flex;
        gap: 1.5rem;
        font-size: 0.95rem;
        color: var(--c-muted);
        font-weight: 500;
    }
    .l-header__nav a:hover {
        color: var(--c-leaf);
    }
}

/* --- 6. Top Page Specific --- */
/* Hero Section */
.p-hero {
    padding-top: calc(var(--header-height) + 3rem);
    padding-bottom: 4rem;
    position: relative;
    overflow: hidden;
}
.p-hero__bg {
    position: absolute;
    top: -3rem;
    right: -3rem;
    width: 500px;
    height: 500px;
    opacity: 0.05;
    color: var(--c-leaf);
    pointer-events: none;
}
.p-hero__grid {
    display: grid;
    gap: 3rem;
    align-items: center;
}
@media (min-width: 768px) {
    .p-hero__grid {
        grid-template-columns: 1fr 1fr;
    }
}
.p-hero__copy h2 {
    font-family: var(--font-serif);
    font-size: 2rem;
    color: var(--c-night);
    line-height: 1.5;
    margin-bottom: 1.5rem;
}

/* Ranking List */
.p-ranking-item {
    display: flex;
    gap: 1rem;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    border-bottom: 1px dashed var(--c-line);
}
.p-ranking-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}
.p-ranking-rank {
    min-width: 2rem;
    text-align: center;
    font-family: var(--font-serif);
    font-weight: bold;
    font-size: 1.5rem;
    line-height: 1;
}
.p-ranking-rank.rank-1 { color: var(--c-petal); }
.p-ranking-rank.rank-2 { color: var(--c-leaf); }
.p-ranking-rank.rank-3 { color: var(--c-muted); }

/* Footer */
.l-footer {
    background: #fff;
    border-top: 1px solid var(--c-line);
    padding: 4rem 0 2rem;
    margin-top: 4rem;
}
/* --- 7. Editor Page Specific (Responsive) --- */

/* 全画面レイアウト固定 */
.p-editor-body {
    height: 100vh;
    height: 100dvh; /* モバイルのアドレスバー対策 */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: #F5F2ED;
}

/* ヘッダー */
.p-editor-header {
    height: 60px;
    background: #fff;
    border-bottom: 1px solid var(--c-line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    flex-shrink: 0;
    z-index: 50;
}

/* メインコンテナ */
.p-editor-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* 執筆エリア */
.p-editor-main {
    flex: 1;
    overflow-y: auto;
    position: relative;
    padding: 1rem;
    -webkit-overflow-scrolling: touch;
}

/* 紙の質感エリア */
.p-editor-paper {
    background-color: #fff;
    width: 100%;
    max-width: 800px;
    min-height: calc(100vh - 100px);
    padding: 2rem 1.5rem;
    border-radius: 4px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    margin: 0 auto;
}
@media (min-width: 768px) {
    .p-editor-main { padding: 2rem; }
    .p-editor-paper { padding: 4rem; }
}

/* ツールバー */
.p-editor-toolbar {
    position: sticky;
    top: 0;
    background: rgba(255, 255, 255, 0.98);
    border-bottom: 1px solid var(--c-line);
    padding-bottom: 0.5rem;
    margin-bottom: 1.5rem;
    display: flex;
    gap: 0.5rem;
    z-index: 10;
}
.p-editor-tool-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: var(--c-muted);
    background: #f5f5f5;
    border: none;
    cursor: pointer;
}

/* 入力エリア */
.p-editor-title {
    width: 100%;
    font-size: 1.25rem;
    font-weight: bold;
    font-family: var(--font-serif);
    border: none;
    outline: none;
    background: transparent;
    margin-bottom: 1.5rem;
    color: var(--c-night);
    padding: 0;
}
.p-editor-textarea {
    width: 100%;
    height: 60vh;
    border: none;
    outline: none;
    resize: none;
    font-size: 1rem;
    line-height: 1.8;
    font-family: var(--font-serif);
    background: transparent;
    color: var(--c-night);
    padding: 0;
}

/* --- サイドバー（設定メニュー） --- */
.p-editor-sidebar {
    width: 300px;
    background: #fff;
    border-left: 1px solid var(--c-line);
    flex-shrink: 0;
    overflow-y: auto;
    padding: 1.5rem;
    
    /* モバイル用の初期状態（隠す） */
    position: fixed;
    top: 0;
    right: -100%;
    bottom: 0;
    z-index: 100;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -5px 0 20px rgba(0,0,0,0.1);
}

/* PCでは常時表示 */
@media (min-width: 1024px) {
    .p-editor-sidebar {
        position: static;
        right: auto;
        box-shadow: none;
        display: block !important;
    }
}

/* モバイルで開いた状態 */
.p-editor-sidebar.is-open {
    right: 0;
}

/* 背景オーバーレイ（モバイル用） */
.p-editor-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
    opacity: 0;
    visibility: hidden;
    transition: 0.3s;
}
.p-editor-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

/* 設定トグルボタン（モバイルのみ表示） */
.p-editor-settings-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: var(--c-muted);
    background: #fff;
    border: 1px solid var(--c-line);
    margin-left: 0.5rem;
    cursor: pointer;
}
@media (min-width: 1024px) {
    .p-editor-settings-btn { display: none; }
}

/* --- 8. Archive & Search --- */

/* 検索サイドバー */
.p-filter-box {
    background: #fff;
    border: 1px solid var(--c-line);
    border-radius: 1rem;
    padding: 1.5rem;
    position: sticky;
    top: calc(var(--header-height) + 2rem);
}

.p-filter-group {
    margin-bottom: 1.5rem;
}

.p-filter-label {
    display: block;
    font-size: 0.75rem;
    font-weight: bold;
    color: var(--c-muted);
    margin-bottom: 0.5rem;
}

/* 作品カード (Grid表示用) */
.p-novel-grid {
    display: grid;
    gap: 1.5rem;
}
@media (min-width: 640px) {
    .p-novel-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
@media (min-width: 1024px) {
    .p-novel-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* --- 9. Single Novel (TOC Page) --- */

/* 作品ヘッダー */
.p-work-header {
    background: #fff;
    border: 1px solid var(--c-line);
    border-radius: 1.5rem;
    padding: 2rem;
    position: relative;
    overflow: hidden;
    margin-bottom: 3rem;
}
@media (min-width: 768px) {
    .p-work-header { padding: 3rem; }
}

.p-work-title {
    font-family: var(--font-serif);
    font-size: 1.75rem;
    font-weight: bold;
    color: var(--c-night);
    line-height: 1.4;
    margin-bottom: 1rem;
}

.p-work-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.8rem;
    color: var(--c-muted);
    border-bottom: 1px dashed var(--c-line);
    padding-bottom: 1.5rem;
    margin-bottom: 1.5rem;
}

/* 目次リスト */
.p-episode-list {
    background: #fff;
    border: 1px solid var(--c-line);
    border-radius: 1rem;
    overflow: hidden;
}
.p-episode-item {
    display: block;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--c-line);
    transition: background-color 0.3s;
}
.p-episode-item:last-child { border-bottom: none; }
.p-episode-item:hover {
    background-color: rgba(47, 125, 93, 0.05); /* Leaf color light */
}
.p-episode-title {
    font-weight: bold;
    color: var(--c-night);
    display: block;
    margin-bottom: 0.25rem;
}
.p-episode-date {
    font-size: 0.75rem;
    color: var(--c-muted);
}
/* --- 10. Single Episode (Viewer) --- */

/* 読書モード用のbodyクラス（header.phpで付与想定） */
body.is-viewer {
    background-color: #FBFAF7; /* 目に優しい色 */
}

/* 簡易ヘッダー（スクロールで隠れる用） */
.l-header--viewer {
    position: fixed;
    top: 0;
    width: 100%;
    height: 56px;
    background: rgba(251, 250, 247, 0.95);
    backdrop-filter: blur(4px);
    border-bottom: 1px solid var(--c-line);
    z-index: 50;
    transition: transform 0.3s;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
}
.l-header--viewer.is-hidden {
    transform: translateY(-100%);
}

/* 本文コンテナ */
.p-story-container {
    max-width: 720px; /* 読みやすい幅 */
    margin: 0 auto;
    padding: 6rem 1.5rem 6rem;
}

/* タイトルエリア */
.p-story-header {
    text-align: center;
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    border-bottom: 1px dashed var(--c-line);
}
.p-story-title {
    font-family: var(--font-serif);
    font-size: 1.75rem;
    font-weight: bold;
    color: var(--c-night);
    line-height: 1.5;
    margin-bottom: 1rem;
}

/* 本文スタイル */
.p-story-body {
    font-family: var(--font-serif);
    font-size: 18px;
    line-height: 2;
    text-align: justify;
    color: var(--c-text);
    word-break: break-all;
}
.p-story-body p {
    margin-bottom: 1.5em; /* 段落間を広めに */
}

/* 応援ボタンエリア */
.p-story-action {
    margin-top: 5rem;
    padding-top: 3rem;
    border-top: 1px solid var(--c-line);
    text-align: center;
}
.c-btn-water {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 2px solid var(--c-petal);
    color: var(--c-petal);
    background: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    transition: 0.2s;
    box-shadow: 0 4px 10px rgba(215, 138, 174, 0.1);
}
.c-btn-water:hover {
    background: rgba(215, 138, 174, 0.1);
    transform: scale(1.05);
}
.c-btn-water:active {
    transform: scale(0.95);
}

/* 前後リンクナビゲーション */
.p-story-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 3rem;
}
.p-story-nav-link {
    display: block;
    padding: 1rem;
    background: #fff;
    border: 1px solid var(--c-line);
    border-radius: 0.75rem;
    font-size: 0.85rem;
    transition: 0.3s;
}
.p-story-nav-link:hover {
    border-color: var(--c-leaf);
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}
.p-story-nav-link--prev { text-align: left; }
.p-story-nav-link--next { text-align: right; }
/* --- 11. Dashboard & MyPage --- */

/* ダッシュボードレイアウト */
.l-dashboard {
    display: flex;
    min-height: 100vh;
    background-color: var(--c-bg);
}

/* サイドバー（作家メニュー） */
.l-dashboard__sidebar {
    width: 260px;
    background: #fff;
    border-right: 1px solid var(--c-line);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
@media (max-width: 768px) {
    .l-dashboard__sidebar { display: none; } /* スマホではハンバーガー内へ移動想定 */
}

.l-dashboard__sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--c-line);
}

.c-dashboard-nav {
    padding: 1.5rem 1rem;
    flex: 1;
}
.c-dashboard-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    color: var(--c-muted);
    font-weight: bold;
    font-size: 0.9rem;
    transition: 0.2s;
}
.c-dashboard-nav a:hover,
.c-dashboard-nav a.is-active {
    background-color: var(--c-bg);
    color: var(--c-night);
}
.c-dashboard-nav a.is-active {
    background-color: var(--c-leaf);
    color: #fff;
}

/* メインエリア */
.l-dashboard__main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; /* flexアイテムのはみ出し防止 */
}

.l-dashboard__header {
    height: var(--header-height);
    background: #fff;
    border-bottom: 1px solid var(--c-line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    flex-shrink: 0;
}

.l-dashboard__content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

/* 統計カード */
.c-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}
.c-stats-card {
    background: #fff;
    border: 1px solid var(--c-line);
    border-radius: 1rem;
    padding: 1.5rem;
}
.c-stats-label {
    font-size: 0.75rem;
    font-weight: bold;
    color: var(--c-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.c-stats-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--c-night);
}
.c-stats-diff {
    font-size: 0.7rem;
    margin-left: 0.5rem;
}
.c-stats-diff.is-up { color: var(--c-leaf); }

/* リストアイテム (本棚・履歴など) */
.c-list-item {
    background: #fff;
    border: 1px solid var(--c-line);
    border-radius: 0.75rem;
    padding: 1rem;
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1rem;
    transition: 0.2s;
}
.c-list-item:hover {
    border-color: var(--c-leaf);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}