:root {
    --bg-color: #FDFBF8;
    --text-color: #5A5144;
    --text-light: #8E8578;
    --btn-high-bg: #FFEAD9;
    --btn-high-hover: #FFDAC1;
    --btn-high-text: #B35E1C;
    --btn-mid-bg: #EAE6DF;
    --btn-mid-hover: #DCD6CD;
    --btn-mid-text: #706456;
    --btn-low-bg: #E2EFE7;
    --btn-low-hover: #D0E4D7;
    --btn-low-text: #41755C;
    --tab-bg: #FFFFFF;
    --accent: #A9BCA3;
    --toast-bg: rgba(255, 255, 255, 0.95);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'M PLUS Rounded 1c', 'Kosugi Maru', -apple-system, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
}

.app-title {
    font-size: 1.2rem;
    font-weight: 500;
    color: var(--text-color);
}

.icon-button {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: inherit;
    transition: transform 0.2s;
}

.icon-button:active {
    transform: scale(0.9);
}

main {
    flex: 1;
    padding: 0 20px 80px 20px; /* nav bar offset */
}

/* Tabs */
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Home Tab */
.gentle-question {
    font-size: 1.5rem;
    font-weight: 500;
    text-align: center;
    margin-bottom: 30px;
    margin-top: 10px;
    color: var(--text-color);
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.state-button {
    display: flex;
    align-items: center;
    padding: 24px 20px;
    border: none;
    border-radius: 24px;
    font-size: 1.1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
}

.state-button:active {
    transform: scale(0.98);
}

.state-button.selected-zone {
    box-shadow: 0 0 0 3px var(--accent);
    background-color: white;
    transform: scale(0.98);
}

.state-button .emoji {
    font-size: 1.8rem;
    margin-right: 16px;
}

.state-high {
    background-color: var(--btn-high-bg);
    color: var(--btn-high-text);
}
.state-high:active, .state-high:hover {
    background-color: var(--btn-high-hover);
}

.state-mid {
    background-color: var(--btn-mid-bg);
    color: var(--btn-mid-text);
}
.state-mid:active, .state-mid:hover {
    background-color: var(--btn-mid-hover);
}

.state-low {
    background-color: var(--btn-low-bg);
    color: var(--btn-low-text);
}
.state-low:active, .state-low:hover {
    background-color: var(--btn-low-hover);
}

/* Resource Tab */
.resource-section {
    margin-bottom: 30px;
}

/* Today's Word */
.today-word-area {
    background-color: #F8F7F4;
    border: 1px solid rgba(0,0,0,0.03);
    border-radius: 20px;
    padding: 24px 20px;
    margin-bottom: 24px;
    text-align: center;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
}

.today-header {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-bottom: 12px;
}

.today-content {
    width: 100%;
}

.today-word-area p {
    font-size: 1.1rem;
    color: var(--text-color);
    line-height: 1.6;
    margin: 0;
    white-space: pre-wrap;
}

.today-content img {
    width: 100% !important;
    max-height: 50vh !important; /* より画面いっぱいになるように */
    height: auto !important;
    object-fit: contain !important; /* 絶対に全体を表示 */
    background-color: #F1F0EC !important;
    border-radius: 12px;
    margin-bottom: 8px;
}

/* Inner Tabs */
.inner-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    background-color: #F1F0EC;
    padding: 4px;
    border-radius: 16px;
}

.inner-tab-btn {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.2s;
}

.inner-tab-btn.active {
    background-color: white;
    color: var(--text-color);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* Resource Gallery */
.resource-gallery {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 90px;
}

/* Inner Tabs */
.inner-tab-content {
    display: none !important; /* デフォルトで強制非表示 */
}
.inner-tab-content.active {
    display: flex !important; /* active時のみ表示 */
}

#photoGalleryTab.active {
    display: grid !important; /* 写真タブだけはgrid表示を優先 */
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.photo-grid-item {
    aspect-ratio: 1/1;
    overflow: hidden;
    position: relative;
    border-radius: 8px;
    background-color: #F8F7F4;
    cursor: pointer;
}

.photo-grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(255, 255, 255, 0.8);
    display: none; /* 初期状態は強制非表示 */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    color: var(--text-color);
    font-weight: bold;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left-color: var(--accent);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Photo View Modal */
.photo-view-content {
    background-color: #F8F7F4;
    padding: 16px;
    border-radius: 20px;
    max-width: 90%;
}
.photo-view-area img {
    width: 100%;
    border-radius: 12px;
    margin-bottom: 16px;
}
.photo-view-area p {
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-color);
    white-space: pre-wrap;
    margin-bottom: 16px;
}

/* Toast Actions */
.toast-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}
.toast-btn {
    width: 100%;
    margin-top: 0 !important;
}

.resource-card {
    background-color: #fdfaf5;
    border-radius: 20px;
    padding: 16px;
    position: relative;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
    border: 1px solid rgba(0,0,0,0.03);
}

.resource-card img {
    width: 100%;
    border-radius: 12px;
    margin-bottom: 12px;
    max-height: 300px;
    object-fit: cover;
}

.resource-card p {
    font-size: 0.95rem;
    color: var(--text-color);
    line-height: 1.5;
    white-space: pre-wrap;
    margin: 0;
}

.delete-resource-btn {
    border: none;
    background: none;
    font-size: 0.85rem;
    cursor: pointer;
    color: #b0aca5;
    padding: 4px;
    text-decoration: underline;
    transition: color 0.2s;
    display: inline-block;
    margin-top: 4px;
}

.delete-resource-btn:hover {
    color: var(--warning);
}

/* FAB */
.fab {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 28px;
    background-color: var(--accent);
    color: white;
    font-size: 2rem;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 12px rgba(169, 188, 163, 0.4);
    cursor: pointer;
    z-index: 100;
    transition: transform 0.2s;
    line-height: 1;
}

.fab:active {
    transform: scale(0.92);
}

.resource-desc {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--text-color);
}

.photo-upload-area {
    width: 100%;
    aspect-ratio: 16 / 9;
    background-color: #F1F0EC;
    border-radius: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    overflow: hidden;
    position: relative;
    border: 2px dashed #D6D2CA;
}

.photo-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-light);
}

#photoPreview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

textarea {
    width: 100%;
    min-height: 150px;
    padding: 16px;
    border-radius: 20px;
    border: none;
    background-color: #F1F0EC;
    color: var(--text-color);
    font-size: 1rem;
    resize: none;
    outline: none;
}
textarea:focus {
    box-shadow: 0 0 0 2px var(--accent);
}

/* Settings Modal */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0,0,0,0.15);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: #FFFFFF;
    padding: 30px 20px;
    border-radius: 28px;
    width: 90%;
    max-width: 400px;
    position: relative;
    box-shadow: 0 10px 25px rgba(0,0,0,0.05);
    max-height: 90vh;
    max-height: 90dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

body.modal-open {
    overflow: hidden;
}

.close-button {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    font-size: 2rem;
    line-height: 1;
    color: var(--text-light);
    cursor: pointer;
}

.modal-content h3 {
    margin-bottom: 24px;
    font-weight: 500;
}

.setting-item {
    margin-bottom: 16px;
}

.toggle-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}

/* Toggle Switch Styling */
.toggle-label input {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 50px;
    height: 28px;
    background-color: #DCD6CD;
    border-radius: 30px;
    transition: 0.3s;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: 0.3s;
}

input:checked + .toggle-slider {
    background-color: var(--accent);
}

input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

.setting-note {
    font-size: 0.85rem;
    color: var(--text-light);
    line-height: 1.5;
    margin-top: 16px;
    background-color: #F8F7F4;
    padding: 12px;
    border-radius: 12px;
}

/* Toast Message */
.toast {
    position: fixed;
    bottom: 90px;
    left: 20px;
    right: 20px;
    background-color: var(--toast-bg);
    color: var(--text-color);
    padding: 20px;
    border-radius: 20px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 500;
    border: 1px solid rgba(0,0,0,0.03);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.4s;
}

.toast.hidden {
    transform: translateY(150%);
    opacity: 0;
    pointer-events: none;
}

#toastText {
    line-height: 1.6;
    font-size: 0.95rem;
}

#toastClose {
    align-self: flex-end;
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 0.9rem;
    padding: 8px 4px;
    cursor: pointer;
}

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 70px;
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid rgba(0,0,0,0.03);
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    color: var(--text-light);
    flex: 1;
    padding: 10px 0;
}

.nav-item.active {
    color: var(--accent);
}

.nav-icon {
    font-size: 1.4rem;
}

.nav-label {
    font-size: 0.75rem;
    font-weight: 500;
}

/* Custom Settings Form */
.setting-divider {
    border: none;
    border-top: 1px solid #EAE6DF;
    margin: 24px 0;
}

.setting-subtitle {
    font-size: 1.05rem;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-color);
}

.setting-desc {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 16px;
    line-height: 1.4;
}

.custom-input-group {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
}

.custom-input-group label {
    font-size: 0.85rem;
    color: var(--text-color);
    margin-bottom: 4px;
}

.custom-input {
    padding: 12px;
    border-radius: 12px;
    border: 1px solid #DCD6CD;
    background-color: #FDFBF8;
    color: var(--text-color);
    font-size: 1rem;
    outline: none;
    transition: all 0.2s;
}

.custom-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(169, 188, 163, 0.2);
}

.settings-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

.primary-btn {
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 14px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.2s;
}

.primary-btn:active {
    transform: scale(0.98);
}

.secondary-btn {
    background-color: transparent;
    color: var(--text-light);
    border: 1px solid #DCD6CD;
    padding: 12px;
    border-radius: 14px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: transform 0.2s;
}

.secondary-btn:active {
    transform: scale(0.98);
}

/* Reflection Tab */
.reflection-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.safe-message {
    background-color: #F8F7F4;
    padding: 16px;
    border-radius: 16px;
    font-size: 0.9rem;
    color: var(--text-color);
    line-height: 1.5;
    text-align: center;
}

.chart-container {
    background-color: white;
    border-radius: 20px;
    padding: 16px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
    width: 100%;
    height: 250px;
    position: relative;
    border: 1px solid rgba(0,0,0,0.03);
}

/* Calendar */
.calendar-wrapper {
    background-color: white;
    border-radius: 20px;
    padding: 16px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
    border: 1px solid rgba(0,0,0,0.03);
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    font-weight: 500;
}

.calendar-days-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-light);
    margin-bottom: 8px;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.calendar-cell {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 0.9rem;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s;
    overflow: hidden;
}

.calendar-cell:active {
    transform: scale(0.9);
}

.calendar-cell.empty {
    cursor: default;
}

.cell-date {
    margin-bottom: 2px;
}

.calendar-dots {
    display: flex;
    gap: 2px;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    max-width: 100%;
    padding: 0 4px;
    height: 10px;
    overflow: hidden;
}

.cal-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.cal-dot-plus {
    font-size: 0.65rem;
    color: var(--text-light);
    line-height: 1;
    margin-left: 1px;
    font-weight: bold;
}

/* Calendar Colors */
.cal-today { border: 2px solid var(--accent); }
.dot-high { background-color: #F8B179; }
.dot-mid { background-color: #A9BCA3; }
.dot-low { background-color: #A0B8CD; }

/* Timeline styling */
.memo-list-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.timeline-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.timeline-time {
    font-size: 0.8rem;
    color: var(--text-light);
    min-width: 40px;
    padding-top: 4px;
}

.timeline-content {
    background-color: #F8F7F4;
    padding: 12px;
    border-radius: 12px;
    flex: 1;
}

.timeline-zone {
    font-weight: 500;
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.timeline-memo {
    font-size: 0.9rem;
    color: var(--text-color);
    line-height: 1.4;
    margin-bottom: 8px;
}

.timeline-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.action-link {
    font-size: 0.8rem;
    color: var(--text-light);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
}
.action-link.delete-link {
    color: #E07A5F;
}

.cal-today { border: 2px solid var(--accent); }

/* Memo display */
.memo-display {
    background-color: white;
    border-radius: 16px;
    padding: 16px;
    margin-top: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
    border: 1px solid rgba(0,0,0,0.03);
    animation: fadeIn 0.2s ease-in-out;
}

.memo-date { font-size: 0.85rem; color: var(--text-light); margin-bottom: 4px; }
.memo-zone { font-weight: 500; margin-bottom: 8px; }
.memo-text { font-size: 0.95rem; background-color: #F8F7F4; padding: 12px; border-radius: 12px; }

/* Daily Memo Input */
.daily-memo-area {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
}
.memo-label {
    font-size: 0.9rem;
    color: var(--text-color);
    margin-bottom: 8px;
    font-weight: 500;
}
.memo-input, .time-input {
    padding: 14px;
    border-radius: 16px;
    border: 1px solid #DCD6CD;
    background-color: #FDFBF8;
    color: var(--text-color);
    font-size: 1rem;
    outline: none;
    transition: all 0.2s;
    width: 100%;
    box-sizing: border-box;
}
.memo-input:focus, .time-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(169, 188, 163, 0.2);
}

.submit-record-btn {
    width: 100%;
    margin-top: 24px;
}
.submit-record-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
