:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #ebe8e2;
  --text: #22201c;
  --muted: #6f6a62;
  --line: #d9d4cb;
  --accent: #1d6f6a;
  --accent-ink: #ffffff;
  --accent-soft: #dcefec;
  --danger: #b23a30;
  --rec: #c8372d;
  --radius: 2px;
  --btn-w: 220px;
  --btn-w-sm: 116px;
  --font: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161716;
    --surface: #1f2120;
    --surface-2: #2a2d2b;
    --text: #ecebe7;
    --muted: #a19d95;
    --line: #3a3d3b;
    --accent: #4fb3aa;
    --accent-ink: #0d1716;
    --accent-soft: #1f3634;
    --danger: #e0766c;
    --rec: #e5574c;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #161716;
  --surface: #1f2120;
  --surface-2: #2a2d2b;
  --text: #ecebe7;
  --muted: #a19d95;
  --line: #3a3d3b;
  --accent: #4fb3aa;
  --accent-ink: #0d1716;
  --accent-soft: #1f3634;
  --danger: #e0766c;
  --rec: #e5574c;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  padding-bottom: env(safe-area-inset-bottom);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.app-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 16px 8px;
}

.app-title {
  margin: 0;
  font-size: 22px;
  letter-spacing: .08em;
}

.app-today {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.layout {
  display: grid;
  gap: 16px;
  max-width: 1080px;
  margin: 0 auto;
  padding: 8px 16px 32px;
}

@media (min-width: 960px) {
  .layout {
    grid-template-columns: 500px minmax(0, 1fr);
    grid-template-areas: "voice list" "editor list";
    align-items: start;
  }
  .voice { grid-area: voice; }
  .editor { grid-area: editor; }
  .list { grid-area: list; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  min-width: 0;
}

.panel-title {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--muted);
}

/* Voice */
.voice { text-align: center; }

.mic {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 148px;
  height: 148px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  cursor: pointer;
  transition: background .2s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}

.mic svg { width: 48px; height: 48px; fill: currentColor; }
.mic-label { font-size: 13px; font-weight: 700; }
.mic:active { transform: scale(.97); }
.mic:focus-visible { outline: 3px solid var(--text); outline-offset: 4px; }

.mic[aria-pressed="true"] {
  background: var(--rec);
  animation: pulse 1.4s ease-out infinite;
}

.mic:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; animation: none; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--rec) 45%, transparent); }
  100% { box-shadow: 0 0 0 22px transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .mic[aria-pressed="true"] { animation: none; }
}

.hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.transcript {
  min-height: 1.6em;
  margin: 12px 0 0;
  font-size: 17px;
  font-weight: 700;
  word-break: break-all;
}

.transcript.interim { color: var(--muted); font-weight: 400; }

.text-input {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.text-input input { flex: 1; min-width: 0; }

/* Form */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field label { font-size: 13px; color: var(--muted); }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 8px;
}

.field-row .field:first-child { grid-column: 1 / -1; }

input, textarea {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; }

.notice {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  font-size: 13px;
}

/* Buttons: same width within each size */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.btn {
  width: var(--btn-w);
  max-width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
}

.btn-main { background: var(--accent); color: var(--accent-ink); }
.btn-sub { background: transparent; color: var(--accent); }
.btn:hover { filter: brightness(1.08); }
.btn:focus-visible, .tab:focus-visible, .mini:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.btn-sm {
  width: var(--btn-w-sm);
  flex: none;
  padding: 8px 10px;
  font-size: 14px;
}

@media (max-width: 520px) {
  .actions .btn { flex: 1 1 0; width: auto; }
}

/* List */
.list-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.list-head .panel-title { margin: 0; }

.tabs { display: flex; gap: 0; }

.tab {
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.tab:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.tab:last-child { border-radius: 0 var(--radius) var(--radius) 0; border-left: 0; }
.tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }

#entries { margin-bottom: 16px; }

.day { margin-bottom: 18px; }

.day-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  font-weight: 700;
}

.day-label small { color: var(--muted); font-weight: 400; }
.day.is-today .day-label { color: var(--accent); }
.day.is-past { opacity: .6; }

.entry {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 4px 12px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}

.entry:last-child { border-bottom: 0; }

.entry-time {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
  font-size: 15px;
}

.entry-time.allday { color: var(--muted); font-weight: 400; font-size: 13px; }

.entry-body { min-width: 0; }
.entry-title { margin: 0; font-weight: 700; word-break: break-word; }
.entry-memo { margin: 2px 0 0; color: var(--muted); font-size: 13px; white-space: pre-wrap; word-break: break-word; }

.entry-tools {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.mini {
  width: 84px;
  padding: 4px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.mini:hover { border-color: var(--accent); color: var(--accent); }
.mini.danger:hover { border-color: var(--danger); color: var(--danger); }

@media (max-width: 420px) {
  .entry { grid-template-columns: 1fr; }
  .entry-tools { grid-column: 1; flex-wrap: nowrap; }
  .entry-tools .mini { flex: 1 1 0; width: auto; }
}

.empty {
  padding: 32px 0;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.sync {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.sync-title {
  margin: 0 0 6px;
  font-size: 14px;
}

.sync-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.sync-status::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line);
}

.sync-status[data-state="ok"]::before { background: var(--accent); }
.sync-status[data-state="busy"]::before { background: var(--muted); }
.sync-status[data-state="error"]::before { background: var(--danger); }

.sync-form {
  display: flex;
  gap: 8px;
}

.sync-form input { flex: 1; min-width: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
