* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", "Yu Gothic", "Noto Sans CJK JP", sans-serif;
  background: #fff8e7; color: #222;
  display: flex; flex-direction: column;
  overflow: hidden; touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button {
  border: 2px solid #b9a98a; background: #fff; border-radius: 12px;
  padding: .5em 1em; cursor: pointer;
}
button:active { background: #f0e6cf; }
button.primary { background: #2f7d4f; border-color: #2f7d4f; color: #fff; }
button.ghost { border-color: transparent; background: transparent; text-decoration: underline; }
button.nav { font-size: 1.4em; min-width: 2.6em; }
button:disabled { opacity: .3; }

/* 上のバー */
#bar { display: flex; align-items: center; justify-content: center; gap: 1em; padding: .4em .8em; flex: none; }
#dateTitle { font-size: clamp(1.4rem, 3.6vw, 2.6rem); font-weight: 700; border: none; background: none; padding: .1em .6em; }
#editBar { display: flex; align-items: center; gap: .8em; justify-content: center; background: #ffe08a; padding: .4em; flex: none; }
#editBar span { font-weight: 700; }

/* カード */
#cards {
  flex: 1; min-height: 0; display: grid; gap: 1.2vmin; padding: 0 1.5vmin 1.5vmin;
  grid-template-columns: repeat(var(--cols, 3), 1fr); grid-auto-rows: 1fr;
}
.card {
  --frame: #999;
  position: relative; min-height: 0; min-width: 0;
  display: flex; flex-direction: column;
  border: .9vmin solid var(--frame); border-radius: 2.2vmin; background: #fff; overflow: hidden; padding: 0;
}
.card .photo { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; background: #fff; }
.card .photo img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.card .noPhoto { color: #bbb; font-size: 4vmin; }
.card .name {
  flex: none; text-align: center; font-weight: 700; padding: .25em .3em;
  font-size: clamp(1.1rem, 3.4vmin, 2.4rem); line-height: 1.2; background: #fff;
  overflow-wrap: anywhere;
}
.card.add { border-style: dashed; align-items: center; justify-content: center; font-size: 4vmin; color: #777; }
.g-shushoku { --frame: #f2c200; }
.g-shusai   { --frame: #e2463c; }
.g-fukusai  { --frame: #38a34a; }
.g-shiru    { --frame: #f08a24; }
.g-dessert  { --frame: #2f7fd8; }
.g-other    { --frame: #9a8fb0; }

.tools { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; padding: .5vmin; gap: .5vmin; }
.tools button { padding: .2em .55em; font-size: clamp(1rem, 2.6vmin, 1.5rem); background: rgba(255,255,255,.92); }
.empty { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1em; font-size: 1.6rem; color: #776; text-align: center; }

/* 歯車 */
#gear {
  position: fixed; left: calc(6px + env(safe-area-inset-left)); bottom: calc(6px + env(safe-area-inset-bottom));
  width: 44px; height: 44px; padding: 0; border-radius: 50%; font-size: 22px; opacity: .45; z-index: 5;
}
#gear.holding { opacity: 1; background: #ffe08a; }
#gearHint, #toast {
  position: fixed; left: 58px; bottom: calc(12px + env(safe-area-inset-bottom)); background: #333; color: #fff;
  padding: .4em .9em; border-radius: 10px; z-index: 30; font-size: 1rem;
}
#toast { left: 50%; transform: translateX(-50%); }

/* 拡大 */
#zoom { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 20; }
#zoomCard {
  margin: 0; width: min(92vw, 120vh); height: 92vh; background: #fff; border-radius: 3vmin;
  border: 1.4vmin solid var(--frame, #999); display: flex; flex-direction: column; overflow: hidden;
  animation: pop .25s ease-out;
}
#zoomPhoto { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#zoomPhoto img { width: 100%; height: 100%; object-fit: contain; }
#zoomName { flex: none; text-align: center; font-weight: 700; font-size: clamp(2rem, 8vmin, 5rem); padding: .2em; overflow-wrap: anywhere; }
@keyframes pop { from { transform: scale(.5); opacity: .3; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { #zoomCard { animation: none; } }

/* シート（設定など） */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 25; padding: 2vmin; }
.panel { background: #fffdf6; border-radius: 18px; padding: 1.2em; width: min(760px, 100%); max-height: 100%; overflow: auto; display: flex; flex-direction: column; gap: .8em; -webkit-user-select: text; user-select: text; }
.panel.small { width: min(460px, 100%); }
.panel.wide { width: 100%; height: 100%; }
.panel h2 { margin: 0; font-size: 1.4rem; }
.panel h3 { margin: .6em 0 0; font-size: 1.1rem; }
.panel p { margin: 0; }
.panel.small > button { text-align: left; font-size: 1.15rem; }
.panelHead { display: flex; align-items: center; gap: .8em; flex-wrap: wrap; }
.panelHead h2 { flex: 1; text-align: center; }
.row { display: flex; gap: .6em; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
label { display: flex; flex-direction: column; gap: .25em; font-size: 1rem; }
label.check { flex-direction: row; align-items: center; gap: .5em; }
label.check input { width: 1.3em; height: 1.3em; }
input[type=text], input[type=search], select { border: 2px solid #b9a98a; border-radius: 10px; padding: .5em .7em; font-size: 1.25rem; background: #fff; width: 100%; }
.filebtn { border: 2px solid #b9a98a; background: #fff; border-radius: 12px; padding: .5em 1em; cursor: pointer; }

.editRow { display: flex; gap: 1em; }
#editPhoto { width: 200px; height: 200px; flex: none; border: 2px solid #ddd; border-radius: 12px; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #fff; color: #bbb; }
#editPhoto img { width: 100%; height: 100%; object-fit: contain; }
.editFields { flex: 1; display: flex; flex-direction: column; gap: .7em; min-width: 0; }
@media (max-width: 600px) { .editRow { flex-direction: column; align-items: center; } }

/* 月の一覧 */
#monthGrid { flex: 1; min-height: 0; overflow: auto; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; align-content: start; }
.wd { text-align: center; font-weight: 700; padding: .2em; }
.day { border: 2px solid #d8cdb4; border-radius: 10px; background: #fff; padding: 4px; text-align: left; display: flex; flex-direction: column; gap: 3px; min-height: 110px; }
.day.blank { border-color: transparent; background: none; }
.day.cur { border-color: #2f7d4f; box-shadow: 0 0 0 2px #2f7d4f; }
.day.edited .dnum::after { content: " ✎"; color: #c07000; }
.dnum { font-weight: 700; font-size: 1.05rem; }
.thumbs { display: flex; gap: 2px; flex-wrap: wrap; }
.thumbs img, .thumbs i { width: 34px; height: 34px; object-fit: cover; border-radius: 5px; border: 2px solid var(--frame, #ccc); background: #f3f3f3; }
.dnames { font-size: .72rem; line-height: 1.25; color: #444; overflow: hidden; }

/* 写真えらび */
#pickSearch { flex: 1; min-width: 160px; width: auto; }
#pickGroups { display: flex; gap: 6px; flex-wrap: wrap; }
#pickGroups button { padding: .3em .7em; font-size: .95rem; }
#pickGroups button.on { background: #2f7d4f; color: #fff; border-color: #2f7d4f; }
#pickGrid { flex: 1; min-height: 0; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; align-content: start; }
.pick { padding: 4px; display: flex; flex-direction: column; gap: 2px; border-color: var(--frame, #ccc); border-width: 3px; }
.pick img, .pick i { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; background: #f3f3f3; display: block; }
.pick span { font-size: .85rem; line-height: 1.2; overflow-wrap: anywhere; }

/* データ */
#dataMonths { display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow: auto; }
.mrow { display: flex; align-items: center; gap: .8em; border-bottom: 1px solid #e5dcc6; padding: .3em 0; }
.mrow b { flex: 1; }
.mrow small { color: #666; }
