:root {
  --bg-color: #0f172a;      /* 深い青の背景 */
  --surface-color: rgba(30, 41, 59, 0.7); /* 半透明の表面 (Glassmorphism) */
  --primary-color: #38bdf8; /* アクセントの水色 */
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: rgba(255, 255, 255, 0.1);
  --danger-color: #ef4444;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent; /* スマホタップ時のハイライト消去 */
}

body {
  font-family: 'Inter', 'Noto Sans JP', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  /* ダークモダンなグラデーション背景 */
  background: radial-gradient(circle at top right, #1e293b 0%, #0f172a 100%);
  background-attachment: fixed;
  overscroll-behavior-y: none; /* スマホの引っ張り更新を防止 */
}

#app-container {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* 画面切り替え */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.screen.active {
  display: flex;
  opacity: 1;
}

/* Glassmorphism Panel */
.glass-panel {
  background: var(--surface-color);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
}

/* --- ログイン画面 --- */
#login-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 20px;
}
.login-box {
  background: var(--surface-color);
  backdrop-filter: blur(10px);
  padding: 40px 30px;
  border-radius: 24px;
  border: 1px solid var(--border-color);
  width: 100%;
  max-width: 400px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}
.login-box h1 {
  font-size: 2.2rem;
  color: var(--primary-color);
  margin-bottom: 8px;
  letter-spacing: 1px;
}
.login-box p {
  color: var(--text-muted);
  margin-bottom: 30px;
}

/* --- ボタン --- */
button {
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: all 0.2s ease;
}
.btn-primary {
  background: var(--primary-color);
  color: #0f172a;
  font-weight: 600;
  padding: 14px 24px;
  border-radius: 12px;
  font-size: 1rem;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}
.btn-primary:active {
  transform: scale(0.98);
  opacity: 0.9;
}
.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  font-weight: 600;
  padding: 14px 24px;
  border-radius: 12px;
  font-size: 1rem;
  width: 100%;
}
.btn-icon {
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  padding: 10px;
  border-radius: 50%;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}
.btn-icon:hover, .btn-icon:active {
  color: var(--primary-color);
  background: rgba(56, 189, 248, 0.1);
}
.btn-icon.active {
  color: var(--danger-color);
  background: rgba(239, 68, 68, 0.1);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* --- メイン画面ヘッダー --- */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--primary-color);
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
}
#user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--primary-color);
}

main {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* --- 下部ナビゲーション (スマホ風) --- */
.nav-tabs {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  display: flex;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border-color);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 50;
}
.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 0.75rem;
  font-weight: 600;
  gap: 4px;
}
.nav-tab .nav-icon {
  font-size: 1.4rem;
  transition: transform 0.2s;
}
.nav-tab.active {
  color: var(--primary-color);
}
.nav-tab.active .nav-icon {
  transform: scale(1.1);
}
.tab-content {
  display: none;
  flex-direction: column;
  flex: 1;
}
.tab-content.active {
  display: flex;
  animation: fadeIn 0.3s ease;
}

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

/* --- カレンダー --- */
.calendar-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px; /* 省スペース化 */
}
.calendar-controls h2 {
  font-size: 1.1rem; /* 省スペース化 */
  font-weight: 600;
}
.calendar-grid {
  background: var(--surface-color);
  border-radius: 16px;
  border: 1px solid var(--border-color);
  padding: 10px; /* 省スペース化 */
  margin-bottom: 12px; /* 省スペース化 */
}
.weekdays-wrapper {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px; /* 省スペース化 */
}
.calendar-days-container {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px; /* 省スペース化 */
}
.weekday {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.day-cell {
  width: 35px;
  height: 35px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  font-size: 0.9rem; /* 省スペース化 */
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}
.day-cell:active {
  transform: scale(0.9);
}
.day-cell.today {
  color: var(--primary-color);
  font-weight: bold;
}
.day-cell.selected {
  background: var(--primary-color);
  color: #0f172a;
  font-weight: bold;
}
.day-cell.has-memo::after {
  content: '';
  position: absolute;
  bottom: 4px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background-color: var(--primary-color);
}
.day-cell.selected.has-memo::after {
  background-color: #0f172a;
}
.day-cell.empty {
  visibility: hidden;
}

/* --- メモエリア＆タイムライン --- */
#memo-area {
  flex: 1;
  display: flex;
  flex-direction: column;
}
#selected-date-display {
  font-size: 1.1rem;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
  color: var(--primary-color);
}

.timeline-list {
  flex: 1;
  overflow-y: auto;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-left: 20px; /* タイムラインの線のスペース */
}

/* タイムラインの縦線 */
.timeline-list::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 6px;
  width: 2px;
  background: var(--border-color);
}

.memo-item {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  position: relative;
  margin-left: 10px;
}

/* タイムラインのドット */
.memo-item::before {
  content: '';
  position: absolute;
  left: -20px;
  top: 16px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary-color);
  box-shadow: 0 0 8px var(--primary-color);
}

.memo-time-badge {
  display: inline-block;
  background: rgba(56, 189, 248, 0.2);
  color: var(--primary-color);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.memo-item p {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
}
.memo-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 8px;
  display: block;
}
.memo-image {
  margin-top: 8px;
  max-width: 100%;
  border-radius: 8px;
  max-height: 200px;
  object-fit: cover;
}
.btn-delete-memo {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.memo-input-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(0, 0, 0, 0.2);
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--border-color);
}
.input-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}
#memo-input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: inherit;
  resize: none;
  min-height: 60px;
  font-size: 1rem;
}
#memo-input:focus {
  outline: none;
}
#memo-input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

.time-picker {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 8px;
  padding: 6px 10px;
  font-family: inherit;
}

.btn-mic-large {
  color: var(--primary-color);
  background: rgba(56, 189, 248, 0.1);
  font-size: 1.4rem;
  padding: 12px;
}
.input-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.input-actions .btn-primary {
  margin-left: auto;
  width: auto;
  padding: 10px 24px;
}

.upload-preview {
  position: relative;
  display: inline-block;
  margin-top: 8px;
}
.upload-preview img {
  height: 60px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}
.btn-icon-small {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--danger-color);
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 0.7rem;
  border: none;
}

/* --- タイマーエリア (メモリちゃん) --- */
.timer-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 30px 20px;
}
.memori-chan-avatar {
  position: relative;
  width: 120px; /* 少し大きく */
  height: 120px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  margin-bottom: 20px;
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.2);
  overflow: hidden; /* はみ出した部分を隠す */
}
.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover; /* 枠いっぱいに広げる */
  object-position: center top; /* 画像の上端に合わせる */
  transform: scale(1.6); /* 1.6倍にズーム */
  transform-origin: top center; /* ズームの中心を「上端」にする（これで耳が切れない） */
}
.memori-dialog {
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid var(--primary-color);
  padding: 12px 20px;
  border-radius: 20px;
  margin-bottom: 30px;
  position: relative;
  font-size: 0.95rem;
}
.memori-dialog::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 0 10px 10px 10px;
  border-style: solid;
  border-color: transparent transparent var(--primary-color) transparent;
}
.timer-display {
  font-size: 4rem;
  font-weight: 300;
  font-family: 'Inter', sans-serif;
  color: var(--primary-color);
  margin-bottom: 30px;
  letter-spacing: 2px;
}
.timer-custom-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  width: 100%;
  align-items: center;
  justify-content: center;
}
.timer-input-group {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px 12px;
}
.timer-input-group input {
  background: transparent;
  border: none;
  color: var(--primary-color);
  font-size: 1.5rem;
  font-weight: 600;
  width: 60px;
  text-align: center;
}
.timer-input-group input:focus {
  outline: none;
}
.timer-input-group span {
  color: var(--text-muted);
  margin-right: 10px;
}
.btn-small {
  padding: 6px 12px;
  font-size: 0.9rem;
}

.btn-mic-timer {
  background: rgba(56, 189, 248, 0.1);
  color: var(--primary-color);
  font-size: 1.4rem;
  padding: 12px;
  border-radius: 50%;
}
.btn-mic-timer.active {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger-color);
}
.timer-actions {
  display: flex;
  gap: 10px;
  width: 100%;
}
.timer-actions .btn-primary, .timer-actions .btn-secondary {
  flex: 1;
}

/* Utils */
.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  color: var(--primary-color);
  font-size: 2rem;
  display: none;
}
.loading-overlay.active {
  display: flex;
}

/* --- 401K Styles --- */
#four01k-tab {
  padding: 10px;
}
.f-dashboard {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
}
.f-total-profit-box {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 15px;
  border-radius: 12px;
  text-align: center;
  flex: 1;
}
.f-lbl {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.f-val {
  font-size: 1.5rem;
  font-weight: 700;
  color: #10b981;
}

/* 401K History List */
.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.history-item:last-child {
    border-bottom: none;
}
.h-date { font-size: 0.75rem; color: var(--text-muted); }
.h-type { font-weight: bold; font-size: 0.9rem; margin-bottom: 4px; }
.h-buy { color: #3b82f6; }
.h-sell { color: #10b981; }
.h-amount { font-size: 1rem; font-weight: bold; }
.h-btn-del {
    background: transparent;
    border: none;
    color: var(--danger-color);
    cursor: pointer;
    padding: 5px;
    box-shadow: none;
    width: auto;
}
