:root {
  --bg: #f8f5ef;
  --bg-main: #f0f2e8;
  --card: #fffaf2;
  --line: #e7dcc8;
  --line-pistachio: #c5d0b0;
  --text: #2d2a26;
  --accent: #8c5a2e;
  --pistachio: #8a9a6b;
  --white-soft: #f5f5f2;
  --main-side-padding: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans JP", sans-serif;
  overflow-x: hidden;
  min-width: 0;
}

/* ログインページ（ピスタチオ基調） */
.login-page {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  background-color: var(--bg-main);
  font-family: "Noto Sans JP", sans-serif;
}

.login-container {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--line-pistachio);
  border-radius: 0.375rem;
  box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.06);
  overflow: hidden;
}

.login-card-body {
  padding: 1.5rem;
}

.login-card-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-logo {
  display: block;
  margin: 0 auto 0.5rem;
}

.login-card-title {
  font-family: "Montserrat", sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.login-form-group {
  margin-bottom: 1rem;
}

.login-form-label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}

.login-form-control {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0.375rem 0.75rem;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--white-soft);
  border: 1px solid var(--line-pistachio);
  border-radius: 0.375rem;
  box-sizing: border-box;
}

.login-form-control::placeholder {
  color: #6c757d;
}

.login-form-control:focus {
  outline: 0;
  border-color: var(--pistachio);
  box-shadow: 0 0 0 0.2rem rgba(138, 154, 107, 0.25);
}

.login-btn-primary {
  width: 100%;
  min-height: 44px;
  padding: 0.375rem 0.75rem;
  font-size: 1rem;
  font-weight: 500;
  color: var(--white-soft);
  background-color: var(--pistachio);
  border: 1px solid var(--pistachio);
  border-radius: 0.375rem;
  cursor: pointer;
}

.login-btn-primary:hover {
  background-color: #7a8a5d;
  border-color: #7a8a5d;
}

.login-error {
  color: #b22424;
  font-size: 0.875rem;
  margin: 0 0 1rem;
}

.login-form .login-error:last-child {
  margin-top: 0.75rem;
  margin-bottom: 0;
}

.login-form {
  display: block;
}

input,
button {
  min-height: 44px;
  font-size: 16px;
}

.error {
  color: #b22424;
}

.app-shell {
  min-height: 100dvh;
  min-width: 0;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  display: grid;
  grid-template-rows: 60px 1fr;
  overflow-x: hidden;
}

.app-header,
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 0 var(--main-side-padding);
  padding-bottom: max(0px, env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.app-header {
  position: relative;
  z-index: 20;
  background: var(--pistachio);
  border-top: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--white-soft);
}

.header-logo-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-logo-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: contain;
  display: block;
}

.header-title {
  font-family: "Montserrat", sans-serif;
  font-weight: 400;
  font-size: 1.3rem;
}

.header-logo-link {
  display: flex;
  align-items: center;
  gap: 8px;
  color: inherit;
  text-decoration: none;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-icon-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: inherit;
  text-decoration: none;
  font-size: 22px;
  border-radius: 8px;
  transition: opacity 0.2s;
}

.header-icon-link:hover {
  opacity: 0.85;
}

.header-icon-link-active {
  opacity: 0.9;
}

.side-menu {
  position: relative;
}

.side-menu summary {
  list-style: none;
}

.side-menu summary::-webkit-details-marker {
  display: none;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  font-size: 20px;
}

.hamburger {
  font-size: 24px;
}

.side-menu-panel {
  position: absolute;
  top: 42px;
  right: 0;
  width: min(280px, 86vw);
  background: #fff;
  border: 1px solid var(--line-pistachio);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
}

.side-menu-header {
  padding: 12px;
  background: var(--pistachio);
  color: var(--white-soft);
  border-radius: 11px 11px 0 0;
  border-bottom: 1px solid var(--line-pistachio);
  font-weight: 700;
}

.side-menu-content {
  padding: 10px 12px;
  display: grid;
  gap: 10px;
  color: var(--text);
}

.side-menu-content a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.side-menu-content form button {
  width: 100%;
  border: 1px solid var(--line-pistachio);
  border-radius: 10px;
  background: var(--white-soft);
  color: var(--text);
  font-weight: 500;
}

.side-menu-content form button:hover {
  background: var(--line-pistachio);
}

.user-email {
  margin: 0;
  font-size: 13px;
  color: var(--text);
  opacity: 0.9;
}

.app-main {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  overflow: hidden;
  background: var(--bg-main);
}

.hero {
  padding: 16px var(--main-side-padding) 12px var(--main-side-padding);
  max-width: 100%;
}

/* main 上部の挨拶エリア（単語学習アプリの question-area + speech-bubble と同様） */
.miso-greeting {
  display: flex;
  align-items: flex-start;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  position: relative;
  margin-bottom: 4px;
}

.miso-avatar {
  width: 50px;
  height: 50px;
  margin-right: 10px;
  flex-shrink: 0;
  object-fit: contain;
  display: block;
}

.miso-greeting .speech {
  position: relative;
  background-color: #f7fbff;
  color: #102a43;
  border-radius: 10px;
  padding: 15px 15px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  flex-grow: 1;
  margin-left: 5px;
  min-height: 40px;
  display: flex;
  align-items: center;
  border: 1px solid #dcebfa;
  font-size: clamp(14px, 3.2vw, 15px);
  font-weight: 400;
  line-height: 1.5;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: pre-line;
}

.miso-greeting .speech::before {
  content: "";
  position: absolute;
  top: 15px;
  left: -10px;
  width: 20px;
  height: 30px;
  border-radius: 0 0 0 15px;
  box-shadow: -3px -15px 0 -7px #f7fbff inset;
  z-index: 1;
}

.miso-greeting .speech::after {
  content: "";
  position: absolute;
  top: 15px;
  left: -11px;
  width: 20px;
  height: 30px;
  border-radius: 0 0 0 15px;
  box-shadow: -3px -15px 0 -7px #dcebfa inset;
  z-index: 0;
}

.timeline-area {
  min-width: 0;
  overflow: auto;
  padding: 10px var(--main-side-padding) 18px;
  padding-bottom: calc(90px + env(safe-area-inset-bottom));
}

.app-main-album {
  overflow: auto;
  padding-bottom: env(safe-area-inset-bottom);
}

.album-area {
  padding: 16px var(--main-side-padding) 24px;
  min-width: 0;
}

.album-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  min-width: 0;
}

.album-thumb-link {
  display: block;
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line-pistachio);
  background: var(--bg-main);
}

.album-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.album-thumb-date {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 4px 6px;
  font-size: 10px;
  color: var(--white-soft);
  background: rgba(0, 0, 0, 0.5);
}

.album-empty {
  margin: 0;
  font-size: 14px;
  color: var(--text);
  opacity: 0.8;
}

.entry-grid-wrap {
  min-width: 0;
}

.entry-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.entry-section {
  position: relative;
  min-width: 0;
  background: #fff;
  border: 1px solid var(--line-pistachio);
  border-radius: 0;
  padding: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
}

.entry-section-title-wrap {
  margin: -16px -16px 14px -16px;
  padding: 0 0 0 16px;
  line-height: 2.25;
  font-size: 16px;
  font-weight: 700;
  color: var(--white-soft);
  background: var(--pistachio);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.entry-section-title {
  margin: 0;
  padding: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--white-soft);
  background: none;
}

.entry-date-inline-form {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.entry-date-inline-input {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--white-soft);
  font-size: 16px;
  font-weight: 700;
  line-height: 2.25;
  padding: 0;
  margin: 0;
  min-height: auto;
  width: 10.5ch;
  cursor: pointer;
}

.entry-date-inline-input::-webkit-datetime-edit {
  padding: 0;
}

.entry-date-inline-input::-webkit-calendar-picker-indicator {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.entry-date-form {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.entry-date-input {
  font-size: 12px;
  padding: 2px 4px;
  min-height: auto;
  border-radius: 4px;
  border: 0;
}

.entry-date-btn {
  font-size: 12px;
  padding: 2px 6px;
  min-height: auto;
  border-radius: 999px;
  border: 0;
  background: rgba(255, 255, 255, 0.15);
  color: var(--white-soft);
}

.entry-date-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.entry-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 20px;
  margin-bottom: 16px;
}

.entry-stat-cards {
  gap: 12px 16px;
}

.entry-stat {
  padding: 10px 12px;
  background: var(--bg-main);
  border: 1px solid var(--line-pistachio);
  border-radius: 0;
  min-width: 0;
}

.entry-stat-card {
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--line-pistachio);
  border-radius: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.entry-stat-card .entry-stat-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--pistachio);
  opacity: 1;
  margin-bottom: 8px;
}

.entry-stat-label {
  display: block;
  font-size: 11px;
  color: var(--pistachio);
  opacity: 0.85;
  margin-bottom: 6px;
}

.entry-stat-rows {
  display: grid;
  grid-template-columns: minmax(0, 3.5em) 1fr;
  gap: 0 6px;
  align-items: baseline;
  min-width: 0;
}

.entry-stat-rows + .entry-stat-rows {
  margin-top: 4px;
}

.entry-stat-row-label {
  font-size: 12px;
  color: var(--text);
  opacity: 0.8;
}

.entry-stat-row-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-photo-wrap {
  position: relative;
  width: 100%;
}

.entry-photo-wrap + .entry-photo-wrap {
  margin-top: 8px;
}

.entry-photo-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  margin: 0;
  z-index: 2;
}

.entry-photo-delete-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: var(--white-soft);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.entry-photo-delete-btn:hover {
  background: rgba(0, 0, 0, 0.6);
}

.entry-add-photo {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin: 10px 0 0;
  gap: 4px;
}

.entry-add-photo input[type="file"] {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* カード内追加時: ＋の上に表示 */
.entry-add-photo .photo-generating-msg {
  display: none;
  font-size: 11px;
  color: var(--text);
  opacity: 0.85;
  order: -1;
}

.entry-add-photo.htmx-request .photo-generating-msg {
  display: block;
}

.entry-add-photo-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 2px dashed var(--line-pistachio);
  border-radius: 50%;
  background: var(--bg-main);
  color: var(--text);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  transition: background 0.15s, border-color 0.15s;
}

.entry-add-photo-btn:hover {
  background: var(--card);
  border-color: var(--pistachio);
  color: var(--pistachio);
}

.entry-section img {
  width: 100%;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  vertical-align: top;
  border-radius: 12px;
}

.entry-card-delete {
  margin: 0;
  flex-shrink: 0;
}

.entry-card-delete-btn {
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: var(--white-soft);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.entry-card-delete-btn:hover {
  opacity: 0.85;
}

.entry-memo-wrap {
  margin-top: 10px;
  min-width: 0;
  position: relative;
}

.entry-memo-display {
  font-size: 14px;
  color: var(--text);
  padding: 8px;
  min-height: 2.5em;
  cursor: pointer;
  border-bottom: 1px solid var(--line-pistachio);
  opacity: 0.9;
}

.entry-memo-display.is-placeholder {
  opacity: 0.55;
}

.entry-memo-form {
  display: none;
}

.entry-memo-wrap.edit-mode .entry-memo-display {
  display: none;
}

.entry-memo-wrap.edit-mode .entry-memo-form {
  display: block;
}

.entry-memo-input {
  width: 100%;
  font-size: 14px;
  padding: 8px;
  border: 0;
  border-bottom: 1px solid var(--line-pistachio);
  background: transparent;
  color: var(--text);
  min-width: 0;
}

.entry-memo-input::placeholder {
  opacity: 0.6;
}

.app-footer {
  gap: 10px;
  align-items: center;
}

.quick-entry-form {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
}

.quick-entry-form input[type="file"] {
  display: none;
}

.quick-entry-form input[type="text"] {
  min-height: 40px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  font-size: 14px;
  background: #fff;
}

.icon-btn {
  min-width: 40px;
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 16px;
  cursor: pointer;
}

.footer-menu {
  display: flex;
  align-items: center;
  gap: 6px;
}

.footer-menu a,
.footer-menu button {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  display: grid;
  place-items: center;
  text-decoration: none;
  padding: 0;
  font-size: 16px;
}

/* 新規カード生成時: 象吹き出し下・最新カード上に表示 */
.photo-adding-msg--top {
  display: none;
  padding: 10px 0;
  font-size: 13px;
  color: var(--text);
  opacity: 0.9;
  text-align: center;
}

.app-shell:has(.floating-camera-form.htmx-request) .photo-adding-msg--top {
  display: block;
}

.app-shell:has(.floating-camera-form.htmx-request) #entry-grid .empty {
  display: none;
}

.floating-camera-form {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 40;
}

.floating-camera-form input[type="file"] {
  display: none;
}

.floating-camera-btn {
  width: 58px;
  height: 58px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: var(--pistachio);
  color: var(--white-soft);
  display: grid;
  place-items: center;
  text-decoration: none;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  font-size: 24px;
  cursor: pointer;
}

.loading,
.empty {
  font-size: 14px;
  opacity: 0.8;
}

/* 狭い画面（iPhone SE など）で横スクロールを防ぐ */
@media (max-width: 374px) {
  .quick-entry-form {
    gap: 6px;
  }
}

@media (min-width: 430px) {
  .app-main {
    grid-template-rows: auto 1fr;
  }

  .entry-list {
    gap: 20px;
  }
}

/* 復元完了メッセージ */
.restored-notice {
  margin: 0;
  padding: 12px var(--main-side-padding);
  background: var(--line-pistachio);
  color: var(--text);
  font-size: 14px;
}

/* バックアップ復元ページ */
.restore-page {
  padding: 20px var(--main-side-padding);
}

.restore-title {
  font-size: 1.25rem;
  margin: 0 0 12px;
}

.restore-desc {
  font-size: 14px;
  margin: 0 0 20px;
  opacity: 0.9;
}

.restore-error {
  color: #b22424;
  margin: 0 0 16px;
  font-size: 14px;
}

.restore-form {
  display: grid;
  gap: 16px;
}

.restore-dates label,
.restore-confirm label {
  display: block;
  font-size: 14px;
  margin-bottom: 6px;
}

.restore-dates select,
.restore-confirm input {
  width: 100%;
  min-height: 44px;
  font-size: 16px;
  padding: 8px 12px;
}

.restore-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
}

.restore-cancel {
  color: var(--accent);
  font-size: 14px;
}

.restore-submit {
  min-height: 44px;
  padding: 0 20px;
  background: var(--pistachio);
  color: var(--white-soft);
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
}

.restore-empty {
  margin: 0 0 16px;
  font-size: 14px;
}

.restore-back {
  color: var(--accent);
  font-size: 14px;
}
