:root {
  --sky: #CDEBFF;
  --sky-dot: #B5DFFF;
  --ink: #23304A;
  --blue: #3A8DFF;
  --sun: #FFC83D;
  --leaf: #34C08A;
  --pink: #FF6F9C;
  --paper: #FFFFFF;
  --muted: #6B7A96;
  --radius: 16px;
  --ui: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Hiragino Sans", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--ui);
  font-weight: 500;
  color: var(--ink);
  background-color: var(--sky);
  background-image: radial-gradient(var(--sky-dot) 2.5px, transparent 3px);
  background-size: 28px 28px;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px);
}

button, input, textarea { font: inherit; color: inherit; }

.vh {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; opacity: 0;
}

:focus-visible { outline: 3px solid var(--pink); outline-offset: 3px; }

/* ---------- header ---------- */
.top {
  display: flex;
  justify-content: center;
  padding: 18px 16px 6px;
}

.logo {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px 8px 12px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--ink);
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  transform: rotate(-1.5deg);
}
.logo i { font-style: normal; }
.logo i:nth-child(1) { color: var(--pink); }
.logo i:nth-child(2) { color: var(--blue); }
.logo i:nth-child(3) { color: var(--leaf); }
.logo i:nth-child(4) { color: #F29B00; }

.logo-dot {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background:
    radial-gradient(circle at 30% 32%, var(--pink) 0 3px, transparent 3.5px),
    radial-gradient(circle at 68% 30%, var(--blue) 0 3px, transparent 3.5px),
    radial-gradient(circle at 50% 68%, var(--leaf) 0 3px, transparent 3.5px),
    var(--sun);
}

/* ---------- layout ---------- */
.layout {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 14px 16px calc(110px + env(safe-area-inset-bottom, 0px));
  display: grid;
  gap: 22px;
}

@media (min-width: 880px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
    gap: 36px;
    padding-top: 22px;
  }
  .stage { position: sticky; top: 20px; }
}

/* ---------- preview sheet ---------- */
.stage { display: flex; justify-content: center; }

.sheet {
  position: relative;
  width: 100%;
  max-width: 460px;
  padding: 10px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 20px;
  box-shadow: 0 7px 0 var(--ink);
}

.tape {
  position: absolute;
  top: -14px;
  width: 86px; height: 28px;
  border-radius: 4px;
  opacity: 0.85;
  z-index: 2;
  pointer-events: none;
}
.tape-l { left: 18px; background: var(--sun); transform: rotate(-8deg); }
.tape-r { right: 18px; background: var(--pink); transform: rotate(7deg); }

.canvas-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  line-height: 0;
}

#preview {
  width: 100%;
  height: auto;
  display: block;
}

.photo-hit {
  position: absolute;
  inset: 0 0 50% 0;
  width: 100%;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.photo-hit.can-pan { cursor: grab; touch-action: none; }
.photo-hit.can-pan:active { cursor: grabbing; }

/* ---------- panel ---------- */
.panel {
  display: grid;
  gap: 16px;
  align-content: start;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 20px;
  font-weight: 700;
  font-size: 1rem;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

.btn-photo { background: var(--leaf); color: #fff; flex: 1 1 auto; }
.btn-photo:focus-within { outline: 3px solid var(--pink); outline-offset: 3px; }

.seg {
  display: inline-flex;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
  overflow: hidden;
}
.seg button {
  min-height: 44px;
  min-width: 56px;
  padding: 0 14px;
  border: 0;
  background: transparent;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.seg button + button { border-left: 3px solid var(--ink); }
.seg button[aria-pressed="true"] { background: var(--blue); color: #fff; }

.seg-size button { min-width: 58px; line-height: 1; }
.seg-size .sz-l { font-size: 1.45rem; }
.seg-size .sz-m { font-size: 1.1rem; }
.seg-size .sz-s { font-size: 0.85rem; }

.field {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: var(--radius);
}
.field:focus-within { border-color: var(--blue); }

.field-date {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  min-height: 52px;
  font-size: 1.2rem;
}
.field-date input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 10px 0;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  text-align: left;
}

.field-text { position: relative; }
.field-text textarea {
  display: block;
  width: 100%;
  min-height: 190px;
  resize: vertical;
  border: 0;
  border-radius: var(--radius);
  background:
    repeating-linear-gradient(transparent 0 33px, #DCE8F5 33px 35px);
  background-position: 0 14px;
  padding: 14px 16px 40px;
  font-size: 1.1rem;
  line-height: 35px;
  outline: none;
}
.field-text textarea::placeholder { color: #A3B1C6; }

.counter {
  position: absolute;
  right: 10px;
  bottom: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--sky);
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.counter.over { background: var(--pink); color: #fff; }

.clear {
  position: absolute;
  left: 10px;
  bottom: 6px;
  min-height: 32px;
  padding: 2px 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.clear:disabled { opacity: 0.35; cursor: default; }

/* 天気 */
.weather {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.weather button {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 8px 4px 7px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.weather button span { font-size: 1.6rem; line-height: 1.15; }
.weather button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.weather button[aria-pressed="true"] { background: var(--sun); }

/* 確認ダイアログ */
.confirm-card { padding-top: 24px; }
.confirm-title { margin: 0; font-size: 1.15rem; font-weight: 900; text-align: center; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; }
.btn-danger { background: var(--pink); color: #fff; }

.group { display: grid; gap: 8px; }
.group-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  padding-left: 4px;
}
.group-split {
  grid-template-columns: auto auto;
  justify-content: start;
  gap: 28px;
}
.group-split > div { display: grid; gap: 8px; align-content: start; }

.chips {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 2px 2px 8px;
  margin: 0 -2px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.chip {
  flex: 0 0 auto;
  display: grid;
  justify-items: center;
  gap: 2px;
  min-width: 88px;
  padding: 8px 12px 7px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  scroll-snap-align: start;
  -webkit-tap-highlight-color: transparent;
}
.chip:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.chip-sample { font-size: 1.5rem; line-height: 1.2; }
.chip-name { font-size: 0.72rem; font-weight: 700; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--sun); }
.chip[aria-pressed="true"] .chip-name { color: var(--ink); }

.switch {
  position: relative;
  width: 70px; height: 44px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #E4EAF2;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background 150ms ease;
}
.switch span {
  position: absolute;
  top: 4px; left: 4px;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--ink);
  transition: transform 150ms ease;
}
.switch[aria-checked="true"] { background: var(--leaf); }
.switch[aria-checked="true"] span { transform: translateX(26px); }

/* ---------- save bar ---------- */
.savebar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(transparent, rgba(205, 235, 255, 0.95) 35%);
  z-index: 10;
  pointer-events: none;
}
.savebar .btn { pointer-events: auto; }

.btn-save {
  width: min(440px, 100%);
  min-height: 58px;
  font-size: 1.15rem;
  font-weight: 900;
  background: var(--sun);
}
.btn-save[disabled] { opacity: 0.6; cursor: progress; }

/* ---------- dialog ---------- */
dialog {
  padding: 0;
  border: 0;
  background: transparent;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  overflow: visible;
}
dialog::backdrop { background: rgba(35, 48, 74, 0.55); }

.done-card {
  position: relative;
  display: grid;
  gap: 14px;
  justify-items: center;
  width: min(420px, calc(100vw - 24px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 18px 18px 20px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 7px 0 var(--ink);
}
.done-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--pink);
}
#doneImg {
  display: block;
  width: 100%;
  max-height: 58vh;
  object-fit: contain;
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  -webkit-touch-callout: default;
}
.done-actions { display: grid; gap: 12px; width: 100%; }
.done-actions .btn { width: 100%; }
.close {
  position: absolute;
  top: 10px; right: 10px;
  width: 40px; height: 40px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: #fff;
  font-size: 1.3rem;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.95rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  z-index: 20;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
