:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #16201f;
  --muted: #687675;
  --line: #dce4e2;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --danger: #b42318;
  --shadow: 0 8px 24px rgba(15, 29, 27, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea {
  font: inherit;
}

button,
.file-button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100svh;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(245, 247, 248, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.2;
}

.topbar p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.memo-area {
  overflow-y: auto;
  padding: 14px 12px 360px;
}

.empty-state {
  display: none;
  padding: 22px 16px;
  color: var(--muted);
}

.empty-state.is-visible {
  display: block;
}

.empty-state h2 {
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 19px;
}

.empty-state p {
  font-size: 14px;
  line-height: 1.6;
}

.memo-list {
  display: grid;
  gap: 10px;
}

.memo-card {
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.memo-card.is-done {
  opacity: 0.64;
}

.memo-card-head,
.memo-card-actions,
.composer-actions,
.category-row,
.photo-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.memo-card-head {
  justify-content: space-between;
  margin-bottom: 8px;
}

.done-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.done-input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.category-row {
  flex-wrap: wrap;
}

.memo-category-row {
  margin: 0 0 8px;
}

.category-toggle {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  gap: 7px;
  padding: 0 12px;
  color: var(--ink);
  background: #f7fbfa;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 14px;
}

.category-toggle input {
  width: 19px;
  height: 19px;
  accent-color: var(--accent);
}

time {
  color: var(--muted);
  font-size: 12px;
}

.memo-text,
#noteText {
  width: 100%;
  resize: vertical;
  color: var(--ink);
  background: #fbfcfc;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

.memo-text {
  min-height: 96px;
  padding: 9px 10px;
  line-height: 1.5;
}

.memo-text:focus,
#noteText:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.memo-photos,
.photo-preview {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin-top: 9px;
}

.photo-tile {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1;
  width: 100%;
  padding: 0;
  background: #edf2f1;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.photo-tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-tile.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.22);
}

.photo-tile.is-selected::after {
  position: absolute;
  right: 5px;
  bottom: 5px;
  padding: 3px 6px;
  color: #fff;
  background: var(--accent);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  content: "選択";
}

.photo-count {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.remove-photo {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 28px;
  height: 28px;
  padding: 0;
  color: #fff;
  background: rgba(22, 32, 31, 0.74);
  border: 0;
  border-radius: 999px;
}

.memo-card-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-top: 9px;
}

.composer {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 4;
  display: grid;
  gap: 8px;
  max-height: 76svh;
  max-width: 520px;
  margin: 0 auto;
  overflow-y: auto;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 28px rgba(15, 29, 27, 0.08);
  backdrop-filter: blur(12px);
}

.text-label {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  clip: rect(0, 0, 0, 0);
}

#noteText {
  min-height: 132px;
  max-height: min(42svh, 360px);
  padding: 11px 12px;
  line-height: 1.45;
}

#photoInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.photo-preview:empty {
  display: none;
}

.photo-preview {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.photo-status {
  min-height: 17px;
  color: var(--muted);
  font-size: 12px;
}

.photo-actions {
  justify-content: flex-end;
}

.voice-line {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
}

.composer-actions {
  justify-content: space-between;
}

.round-button,
.primary-button,
.ghost-button,
.delete-button {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  cursor: pointer;
}

.round-button,
.ghost-button {
  color: var(--ink);
  background: #fff;
}

.round-button.is-recording {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.primary-button {
  flex: 1;
  min-width: 96px;
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

.primary-button:active {
  background: var(--accent-dark);
}

.ghost-button {
  color: var(--muted);
}

.small-action {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.danger-action {
  color: var(--danger);
  border-color: #f0cbc7;
}

.ghost-button:disabled,
.delete-selected-note-photos-button:disabled {
  opacity: 0.44;
}

.delete-button {
  min-height: 36px;
  color: var(--danger);
  background: #fff;
  border-color: #f0cbc7;
}

.camera-panel {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  grid-template-rows: 1fr auto;
  background: #061512;
}

.camera-panel[hidden] {
  display: none;
}

.camera-stage {
  display: grid;
  min-height: 0;
  padding: calc(14px + env(safe-area-inset-top)) 12px 10px;
  place-items: center;
}

.camera-video {
  width: 100%;
  max-width: 520px;
  height: 100%;
  max-height: 72svh;
  background: #000;
  border-radius: 8px;
  object-fit: contain;
}

.camera-controls {
  display: grid;
  gap: 12px;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid rgba(255, 255, 255, 0.22);
}

.camera-controls p {
  color: var(--muted);
  font-size: 13px;
}

.camera-control-row {
  display: flex;
  gap: 10px;
}

@media (min-width: 700px) {
  body::before {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 32px;
    color: var(--muted);
    text-align: center;
    content: "このアプリはスマホ用です。スマホ幅で開いてください。";
  }

  .app-shell {
    min-height: 100svh;
    opacity: 0.18;
    pointer-events: none;
  }
}
