* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
    overflow-y: scroll;
}

body {
    overflow-x: hidden;
    width: 100%;
}

:root {
    --gbf-bg-light: #f0f2f5;
    --gbf-card-bg: #ffffff;
    --gbf-header-bg: linear-gradient(to bottom, #1a355a 0%, #0e1a2b 100%);
    --gbf-gold: linear-gradient(135deg, #f1e0a8 0%, #c9a96e 50%, #f1e0a8 100%);
    --gbf-gold-border: #b89a66;
    --gbf-blue: linear-gradient(to bottom, #4f93e3 0%, #2171d1 100%);
    --gbf-blue-border: #1a5bb8;
    --gbf-text-dark: #2c3e50;
    --gbf-success: #4caf50;
    --gbf-danger: #e53935;
    --gbf-info: #1976d2;
    --gbf-shadow-soft: 0 4px 20px rgba(0,0,0,0.06);
    --gbf-shadow-hard: 0 4px 15px rgba(0,0,0,0.15);
}

body {
    background-color: var(--gbf-bg-light); color: var(--gbf-text-dark);
    font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
    margin: 0; padding-bottom: 120px; line-height: 1.4; overflow-x: hidden;
}

.container { max-width: 1000px; margin: 0 auto; padding: 15px; width: 100%; }

.img-box {
    background: #000; border: 1px solid #444; border-radius: 6px;
    overflow: hidden; display: flex; align-items: center; justify-content: center;
}
.preset-card .img-box { width: 54px; height: 54px; margin-bottom: 8px; border-color: #ddd; }
.img-box img { width: 100%; height: 100%; object-fit: contain; }

.main-header {
    background: var(--gbf-header-bg);
    border-bottom: 2px solid var(--gbf-gold-border);
    padding: 12px 0;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    position: sticky;
    top: 0;
    z-index: 1000;
    height: 55px;
    display: flex;
    justify-content: center;
}

.header-container {
    width: 100%;
    max-width: 1040px;
    padding: 0 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-logo {
    color: #f1e0a8;
    font-family: "Noto Serif JP", "Sawarabi Mincho", serif;
    font-weight: bold;
    text-decoration: none;
    font-size: 1.1rem;
}

.footer-nav { display: flex; justify-content: space-around; padding: 8px 0; }
.nav-item { text-decoration: none; color: #888; font-size: 0.7rem; font-weight: bold; flex: 1; text-align: center; }
.nav-item .icon { font-size: 1.4rem; color: #c9a96e; display: block; margin-bottom: 2px; }
.nav-item.active { color: #fff; }
.nav-item.active .icon { color: #fff; filter: drop-shadow(0 0 5px rgba(255,255,255,0.8)); }

.summary-card {
    background: var(--gbf-card-bg); border-radius: 15px; padding: 25px 15px;
    text-align: center; box-shadow: var(--gbf-shadow-soft); border: 1px solid rgba(255,255,255,1);
    margin-bottom: 20px;
}
.summary-card-title { color: #7f8c8d; font-size: 0.85rem; font-weight: bold; letter-spacing: 0.1em; margin-bottom: 10px; }
.progress-donut-text {
    font-size: 2.2rem; font-weight: bold; background: var(--gbf-gold);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

.category-group { margin-bottom: 15px; border-radius: 12px; overflow: hidden; box-shadow: var(--gbf-shadow-hard); background: #fff; border: 1px solid #ddd; }
.category-header { background: var(--gbf-header-bg); color: #f1e0a8; font-family: "Noto Serif JP", "Sawarabi Mincho", serif; padding: 15px; font-weight: bold; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.category-header::after { content: '▼'; font-size: 0.7rem; color: var(--gbf-gold-border); transition: transform 0.3s; }
.category-group.open .category-header::after { transform: rotate(180deg); }

.category-content {
    max-height: 0; overflow: hidden; transition: max-height 0.4s ease, padding 0.3s;
}

.category-group.open > .category-content { 
    max-height: none; 
    overflow: visible;
    padding: 15px; 
    display: grid;
    grid-template-columns: repeat(2, 1fr); 
    gap: 12px;
    align-items: start;
}

@media (min-width: 992px) {
    .category-group.open > .category-content { 
        grid-template-columns: repeat(3, 1fr); 
    }
}

.subcategory-group {
    display: contents; 
}

.subcategory-header { 
    grid-column: span 1;
    order: 1;
    background: #ffffff; 
    padding: 15px 10px; 
    font-size: 0.85rem; 
    font-weight: bold; 
    border-radius: 10px; 
    border: 1px solid #e2e8f0; 
    cursor: pointer; 
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
    min-height: 100px;
    width: 100%;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    position: relative;
}

.subcategory-header:hover {
    border-color: #cbd5e1;
    background: #f8fafc;
}

.subcategory-header img {
    width: 45px;
    height: 45px;
    object-fit: contain;
}

.subcategory-group.open .subcategory-header { 
    background: #eff6ff;
    border-color: var(--gbf-blue-border);
    box-shadow: 0 4px 12px rgba(33, 113, 209, 0.15);
    color: #1e40af;
}

.subcategory-content { 
    display: none; 
    grid-column: 1 / -1;
    order: 2;
    width: 100%;
    background: #f1f5f9; 
    border-radius: 12px;
    padding: 18px 15px;
    margin-top: 8px;
    margin-bottom: 20px;
    border: 1px solid #cbd5e1; 
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.05);
}

.subcategory-group.open .subcategory-content { 
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

@media (min-width: 992px) {
    .subcategory-group.open .subcategory-content { 
        grid-template-columns: repeat(4, 1fr); 
    }
}

.preset-card {
    display: flex; flex-direction: column; align-items: center; 
    padding: 12px 5px; 
    border: 1px solid #eee; border-radius: 10px; background: #fff; 
    position: relative; text-align: center; cursor: pointer; height: 100%;
    min-width: 0;
    transition: padding 0.2s ease;
}

.preset-card:not(:has(.img-box)) strong {
    margin-top: 0;
}
.preset-card.active { 
    background: #fffdf2; border: 2px solid var(--gbf-gold-border); 
    filter: drop-shadow(0 0 5px rgba(214, 193, 154, 0.3));
    padding-bottom: 60px; 
}
.preset-card.active::before {
    content: '設定中'; position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
    background: var(--gbf-gold); color: #fff; font-size: 0.65rem; padding: 2px 10px; border-radius: 10px; font-weight: bold; z-index: 10;
}
.preset-card strong { font-size: 0.75rem; min-height: 2.4em; display: flex; align-items: center; line-height: 1.2; margin-bottom: 5px; }

.goal-counter {
    position: absolute; bottom: 8px; 
    left: 4px; right: 4px; 
    display: flex; align-items: center; 
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.98); border: 1px solid #d6c19a; border-radius: 30px; 
    padding: 3px; 
    opacity: 0; pointer-events: none;
    transform: translateY(10px);
    transition: all 0.2s ease;
    z-index: 5;
}
.goal-counter.is-unique {
    justify-content: center; 
    background: rgba(0,0,0,0.05); 
    border-radius: 4px;
}
.goal-counter.is-unique::before {
    content: "上限";
    font-size: 0.6rem;
    margin-right: 4px;
    color: #888;
}
@media (min-width: 600px) {
    .goal-counter {
        left: 50%; right: auto;
        width: 140px;
        transform: translateX(-50%) translateY(10px);
    }
}
.preset-card.active .goal-counter { 
    opacity: 1; pointer-events: auto; 
    transform: translateY(0); 
}
@media (min-width: 600px) {
    .preset-card.active .goal-counter { transform: translateX(-50%) translateY(0); }
}

.count-btn { 
    width: 40px; height: 38px; min-width: 34px;
    border-radius: 20px; border: 1px solid #ddd; 
    background: #f8f9fa; display: flex; 
    align-items: center; justify-content: center; 
    font-weight: bold; cursor: pointer; font-size: 1.2rem;
    flex-shrink: 0; transition: 0.2s;
}
.count-btn:active { background: #eee; transform: scale(0.9); }
.goal-count-display { font-weight: bold; font-size: 1rem; flex: 1; text-align: center; color: #a88d5e; }

.input-mode-tabs { position: sticky; top: 55px; z-index: 990; background: var(--gbf-bg-light); display: flex; padding: 10px 15px; gap: 8px; }
.tab-btn { flex: 1; background: #fff; border: 1px solid #ccc; color: #666; padding: 12px; border-radius: 8px; font-weight: bold; cursor: pointer; }
.tab-btn.active { background: var(--gbf-blue); color: #fff; border-color: var(--gbf-blue-border); }

.material-row {
    background: var(--gbf-card-bg); margin-bottom: 15px; padding: 15px; border-radius: 12px;
    box-shadow: var(--gbf-shadow-soft); display: grid; grid-template-columns: 60px 1fr auto;
    grid-template-areas: "icon name qty" "icon progress progress" "icon controls controls";
    gap: 12px; align-items: center; border: 1px solid rgba(255,255,255,0.8);
}
.material-row .name { grid-area: name; font-weight: bold; font-size: 1.05rem; }
.material-row .need { grid-area: qty; font-size: 0.85rem; text-align: right; color: #7f8c8d; }
.material-row .need strong { color: #d35400; font-size: 1.1rem; }
.progress-container { grid-area: progress; height: 10px; background: #eee; border-radius: 10px; overflow: hidden; border: 1px solid #ddd; }
.progress-bar { height: 100%; background: linear-gradient(to right, #3498db, #2ecc71); transition: width 0.4s ease; }

.controls-wrap { grid-area: controls; display: flex; flex-direction: column; gap: 10px; }
.input-wrap input { width: 85px; padding: 10px; border: 2px solid #ddd; border-radius: 8px; text-align: center; font-size: 1.1rem; font-weight: bold; }

.btns-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; flex: 1; }
.quick-btn {
    padding: 10px 0; border-radius: 8px; font-size: 0.8rem; font-weight: bold; cursor: pointer; border: 1px solid #ccc; background: #fff; transition: all 0.2s;
    display: flex; align-items: center; justify-content: center;
}
.quick-btn.minus { color: #d32f2f; background: #fff5f5; border-color: #ffcdd2; }
.quick-btn.plus { color: #1976d2; background: #f0f7ff; border-color: #bbdefb; }
.quick-btn.plus-major { grid-column: span 4; background: var(--gbf-blue); color: #fff; border: none; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }

.material-row.cleared { background: linear-gradient(to right, #f0fff0, #ffffff); border-left: 6px solid var(--gbf-success); }

.goal-label { 
    padding: 12px 5px; color: #a88d5e; font-weight: bold; border-bottom: 2px solid #d6c19a; 
    margin-top: 25px; margin-bottom: 15px; font-size: 1.1rem; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; line-height: 1.3;
}
.goal-label span:first-child { flex: 1; word-break: break-all; }
.goal-actions { display: flex; gap: 6px; flex-shrink: 0; margin-top: -2px; }
.complete-trigger-btn, .delete-trigger-btn, .step-complete-btn { border: none; padding: 8px 12px; border-radius: 6px; font-weight: bold; font-size: 0.75rem; cursor: pointer; color: #fff; }
.complete-trigger-btn { background: var(--gbf-success); }
.delete-trigger-btn { background: var(--gbf-danger); }
.step-complete-btn { background: var(--gbf-info); }

.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); z-index: 2000; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.active { display: flex; }
.modal-content { background: #fff; width: 100%; max-width: 400px; border-radius: 15px; overflow: hidden; border: 2px solid var(--gbf-gold-border); animation: modalPop 0.3s cubic-bezier(0.17, 0.89, 0.32, 1.28); }
@keyframes modalPop { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-header { background: var(--gbf-header-bg); color: #f1e0a8; font-family: "Noto Serif JP", "Sawarabi Mincho", serif; padding: 15px; text-align: center; font-weight: bold; }
.modal-body { padding: 25px; text-align: center; }
.modal-footer { display: flex; border-top: 1px solid #eee; }
.modal-btn { flex: 1; padding: 15px; border: none; font-weight: bold; cursor: pointer; }
.modal-btn.cancel { background: #f5f5f5; color: #666; }
.modal-btn.confirm { background: var(--gbf-blue); color: #fff; }

@media (max-width: 599px) {
    .input-wrap input { width: 60%; }
    .quick-btn { padding: 10px 4vw; }
    .preset-card.active { padding-bottom: 65px; }
}

@media (min-width: 600px) {
    .controls-wrap { flex-direction: row; align-items: center; }
    .count-btn:hover { border-color: var(--gbf-gold-border); background: #fdfaf2; }
    .count-btn { width: 34px; height: 34px; font-size: 1.1rem; }
}

.info-section {
    background: #fff; border-radius: 12px; overflow: hidden;
    box-shadow: var(--gbf-shadow-soft); border: 1px solid #ddd;
    margin-bottom: 20px;
}
.info-header {
    background: var(--gbf-header-bg); color: #f1e0a8;
    font-family: "Noto Serif JP", "Sawarabi Mincho", serif;
    padding: 10px 15px; font-weight: bold; font-size: 0.85rem;
    border-bottom: 2px solid var(--gbf-gold-border);
}

.top-nav-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px;
}
.nav-card {
    text-decoration: none; background: #fff; border: 1px solid #eee;
    border-radius: 12px; padding: 15px 10px; display: flex; flex-direction: column;
    align-items: center; text-align: center; transition: all 0.2s;
    box-shadow: var(--gbf-shadow-soft);
}
.nav-card:active { transform: scale(0.96); background: #fdfaf2; }
.nav-icon { font-size: 1.8rem; margin-bottom: 8px; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1)); }
.nav-info strong { display: block; color: var(--gbf-text-dark); font-size: 0.9rem; margin-bottom: 2px; }
.nav-info span { font-size: 0.65rem; color: #94a3b8; }

.near-item {
    display: flex; align-items: center; padding: 12px 15px;
    border-bottom: 1px solid #f0f2f5; gap: 12px;
}
.near-item:last-child { border-bottom: none; }
.near-item .name { flex: 1; font-size: 0.85rem; font-weight: bold; color: #444; }
.near-item .rest { font-size: 0.75rem; color: #7f8c8d; }
.near-item .rest strong { color: #e53935; font-size: 1rem; margin: 0 2px; }
.near-item-title {
    font-size: 0.85rem;
    font-weight: bold;
    color: #333; /* ここで色を指定 */
}
.rest-count {
    color: #e53935;
}
.near-item-goal {
    font-size: 0.65rem;
    color: #888;
    display: flex;
    align-items: center;
    margin-top: 2px;
}

.rank-row {
    display: flex; align-items: center; padding: 12px 15px; gap: 12px;
    border-bottom: 1px solid #f0f2f5;
}
.rank-badge {
    width: 24px; height: 24px; border-radius: 50%; background: #eee;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.7rem; font-weight: bold; color: #777;
}
.rank-badge.top1 { background: var(--gbf-gold); color: #fff; }
.rank-name { flex: 1; font-size: 0.85rem; font-weight: bold; }

.admin-zone {
    margin: 40px auto 0px;
    padding: 20px 20px 0;
    text-align: center;
    border-top: 1px solid #e2e8f0;
    max-width: 400px;
}

.btn-reset-data {
    background-color: #f8fafc;
    color: #000;
    border: 1px solid #e2e8f0;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-reset-data:hover {
    background-color: #fee2e2;
    color: #ef4444;
    border-color: #fca5a5;
}

.admin-note {
    font-size: 0.65rem;
    color: #000;
    margin-top: 8px;
}

.site-info-footer {
    margin-top: 20px;
    padding: 30px 15px 0px; 
    text-align: center;
    font-size: 0.65rem;
    color: #94a3b8;
    line-height: 1.6;
    border-top: 1px solid #e2e8f0;
}

.site-info-footer a {
    color: #3b82f6;
    text-decoration: none;
}

.back-to-welcome {
    margin-top: 25px;
}

.back-link {
    color: #000; /* ライトモード時の基本色 */
    text-decoration: none;
    font-size: 0.8rem;
    display: inline-block;
    padding: 10px;
    transition: color 0.2s;
}

/* ホバー時の色（マウスを乗せた時） */
.back-link:hover {
    color: #ef4444;
}

.sp-only { display: none; }
@media (max-width: 768px) {
    .sp-only { display: inline; }
}

.main-footer {
    position: fixed;
    bottom: 20px;
    left: 0;
    width: 100%;
    z-index: 1000;
    pointer-events: none;
}

.footer-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 90%;
    max-width: 500px;
    margin: 0 auto;
    height: 70px;
    background: linear-gradient(to bottom, #1e293b, #0f172a);
    border-radius: 40px;
    border: 1px solid #b4945c;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    pointer-events: auto;
}

@media (min-width: 1024px) {
    .container {
        max-width: 1100px;
        padding: 30px;
    }

    .summary-card {
        padding: 40px;
        margin-bottom: 40px;
        display: flex;
        justify-content: space-around;
        align-items: center;
    }

    .summary-card-title {
        margin-bottom: 0;
        font-size: 1rem;
    }
}

/* ダークモード用の上書き設定（既存の構成を維持） */
body.dark-mode {
    --gbf-bg-light: #0f172a;       /* 背景を深い紺に */
    --gbf-card-bg: #1e293b;        /* カードを少し明るい紺に */
    --gbf-text-dark: #f1f5f9;      /* 文字を白に近いグレーに */
    --gbf-shadow-soft: 0 4px 20px rgba(0,0,0,0.4);
}

body.dark-mode .category-group,
body.dark-mode .info-section,
body.dark-mode .nav-card,
body.dark-mode .preset-card,
body.dark-mode .subcategory-header {
    background-color: var(--gbf-card-bg);
    border-color: #334155;
    color: var(--gbf-text-dark);
}

body.dark-mode .preset-card.active {
    background-color: #fff;
    color: #000
}

body.dark-mode .subcategory-content {
    background-color: #0f172a;
    border-color: #334155;
}

body.dark-mode .material-row {
    border-color: rgba(255,255,255,0.1);
}

/* 入力フォームの調整 */
body.dark-mode input {
    background-color: #0f172a;
    color: #fff;
    border-color: #334155;
}
/* 1. もうすぐ完了する素材名の修正 */
body.dark-mode .near-item .name {
    color: var(--gbf-text-dark); /* 暗い紺から明るいグレーに */
}

/* 2. 達成時の素材エリア（.cleared）の修正 */
/* 背景をライトモードの「白〜緑」から「濃い緑〜紺」のグラデーションに変更し、文字を白くします */
body.dark-mode .material-row.cleared {
    background: linear-gradient(to right, #064e3b, #1e293b); /* 濃い緑のグラデーション */
    border-left: 6px solid var(--gbf-success);
    color: #ffffff;
}

/* 3. モーダルの修正 */
body.dark-mode .modal-content {
    background-color: #1e293b; /* カードと同じ紺色 */
    border-color: var(--gbf-gold-border);
}

body.dark-mode .modal-body {
    color: #ffffff; /* 文字を白に */
}

body.dark-mode .modal-btn.cancel {
    background: #334155;
    color: #cbd5e1;
}
/* 1. もうすぐ完了する素材名の修正（優先度を上げて白くします） */
body.dark-mode .near-item .name {
    color: #f1f5f9 !important; /* 明るいグレー。!importantで既存の#444を上書き */
}

/* 2. モーダル内のテキスト（「素材在庫は減りません」等）の修正 */
body.dark-mode .modal-body,
body.dark-mode .modal-body *, /* モーダル内にある全ての子要素（pタグやspanなど） */
body.dark-mode .admin-note {
    color: #ffffff !important;
}

/* 3. モーダルの背景も改めて指定（確実に白背景を消す） */
body.dark-mode .modal-content {
    background: #1e293b !important;
    color: #ffffff;
}

body.dark-mode .near-item {
    border-bottom-color: #334155;
}
body.dark-mode .near-item-title {
    color: #f1f5f9; /* ダークモードで白っぽく */
}
body.dark-mode .near-item-goal {
    color: #94a3b8;
}

body.dark-mode .back-link {
    color: #f1f5f9; /* ダークモード時の基本色（白っぽく） */
}

/* ダークモード時のホバー色（お好みで調整してください） */
body.dark-mode .back-link:hover {
    color: #ff7878; 
}
body.dark-mode .goal-label { 
    color: #fff;
}