:root {
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
    --glass-border: 1px solid rgba(255, 255, 255, 0.3);
}

/* Cloud White */
body[data-theme="light"] {
    --bg-color: #fafafa;
    --card-bg: rgba(255, 255, 255, 0.9);
    --border-color: rgba(0, 0, 0, 0.1);
    --text-color: #1a1a1a;
    --text-muted: #666;
    --primary-color: #000;
    --primary-hover: #333;
    --success-color: #1e8e3e;
    --danger-color: #d93025;
    --gradient-title-end: #555;
    background: #f5f5f7;
}

/* Midnight Dark */
body[data-theme="dark"] {
    --bg-color: #0a0a0a;
    --card-bg: rgba(22, 22, 22, 0.8);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-color: #ededed;
    --text-muted: #888;
    --primary-color: #fff;
    --primary-hover: #ccc;
    --success-color: #2ea043;
    --danger-color: #f85149;
    --gradient-title-end: #999;
    --glass-border: 1px solid rgba(255, 255, 255, 0.05);
    background: #111;
}

body {
    margin: 0; padding: 0; font-family: 'Inter', sans-serif;
    color: var(--text-color); min-height: 100vh; display: flex; flex-direction: column;
    transition: background 0.5s ease, color 0.5s ease;
    overflow-x: hidden;
}

.app-layout { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.app-header {
    background: rgba(255, 255, 255, 0.2); backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px); border-bottom: var(--glass-border);
    padding: 20px 40px; flex-shrink: 0; transition: background 0.4s ease;
}
body[data-theme="dark"] .app-header { background: rgba(22, 27, 34, 0.3); }

.header-content {
    max-width: 1600px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 15px;
}

.header-titles h1 {
    font-size: 26px; font-weight: 700; margin: 0 0 4px;
    background: linear-gradient(90deg, var(--primary-color), var(--gradient-title-end));
    background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

.header-titles p { font-size: 13px; color: var(--text-muted); margin: 0; }

.header-right-group { display: flex; align-items: center; gap: 15px; flex-wrap: wrap; }

/* View & Theme Controls */
.controls-row { display: flex; gap: 10px; align-items: center; }

.category-toggle {
    display: flex; background: rgba(0,0,0,0.05); border-radius: 10px; padding: 4px;
    border: 1px solid var(--border-color);
}
body[data-theme="dark"] .category-toggle { background: rgba(0,0,0,0.4); }

.tab-btn {
    background: transparent; border: none; color: var(--text-muted); font-size: 13px;
    padding: 8px 16px; border-radius: 6px; cursor: pointer; transition: all 0.3s;
    font-weight: 600; display: flex; align-items: center; gap: 6px;
}
.tab-btn.active { background: var(--primary-color); color: white; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }

.theme-select {
    padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border-color);
    background: var(--card-bg); color: var(--text-color); font-size: 13px; font-weight: 600;
    cursor: pointer; outline: none; transition: all 0.3s; height: 36px;
}
.theme-select:hover { border-color: var(--primary-color); }

.secondary-btn {
    padding: 8px 14px; border-radius: 8px; background: rgba(0,0,0,0.03);
    border: 1px solid var(--border-color); color: var(--text-color); font-size: 13px; font-weight: 600;
    height: 36px;
}
body[data-theme="dark"] .secondary-btn { background: rgba(255,255,255,0.1); }
.secondary-btn:hover { background: rgba(0,0,0,0.08); }
body[data-theme="dark"] .secondary-btn:hover { background: rgba(255,255,255,0.2); }

.main-content {
    flex: 1; overflow-y: auto; overflow-x: hidden; position: relative; padding: 20px 0;
}

.week-navigation {
    display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,0.1); border-top: var(--glass-border); padding: 8px 40px; gap: 10px;
}
body[data-theme="dark"] .week-navigation { background: rgba(0,0,0,0.1); border-top: 1px solid rgba(255, 255, 255, 0.05); }

.current-week-label { font-size: 13px; font-weight: 700; color: var(--text-color); margin: 0 10px; }

.icon-btn {
    background: transparent; color: var(--text-muted); padding: 6px 12px; border-radius: 6px;
    font-size: 12px; font-weight: 600; cursor: pointer; border: none; transition: 0.2s;
}
.icon-btn:hover { background: rgba(0,0,0,0.05); color: var(--primary-color); }
body[data-theme="dark"] .icon-btn:hover { background: rgba(255,255,255,0.1); }

.border-btn { border: 1px solid var(--border-color); }

/* 1週間 俯瞰(ふかん) グリッドレイアウト */
.week-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px; padding: 10px 40px 40px 40px;
    box-sizing: border-box; align-items: stretch; max-width: 1600px; margin: 0 auto;
    transition: opacity 0.3s ease;
}

@media (min-width: 1400px) {
    /* 大画面なら上4日、下3日など綺麗に収める */
    .week-container { grid-template-columns: repeat(4, 1fr); }
}


.day-card {
    background: var(--card-bg); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border: var(--glass-border); border-radius: 20px; padding: 20px; box-shadow: var(--glass-shadow);
    display: flex; flex-direction: column;
    animation: fadeIn 0.5s ease-out forwards; transition: background 0.4s ease, border-color 0.4s ease;
}

.day-card.today-card { border: 2px solid var(--primary-color); box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.15); }

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

.card-header h2 { font-size: 16px; margin: 0 0 16px; color: var(--text-color); }
.today-card .card-header h2 { color: var(--primary-color); font-weight: 700; }

.task-input-section { display: flex; gap: 8px; margin-bottom: 16px; }

input[type="text"] {
    flex: 1; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.2); color: var(--text-color); font-size: 14px; transition: all 0.3s;
}
body[data-theme="dark"] input[type="text"] { background: rgba(13, 17, 23, 0.6); }

input[type="text"]:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 2px rgba(0,0,0,0.05); }

button { cursor: pointer; font-family: 'Inter', sans-serif; font-weight: 600; border: none; transition: all 0.3s ease; }

.add-task-btn { padding: 0 12px; border-radius: 8px; background: var(--primary-color); color: #fff; font-size: 13px; }
.add-task-btn:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); }
.add-task-btn:disabled, input[type="text"]:disabled { opacity: 0.5; cursor: not-allowed; }

.task-list { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }

.task-item {
    display: flex; align-items: flex-start; padding: 10px; background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--border-color); border-radius: 10px; position: relative; transition: all 0.2s;
}
body[data-theme="dark"] .task-item { background: rgba(255, 255, 255, 0.03); }

.task-item:not(.empty):hover { background: rgba(0, 0, 0, 0.04); }
body[data-theme="dark"] .task-item:not(.empty):hover { background: rgba(255, 255, 255, 0.06); }

.task-item.empty { background: transparent; border-style: dashed; opacity: 0.5; }
.task-item.completed { opacity: 0.6; }
.task-item.completed .task-text { text-decoration: line-through; color: var(--text-muted); }

.rank {
    width: 20px; height: 20px; background: rgba(0,0,0,0.05); color: var(--primary-color);
    border-radius: 50%; display: flex; justify-content: center; align-items: center;
    font-size: 11px; font-weight: 700; margin-right: 10px; flex-shrink: 0; margin-top: 1px;
}
body[data-theme="dark"] .rank { background: rgba(255,255,255,0.05); }

.empty-rank { color: var(--text-muted); }
.empty-text { color: var(--text-muted); font-size: 13px; font-style: italic; margin-top: 1px; }

.checkbox {
    appearance: none; width: 18px; height: 18px; border: 2px solid var(--border-color);
    border-radius: 5px; margin-right: 10px; cursor: pointer; position: relative; flex-shrink: 0; margin-top: 2px;
}
.checkbox:checked { background-color: var(--success-color); border-color: var(--success-color); }
.checkbox:checked::after {
    content: ''; position: absolute; top: 2px; left: 5px; width: 3px; height: 7px;
    border: solid white; border-width: 0 2px 2px 0; transform: rotate(45deg);
}

.task-text { flex: 1; font-size: 14px; line-height: 1.4; word-break: break-all; margin-top: 2px;}

.delete-btn { background: none; color: var(--text-muted); font-size: 18px; padding: 0 4px; opacity: 0; transition: opacity 0.2s; }
.task-item:hover .delete-btn { opacity: 1; }
@media (hover: none) { .delete-btn { opacity: 0.5; } }
.delete-btn:hover { color: var(--danger-color); transform: scale(1.2); }

.drag-handle {
    display: flex; align-items: center; justify-content: center;
    width: 28px; flex-shrink: 0; color: var(--text-muted);
    font-size: 16px; cursor: grab; touch-action: none; user-select: none;
    opacity: 0.35; transition: opacity 0.2s;
}
.drag-handle:active { cursor: grabbing; }
.task-item:hover .drag-handle { opacity: 0.7; }
@media (hover: none) { .drag-handle { opacity: 0.5; } }

.task-item.dragging {
    opacity: 0.45;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.actions-section { margin-top: auto; padding-top: 10px; }

.carry-over-btn {
    padding: 10px; border-radius: 8px; background: var(--primary-color);
    color: white; font-size: 13px; width: 100%; transition: filter 0.2s;
}
.carry-over-btn:hover { filter: brightness(1.1); box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.all-done-msg { text-align: center; color: var(--success-color); font-weight: 600; font-size: 13px; padding: 5px 0; }

.danger-btn {
    padding: 10px 16px; border-radius: 8px; background: transparent; border: 1px solid var(--danger-color);
    color: var(--danger-color); font-size: 14px;
}
.danger-btn:hover { background: rgba(248, 81, 73, 0.1); }

/* Modals */
.modal {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(3px); z-index: 1000;
    display: flex; justify-content: center; align-items: center; opacity: 1; transition: opacity 0.3s;
}
.modal.hidden { opacity: 0; pointer-events: none; }

.modal-content {
    background: var(--bg-color); border: var(--glass-border); border-radius: 16px; width: 90%;
    max-width: 500px; max-height: 80vh; display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}

.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-header h2 { margin: 0; font-size: 18px; }
.close-btn { background: none; color: var(--text-muted); font-size: 24px; padding: 0 5px; }
.close-btn:hover { color: var(--danger-color); }

.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border-color); text-align: right; background: rgba(0,0,0,0.02); border-bottom-left-radius: 16px; border-bottom-right-radius: 16px; }

.history-list { list-style: none; padding: 0; margin: 0; }
.history-date-header { font-size: 14px; color: var(--primary-color); margin: 20px 0 10px; border-bottom: 1px solid var(--border-color); padding-bottom: 5px; }
.history-date-header:first-child { margin-top: 0; }
.history-item { display: flex; padding: 10px 0; border-bottom: 1px dashed rgba(0,0,0,0.1); gap: 15px; }
body[data-theme="dark"] .history-item { border-bottom: 1px dashed rgba(255,255,255,0.1); }

.history-time { font-family: monospace; color: var(--text-muted); font-size: 13px; }
.history-text { color: var(--text-color); font-size: 14px; }
.empty-msg { color: var(--text-muted); text-align: center; padding: 30px 0; }

/* Routine UI */
.routine-list-item {
    background: rgba(0,0,0,0.02); border: 1px solid var(--border-color);
    border-radius: 12px; padding: 12px 16px; display: flex; justify-content: space-between; align-items: center;
}
body[data-theme="dark"] .routine-list-item { background: rgba(255,255,255,0.03); }

.routine-info { display: flex; flex-direction: column; gap: 4px; }
.routine-name { font-weight: 700; font-size: 14px; color: var(--text-color); }
.routine-rule { font-size: 11px; color: var(--text-muted); background: rgba(0,0,0,0.05); padding: 2px 8px; border-radius: 4px; align-self: flex-start; }
body[data-theme="dark"] .routine-rule { background: rgba(255,255,255,0.05); }

.hidden { display: none !important; }

/* Accessibility Focus */
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--primary-color); outline-offset: 2px; }

/* Adjust for mobile to easily scroll if grid collapses to 1 column */
@media (max-width: 768px) {
    .app-header { padding: 12px 16px; }
    .week-container { padding: 8px 12px 24px; grid-template-columns: 1fr; }
    .header-content { flex-direction: column; align-items: flex-start; }
    .header-right-group { width: 100%; justify-content: space-between; }
    .controls-row { flex-wrap: wrap; }
    .week-navigation { padding: 8px 12px; justify-content: space-between; gap: 4px; }
    .current-week-label { font-size: 11px; margin: 0; text-align: center; }
}
@media (max-width: 400px) {
    .week-container { padding: 6px 8px 20px; }
    .day-card { padding: 14px; }
}
