/* MyDesk — iPhone 風ホーム v2（PC / モバイル統一シェル） */

:root {
  --ios-home-width: 420px;
  --ios-home-pad-x: 1rem;
}

/* --- ホーム: 日時・挨拶はモバイル上部バーへ（home.js が描画） --- */

@media (max-width: 768px) {
  body[data-view="dashboard"] .mobile-bar .brand-icon {
    display: none;
  }

  body[data-view="dashboard"] .mobile-bar-title strong {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
  }

  body[data-view="dashboard"] .mobile-bar-title .mobile-date {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--muted);
  }
}

/* --- ダッシュボード全体のキャンバス（PC / モバイル共通の壁紙） --- */

body[data-view="dashboard"] #view-dashboard {
  position: relative;
  isolation: isolate;
}

body[data-view="dashboard"] #view-dashboard::before {
  content: "";
  position: absolute;
  inset: -1.5rem -1rem 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 90% 55% at 15% -5%, rgba(124, 108, 240, 0.42), transparent 58%),
    radial-gradient(ellipse 75% 50% at 95% 8%, rgba(255, 130, 85, 0.28), transparent 52%),
    radial-gradient(ellipse 65% 45% at 50% 105%, rgba(52, 211, 153, 0.16), transparent 55%),
    linear-gradient(180deg, rgba(10, 8, 21, 0.15) 0%, transparent 35%);
}

@media (min-width: 769px) {
  body[data-view="dashboard"] #view-dashboard::before {
    inset: -2rem 0 0;
    border-radius: 0;
  }
}

:root[data-theme="light"] body[data-view="dashboard"] #view-dashboard::before {
  background:
    radial-gradient(ellipse 90% 55% at 15% -5%, rgba(124, 108, 240, 0.22), transparent 58%),
    radial-gradient(ellipse 75% 50% at 95% 8%, rgba(255, 150, 95, 0.18), transparent 52%),
    radial-gradient(ellipse 65% 45% at 50% 105%, rgba(52, 211, 153, 0.1), transparent 55%),
    linear-gradient(180deg, rgba(255, 250, 246, 0.95) 0%, transparent 40%);
}

@media (min-width: 769px) {
  body[data-view="dashboard"] .main {
    max-width: none;
    padding-top: 1.75rem;
    padding-bottom: 2.5rem;
  }

  body[data-view="dashboard"] #view-dashboard {
    width: min(var(--ios-home-width), 100%);
    margin: 0 auto;
  }
}

.ios-home-v2 {
  position: relative;
  width: min(var(--ios-home-width), 100%);
  max-width: var(--ios-home-width);
  margin: 0 auto;
  padding: 0 var(--ios-home-pad-x) 2rem;
  isolation: isolate;
}

.ios-home-wallpaper {
  display: none;
}

.ios-home-v2 > :not(.ios-home-wallpaper):not(.ios-home-legacy) {
  position: relative;
  z-index: 1;
}

/* --- Hero（非表示・互換用にスタイルのみ残す） --- */

.ios-home-hero {
  display: none !important;
}

.ios-home-time,
  margin: 0;
  font-size: 3.5rem;
  font-weight: 200;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.ios-home-date {
  margin: 0.5rem 0 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--muted);
}

.ios-home-greeting {
  margin: 0.25rem 0 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

#view-dashboard .page-header {
  display: none;
}

/* --- Bento --- */

.ios-bento {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
  margin-bottom: 1.4rem;
}

.ios-bento-cell {
  border-radius: 22px;
  border: 1px solid var(--glass-border);
  background: var(--glass-regular);
  backdrop-filter: var(--glass-nav);
  -webkit-backdrop-filter: var(--glass-nav);
  padding: 0.9rem 0.95rem;
  box-shadow:
    var(--shadow-sm),
    inset 0 1px 0 var(--glass-highlight);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .ios-bento-cell {
    background: var(--surface-solid);
  }
}

.ios-bento-mq {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, rgba(124, 108, 240, 0.28), rgba(255, 180, 100, 0.14));
  border-color: rgba(124, 108, 240, 0.32);
}

:root[data-theme="light"] .ios-bento-mq {
  background: linear-gradient(135deg, rgba(124, 108, 240, 0.14), rgba(255, 180, 100, 0.1));
}

.ios-bento-focus,
.ios-bento-briefing {
  grid-column: 1 / -1;
}

.ios-bento-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.ios-bento-label {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.ios-bento-link {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-alt);
  cursor: pointer;
}

.ios-bento-mq-title {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -0.02em;
}

/* --- 習慣リング --- */

.ios-habit-ring-wrap {
  position: relative;
  width: 3.75rem;
  height: 3.75rem;
  margin: 0 auto 0.6rem;
}

.ios-habit-ring {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: conic-gradient(
    var(--accent) calc(var(--ring-pct, 0) * 1%),
    rgba(255, 255, 255, 0.14) 0
  );
  mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px));
}

.ios-habit-ring-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* --- Bento lists --- */

.ios-bento-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ios-bento-row {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  width: 100%;
  padding: 0.34rem 0;
  border: none;
  background: none;
  font: inherit;
  font-size: 0.8125rem;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.ios-bento-row input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 0.12rem;
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
}

.ios-bento-check {
  flex-shrink: 0;
  width: 1.15rem;
  height: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  font-size: 0.65rem;
  color: var(--accent);
}

.ios-bento-row.done .ios-bento-check {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.ios-bento-row-text {
  flex: 1;
  line-height: 1.35;
}

.ios-bento-row.done .ios-bento-row-text {
  text-decoration: line-through;
  opacity: 0.55;
}

.ios-bento-row.main-quest .ios-bento-row-text {
  font-weight: 700;
  color: var(--accent);
}

.ios-bento-empty {
  font-size: 0.8125rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.ios-bento-focus-input {
  width: 100%;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  padding: 0.15rem 0 0;
}

.ios-bento-focus-input:focus {
  outline: none;
}

.ios-bento-focus-input::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

.ios-bento-briefing .ios-briefing-body {
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
}

.ios-bento-briefing .ios-briefing-body.muted {
  color: var(--muted);
}

.ios-bento-briefing .ios-briefing-body.ios-briefing-error strong {
  color: var(--high);
}

/* --- Spring tap --- */

.ios-spring,
.ios-bento-row {
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ios-spring:active .ios-app-icon,
.ios-bento-row:active {
  transform: scale(0.94);
}

/* --- App grid（4列固定・Squircle） --- */

.ios-apps-section {
  margin-bottom: 1rem;
}

.ios-app-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1.2rem 0.6rem;
}

.ios-app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.38rem;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  font: inherit;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

.ios-app-icon-wrap {
  position: relative;
}

.ios-app-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3.65rem;
  height: 3.65rem;
  border-radius: 22%;
  color: #fff;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ios-app-icon svg {
  width: 1.6rem;
  height: 1.6rem;
}

.ios-app-icon--tasks { background: linear-gradient(145deg, #5b9cff, #2563eb); }
.ios-app-icon--habits { background: linear-gradient(145deg, #34d399, #059669); }
.ios-app-icon--calendar { background: linear-gradient(145deg, #ff7070, #e03131); }
.ios-app-icon--journal { background: linear-gradient(145deg, #c084fc, #9333ea); }
.ios-app-icon--projects { background: linear-gradient(145deg, #818cf8, #4f46e5); }
.ios-app-icon--goals { background: linear-gradient(145deg, #fbbf24, #d97706); }
.ios-app-icon--levels { background: linear-gradient(145deg, #f472b6, #db2777); }
.ios-app-icon--body { background: linear-gradient(145deg, #2dd4bf, #0d9488); }
.ios-app-icon--finance { background: linear-gradient(145deg, #a3e635, #65a30d); }
.ios-app-icon--business { background: linear-gradient(145deg, #94a3b8, #475569); }
.ios-app-icon--sns { background: linear-gradient(145deg, #fb7185, #e11d48); }
.ios-app-icon--dev { background: linear-gradient(145deg, #64748b, #334155); }
.ios-app-icon--ai {
  background: linear-gradient(145deg, #a78bfa, #7c3aed);
  box-shadow:
    0 4px 16px rgba(124, 108, 240, 0.48),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.ios-app-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 1.2rem;
  height: 1.2rem;
  padding: 0 0.32rem;
  border-radius: 999px;
  background: var(--high);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 700;
  line-height: 1.2rem;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.ios-app-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Secondary --- */

.ios-home-secondary {
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  background: var(--glass-regular);
  backdrop-filter: var(--glass-nav);
  -webkit-backdrop-filter: var(--glass-nav);
  padding: 0.7rem 0.9rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow-sm);
}

.ios-home-secondary summary {
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
  list-style: none;
}

.ios-home-secondary summary::-webkit-details-marker {
  display: none;
}

.ios-home-secondary-body {
  margin-top: 0.75rem;
  display: grid;
  gap: 0.75rem;
  min-width: 0;
}

.ios-home-v2 > .r5-ritual-banner {
  margin-bottom: 0.65rem;
}

.ios-home-secondary .r5-rings-card,
.ios-home-secondary .r5-ai-panel,
.ios-home-secondary .card {
  margin: 0;
  min-width: 0;
}

.ios-home-secondary .r5-rings-svg-wrap {
  max-width: 100%;
}

#view-dashboard {
  min-width: 0;
  overflow-x: clip;
}

/* legacy hidden（テスト互換） */
.ios-home-legacy {
  display: none !important;
}

.ios-widget-summary .ios-widget-stat {
  display: inline-flex;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: var(--accent-soft);
  font-size: 0.78rem;
  font-weight: 600;
}

.ios-widget-summary .ios-widget-stat.is-alert {
  background: rgba(255, 120, 100, 0.18);
  color: var(--high);
}

/* --- ビュー戻る --- */

.view-app-header {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.view-back-btn {
  flex-shrink: 0;
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  margin-top: 0.15rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-solid);
  color: var(--accent-alt);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.view-app-header .page-header {
  display: block !important;
}

.mobile-back-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  margin-right: 0.15rem;
  border: none;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-alt);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .mobile-back-btn:not([hidden]) {
    display: flex;
  }

  .view-back-btn {
    display: flex;
  }

  #view-dashboard .mobile-quick {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ios-spring,
  .ios-bento-row,
  .ios-app-icon {
    transition: none;
  }
}
