:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --ink: #1b2333;
  --ink-soft: #55607a;
  --line: #d8dfec;
  --accent: #2f6bd8;
  --accent-ink: #ffffff;
  --danger: #b4283c;
  --ok-bg: #e6f4ec;
  --ok-ink: #1c6b41;
  --off-bg: #eef0f5;
  --off-ink: #5b6479;
  --focus: #ffab2e;
  --radius: 12px;
}

* { box-sizing: border-box; }

/* Author `display:` rules below beat the UA stylesheet's [hidden] rule, which
   would otherwise leave hidden controls (logout, the add button a viewer may
   not use, the delete dialog) visible. Visibility is a permission signal here,
   so make the attribute authoritative. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.7;
}

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

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--surface);
  padding: 10px 16px;
  z-index: 20;
}

.skip-link:focus {
  left: 8px;
  top: 8px;
}

/* --- header --- */

.site-header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

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

.brand-pet {
  position: relative;
  display: block;
  width: 40px;
  height: 38px;
  flex: none;
}

.pet-ear {
  position: absolute;
  top: 0;
  width: 12px;
  height: 16px;
  background: #6e9bec;
  border-radius: 60% 60% 20% 20%;
}

.pet-ear-left { left: 3px; transform: rotate(-14deg); }
.pet-ear-right { right: 3px; transform: rotate(14deg); }

.pet-face {
  position: absolute;
  inset: 8px 0 0 0;
  background: linear-gradient(#8fb4f4, #5f8de4);
  border-radius: 45%;
}

.pet-eye {
  position: absolute;
  top: 10px;
  width: 5px;
  height: 6px;
  background: #17233b;
  border-radius: 50%;
}

.pet-eye-left { left: 11px; }
.pet-eye-right { right: 11px; }

.pet-mouth {
  position: absolute;
  left: 50%;
  top: 18px;
  width: 10px;
  height: 5px;
  margin-left: -5px;
  border-bottom: 2px solid #17233b;
  border-radius: 0 0 10px 10px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-org { font-size: 12px; color: var(--ink-soft); }
.brand-name { font-size: 17px; }

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

.who { font-size: 13px; color: var(--ink-soft); }

/* --- layout --- */

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

h1 { font-size: 20px; margin: 0 0 12px; }
h2 { font-size: 17px; margin: 0 0 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.hint { font-size: 13px; color: var(--ink-soft); margin: 8px 0 0; }
.empty { color: var(--ink-soft); background: var(--surface);
  border: 1px dashed var(--line); border-radius: var(--radius); padding: 20px; }

.global-message {
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 0 0 16px;
  font-size: 14px;
}

.global-message[data-tone="info"] { background: var(--ok-bg); color: var(--ok-ink); }
.global-message[data-tone="error"] { background: #fdecef; color: var(--danger); }

/* --- signin --- */

.signin { text-align: center; margin-top: 32px; }
.signin h1 { font-size: 22px; }

/* --- tabs --- */

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  overflow-x: auto;
}

.tab {
  flex: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 8px 16px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  min-height: 40px;
}

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

.panel-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-head h1 { margin: 0; }

/* --- stats --- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-label { display: block; font-size: 13px; color: var(--ink-soft); }

.stat-value {
  display: block;
  font-size: 22px;
  margin-top: 4px;
  /* Role labels are phrases, not numbers: never split them mid-word. */
  overflow-wrap: break-word;
  word-break: normal;
  line-break: strict;
}

/* The role label is text where the others are counts; size it as text so it
   does not wrap into three ragged lines on a narrow screen. */
.stat-value.is-text { font-size: 16px; line-height: 1.6; font-weight: 700; }

/* --- buttons --- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.button:hover { border-color: var(--accent); }
.button:disabled { opacity: 0.55; cursor: not-allowed; }

.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button.ghost { background: var(--surface); }
.button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.button.danger-ghost { color: var(--danger); border-color: #edc4cc; }

/* --- editor form --- */

.editor { margin-bottom: 20px; }

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}

.required { font-weight: 400; color: var(--danger); font-size: 12px; }

.field input[type="text"],
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 16px; /* keeps iOS from zooming on focus */
  background: #fff;
  color: var(--ink);
}

.field textarea { resize: vertical; min-height: 120px; }

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-field input { width: 20px; height: 20px; flex: none; }
.checkbox-field label { margin: 0; font-weight: 400; }

.form-error {
  background: #fdecef;
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  margin: 0 0 14px;
}

.form-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* --- entries --- */

.entry-list, .audit-list { list-style: none; margin: 0; padding: 0; }

.entry {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--ok-ink);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.entry[data-enabled="false"] { border-left-color: var(--off-ink); opacity: 0.9; }

.entry-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: baseline;
  justify-content: space-between;
}

.entry-title { font-size: 16px; margin: 0; }
.entry-badges { display: flex; gap: 6px; margin: 0; }

.badge {
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 10px;
}

.badge-on { background: var(--ok-bg); color: var(--ok-ink); }
.badge-off { background: var(--off-bg); color: var(--off-ink); }
.badge-neutral { background: #eef2fb; color: #3c5a99; }

.entry-body {
  margin: 10px 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 15px;
}

.entry-meta { font-size: 12px; color: var(--ink-soft); margin: 0 0 12px; }

.entry-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.entry-actions .button { min-height: 40px; padding: 8px 14px; font-size: 14px; }

/* --- audit --- */

.audit-item {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  gap: 8px 14px;
  align-items: baseline;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  font-size: 14px;
}

.audit-time { color: var(--ink-soft); font-variant-numeric: tabular-nums; font-size: 13px; }
.audit-what { overflow-wrap: anywhere; }
.audit-who { color: var(--ink-soft); font-size: 13px; overflow-wrap: anywhere; }

/* --- modal --- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 26, 40, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 30;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 420px;
  width: 100%;
}

.modal h2 { margin-top: 0; }

/* --- narrow screens (390px reference) --- */

@media (max-width: 480px) {
  main { padding: 16px 12px 56px; }
  .site-header { padding: 10px 12px; }
  /* One card per row: the auto-fit grid otherwise pairs two counts and drops
     the role card alone, which reads as a layout fault. */
  .stat-row { grid-template-columns: 1fr; }
  .stat { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
  .stat-label { flex: 0 1 auto; }
  .stat-value { margin-top: 0; text-align: right; }
  .panel-head { align-items: stretch; }
  .panel-head .button { width: 100%; }
  .entry-actions .button { flex: 1 1 auto; }
  .audit-item { grid-template-columns: 1fr; gap: 2px; }
  .form-actions .button { flex: 1 1 auto; }
}

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