:root {
  color-scheme: light;
  --ink: #1f2328;
  --ink-soft: #5b6470;
  --paper: #fdfbf7;
  --paper-2: #f4efe6;
  --line: #e3dbcd;
  --accent: #f2a93b;
  --accent-dark: #c97f14;
  --danger: #c0392b;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(31, 35, 40, 0.12);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

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

.panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  min-height: 100vh;
}

.panel__head {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search {
  display: flex;
  gap: 6px;
  align-items: center;
}

.search input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 9px 12px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 14px;
  color: var(--ink);
}

.search input:focus-visible,
.note-form__input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.tabs {
  display: flex;
  gap: 6px;
}

.tab {
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 13px;
  cursor: pointer;
}

.tab.is-active {
  border-color: var(--accent);
  background: #fff5e3;
  color: var(--accent-dark);
  font-weight: 600;
}

.btn {
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  min-height: 36px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #3b2606;
  font-weight: 600;
}

.btn--quiet {
  background: var(--paper-2);
}

.btn:focus-visible {
  outline: 2px solid var(--accent-dark);
  outline-offset: 2px;
}

.status {
  margin: 0;
  min-height: 18px;
  font-size: 12px;
  color: var(--ink-soft);
}

.status[data-kind="error"] { color: var(--danger); }
.status[data-kind="ok"] { color: #1e7d46; }

.grid {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
  align-content: start;
}

.sticker {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px 4px;
  border: 1.5px solid transparent;
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
}

.sticker:hover { border-color: var(--line); background: #fffdf8; }
.sticker:focus-visible { outline: 2px solid var(--accent-dark); outline-offset: 1px; }
.sticker img { width: 100%; height: auto; max-width: 64px; display: block; }
.sticker__name { font-size: 11px; color: var(--ink-soft); text-align: center; }
.sticker__fav {
  position: absolute;
  top: 2px; right: 4px;
  font-size: 11px;
  color: var(--accent-dark);
}

.empty, .hint {
  margin: 0;
  font-size: 12px;
  color: var(--ink-soft);
}

.hint {
  padding: 6px 10px;
  border-radius: 8px;
  background: #fff5e3;
  color: var(--accent-dark);
}

.panel__foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--ink-soft);
  border-top: 1px dashed var(--line);
  padding-top: 6px;
}

.foot-user { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%; }

.dialog {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(31, 35, 40, 0.45);
  z-index: 20;
}

.dialog[hidden] { display: none; }

.dialog__card {
  position: relative;
  width: min(340px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--paper);
  border-radius: var(--radius);
  border: 1.5px solid var(--line);
  box-shadow: var(--shadow);
  padding: 18px 16px 14px;
  text-align: center;
}

.dialog__close {
  position: absolute;
  top: 6px; right: 8px;
  width: 32px; height: 32px;
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
}

.dialog__image {
  width: 168px;
  height: 168px;
  object-fit: contain;
}

.dialog__title { margin: 4px 0 0; font-size: 16px; }
.dialog__phrase { margin: 2px 0 8px; color: var(--ink-soft); font-size: 13px; }
.dialog__note {
  margin: 0 0 10px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--paper-2);
  font-size: 12px;
  color: var(--ink-soft);
  text-align: left;
}

.dialog__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.dialog__feedback { min-height: 16px; margin: 8px 0 0; font-size: 12px; color: var(--ink-soft); }
.dialog__feedback[data-kind="error"] { color: var(--danger); }
.dialog__feedback[data-kind="ok"] { color: #1e7d46; }

.error {
  max-width: 420px;
  margin: 12vh auto;
  padding: 20px;
  text-align: center;
}

.error__title { font-size: 18px; margin: 0 0 8px; }
.error__message { color: var(--ink-soft); margin: 0 0 16px; }

/* Detail (modal_dialog) view */
.detail-page { background: var(--paper); }

.detail {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 520px;
  margin: 0 auto;
}

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

.detail__image { width: 96px; height: 96px; object-fit: contain; }

.detail__title { margin: 0; font-size: 17px; }
.detail__phrase { margin: 2px 0; color: var(--ink-soft); font-size: 13px; }
.detail__tags { margin: 2px 0 0; font-size: 12px; color: var(--accent-dark); }

.note-form { display: flex; flex-direction: column; gap: 6px; }
.note-form__label { font-size: 13px; font-weight: 600; }
.note-form__input {
  width: 100%;
  resize: vertical;
  min-height: 72px;
  padding: 10px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
}
.note-form__count { margin: 0; text-align: right; font-size: 11px; color: var(--ink-soft); }
.detail__feedback { margin: 0; min-height: 16px; font-size: 12px; color: var(--ink-soft); }
.detail__feedback[data-kind="error"] { color: var(--danger); }
.detail__actions { display: flex; gap: 8px; }

@media (max-width: 360px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
  .dialog__image { width: 132px; height: 132px; }
}

@media (min-width: 720px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
  .dialog__image { width: 196px; height: 196px; }
}

@media (prefers-reduced-motion: no-preference) {
  .dialog__card { animation: pop 140ms ease-out; }
  @keyframes pop { from { transform: scale(0.97); opacity: 0.6; } to { transform: none; opacity: 1; } }
}
