/* The shared list follows the same tokens as the phone app and Desktop:
   white (or dark) surface, gray lines and the #10a37f accent, following the system theme. */
:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --text: #111111;
  --muted: #6b7280;
  --panel: #f6f7f8;
  --card: #ffffff;
  --line: #e5e7eb;
  --line-strong: #cfd4dc;
  --hover: #f3f4f6;
  --pressed: #eceef1;
  --accent: #10a37f;
  --accent-hover: #0d8c6d;
  --accent-text: #047857;
  --accent-soft: #ecfdf5;
  --path: #0369a1;
  --badge-bg: #eef2f6;
  --badge-text: #4b5563;
  --warn-bg: #fef3c7;
  --warn-text: #b45309;
  --warn-line: #fcd34d;
  --danger: #dc2626;
  --input-bg: #ffffff;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.2);
  --gutter: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1117;
    --text: #f8fafc;
    --muted: #b5c0cc;
    --panel: #151c25;
    --card: #0f141a;
    --line: #344150;
    --line-strong: #4a5a6d;
    --hover: #1a2330;
    --pressed: #202b3a;
    --accent: #10a37f;
    --accent-hover: #12b48c;
    --accent-text: #8ee8cf;
    --accent-soft: #10231f;
    --path: #7dd3fc;
    --badge-bg: #18212b;
    --badge-text: #b5c0cc;
    --warn-bg: #451a03;
    --warn-text: #fde68a;
    --warn-line: #b45309;
    --danger: #fda4af;
    --input-bg: #0f141a;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

html { min-height: 100%; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
}
button, textarea, select { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 6px max(var(--gutter), env(safe-area-inset-right)) 6px max(var(--gutter), env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.app-brand { display: inline-flex; align-items: center; gap: 8px; min-width: 0; font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.app-brand img { width: 28px; height: 28px; border-radius: 7px; }
.app-header__note { color: var(--muted); font-size: 12px; }
.app-header__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.header-icon { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); }
.header-icon:hover { background: var(--hover); color: var(--text); }
.is-ios-app .app-header { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.chip:hover { background: var(--hover); }
.chip.primary { border-color: var(--accent); background: var(--accent); color: #ffffff; font-weight: 700; }
.chip.primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
.chip:disabled { cursor: not-allowed; opacity: 0.45; }

/* ===== Share heading ===== */
.viewer-shell {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px max(var(--gutter), env(safe-area-inset-right)) calc(48px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
}
.share-head h1 { margin: 0; font-size: 20px; line-height: 1.35; font-weight: 800; overflow-wrap: anywhere; }
.share-description { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.share-description.is-clamped { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; }
.text-button { padding: 2px 0; border: 0; background: none; color: var(--accent-text); font-size: 12px; font-weight: 700; cursor: pointer; }
.text-button:disabled { cursor: not-allowed; opacity: 0.45; }
.share-meta-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
.meta-line { min-width: 0; color: var(--muted); font-size: 12px; }
.report-button { flex: 0 0 auto; color: var(--muted); font-weight: 600; }
.report-button:hover { color: var(--danger); }
.warning-banner { margin-top: 10px; padding: 9px 11px; border: 1px solid var(--warn-line); border-radius: 10px; background: var(--warn-bg); color: var(--warn-text); font-size: 12px; line-height: 1.55; }

/* ===== Input, search and folder location (sticky like the app's top bar) ===== */
.list-anchor { height: 0; }
.io-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 12px calc(-1 * var(--gutter)) 0;
  padding: 8px var(--gutter);
  background: var(--bg);
}
.io-row { display: flex; align-items: flex-start; gap: 4px; padding: 5px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.common-input { flex: 1; min-width: 0; display: flex; }
.common-input textarea {
  width: 100%;
  min-height: 36px;
  max-height: 110px;
  resize: none;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: var(--input-bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.common-input textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.2); }
.common-input textarea::placeholder { color: var(--muted); opacity: 0.85; }
.icon-btn { width: 36px; height: 36px; flex: 0 0 36px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.is-active { background: var(--accent-soft); color: var(--accent-text); }
.toolbar-hint { margin: 6px 4px 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.toolbar-hint:empty { display: none; }
.toolbar-hint.is-error { color: var(--danger); font-weight: 600; }

.folder-bar { display: flex; align-items: center; gap: 8px; min-width: 0; margin-top: 8px; }
.up-button { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 2px; height: 32px; padding: 0 10px 0 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-size: 13px; font-weight: 700; cursor: pointer; }
.up-button:hover { background: var(--hover); }
.crumbs { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; margin: 0; padding: 0; overflow-x: auto; list-style: none; white-space: nowrap; scrollbar-width: none; color: var(--muted); font-size: 12px; }
.crumbs::-webkit-scrollbar { display: none; }
.crumbs li { display: inline-flex; align-items: center; gap: 4px; }
.crumbs li + li::before { content: "›"; color: var(--muted); }
.crumbs button { padding: 4px 2px; border: 0; background: none; color: var(--accent-text); font-size: 12px; cursor: pointer; }
.crumbs [aria-current="page"] { color: var(--text); font-weight: 700; }
.folder-count { flex: 0 0 auto; color: var(--muted); font-size: 12px; }

.folder-note { margin: 6px 2px 0; color: var(--muted); font-size: 13px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.list-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 6px 2px 0; }
.list-title { min-width: 0; font-size: 13px; font-weight: 700; overflow-wrap: anywhere; }
.section-count { flex: 0 0 auto; color: var(--muted); font-size: 12px; }

/* ===== Folder and button tiles (same density as the app and Desktop) ===== */
.entry-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; margin-top: 10px; }
.tile {
  position: relative;
  min-width: 0;
  display: flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  transition: border-color 0.15s ease, background-color 0.15s ease;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.tile:hover { border-color: var(--line-strong); }
.tile:has(:focus-visible) { border-color: var(--accent); }
.tile.is-pressing { background: var(--pressed); }
.folder-card { background: var(--panel); }
.share-card.is-template { border-color: var(--accent); background: var(--accent-soft); }

.share-card__open, .folder-card__open {
  flex: 1;
  min-width: 0;
  min-height: 78px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  padding: 10px 34px 10px 11px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}
.share-card__open:focus-visible, .folder-card__open:focus-visible { outline-offset: -2px; }
.share-card__caption { color: var(--muted); font-size: 11px; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-card__title, .folder-card__name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.38;
  overflow-wrap: anywhere;
}
.share-card__path { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; color: var(--path); font-size: 11px; line-height: 1.4; overflow-wrap: anywhere; }
.share-card__memo, .folder-card__memo {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.share-card__caption:empty, .share-card__path:empty, .share-card__memo:empty, .share-card__meta:empty, .folder-card__memo:empty { display: none; }
.share-card__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: auto; padding-top: 4px; color: var(--muted); }
.share-card__meta svg { width: 15px; height: 15px; }
.memo-mark { display: none; }
.folder-card__icon { display: inline-flex; color: var(--muted); }
.folder-card__icon svg { width: 20px; height: 20px; }
.folder-card__count { margin-top: auto; padding-top: 2px; color: var(--muted); font-size: 11px; }

.badge { display: inline-flex; align-items: center; padding: 1px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--badge-bg); color: var(--badge-text); font-size: 11px; font-weight: 600; line-height: 1.6; white-space: nowrap; }
.badge--accent { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.badge--warning { border-color: var(--warn-line); background: var(--warn-bg); color: var(--warn-text); }

.entry-menu-button { position: absolute; top: 5px; right: 3px; width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.entry-menu-button:hover { background: var(--hover); color: var(--text); }

.empty-state { grid-column: 1 / -1; margin-top: 8px; padding: 28px 16px; border: 1px dashed var(--line-strong); border-radius: 12px; color: var(--muted); text-align: center; line-height: 1.7; }

/* ===== Footer ===== */
.viewer-footer { display: grid; gap: 10px; margin-top: 28px; }
.howto-panel { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--muted); font-size: 13px; line-height: 1.7; }
.howto-panel summary { color: var(--text); font-weight: 700; cursor: pointer; }
.howto-panel ol { margin: 8px 0 2px; padding-left: 20px; }
.howto-panel p { margin: 8px 0; }
.share-other-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.viewer-footnote { margin: 0 2px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.viewer-footnote a { color: var(--accent-text); font-weight: 700; }

/* ===== Dialogs and the URL / memo sheet ===== */
.app-dialog {
  width: min(560px, calc(100% - 32px));
  max-height: min(760px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow);
  overscroll-behavior: contain;
}
/* ::backdrop does not inherit custom properties in older Safari, so the colors are literal. */
.app-dialog::backdrop { background: rgba(15, 23, 42, 0.45); }
@media (prefers-color-scheme: dark) {
  .app-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
}
.dialog-form, .sheet-body { display: grid; gap: 14px; padding: 18px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.dialog-head h2 { margin: 4px 0 0; font-size: 18px; line-height: 1.4; overflow-wrap: anywhere; }
.section-kicker { color: var(--accent-text); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; }
.dialog-close { flex: 0 0 auto; width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: var(--card); font-size: 18px; line-height: 1; cursor: pointer; }
.dialog-close:hover { background: var(--hover); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.primary-button, .secondary-button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-weight: 700; cursor: pointer; }
.primary-button { border-color: var(--accent); background: var(--accent); color: #ffffff; }
.primary-button:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
.secondary-button:hover { background: var(--hover); }
.primary-button:disabled, .secondary-button:disabled { cursor: not-allowed; opacity: 0.45; }
.memo-view { min-height: 80px; max-height: 56vh; overflow: auto; line-height: 1.8; overflow-wrap: anywhere; white-space: pre-wrap; -webkit-user-select: text; user-select: text; }
#pcActionSteps { margin: 0; padding-left: 20px; line-height: 1.7; overflow-wrap: anywhere; }
.report-note { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.report-field { display: grid; gap: 6px; font-size: 13px; font-weight: 700; }
.report-field select { width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--input-bg); color: var(--text); }

.sheet-grabber { display: none; justify-self: center; width: 36px; height: 4px; margin: -6px 0 -4px; border-radius: 999px; background: var(--line-strong); }
.sheet-heading { min-width: 0; }
.sheet-heading .badge { margin-bottom: 2px; }
.sheet-caption { margin: 2px 0 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.sheet-block { display: grid; gap: 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.sheet-label { color: var(--muted); font-size: 11px; font-weight: 700; }
.sheet-url { max-height: 7.5em; margin: 0; overflow: auto; color: var(--path); font-size: 13px; line-height: 1.5; word-break: break-all; -webkit-user-select: text; user-select: text; }
.sheet-note { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.sheet-memo { max-height: 32vh; overflow: auto; font-size: 14px; line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.sheet-path { margin: 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.sheet-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.sheet-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.sheet-actions .primary-button { grid-column: 1 / -1; }
.sheet-actions .secondary-button { min-height: 40px; padding: 0 10px; font-size: 13px; font-weight: 600; }
.sheet-actions svg { width: 16px; height: 16px; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: min(520px, calc(100% - 32px)); padding: 10px 16px; border-radius: 10px; background: #111827; color: #ffffff; box-shadow: var(--shadow); font-size: 13px; text-align: center; }
.toast.is-error { background: #991b1b; }

/* ===== Phones: the same 2-column tiles as the app; memo text moves to long-press ===== */
@media (max-width: 639px) {
  :root { --gutter: 12px; }
  .app-header__note { display: none; }
  .share-head h1 { font-size: 19px; }
  .common-input textarea { font-size: 16px; }
  .entry-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* Like the app: no memo text on the tile, a memo mark instead; long-press shows it. */
  .share-card__memo, .folder-card__memo { display: none; }
  .memo-mark { display: inline-flex; }
  .share-card__open, .folder-card__open { min-height: 74px; }
  .app-dialog {
    width: 100%;
    max-width: 100%;
    max-height: 88vh;
    max-height: 88dvh;
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: 18px 18px 0 0;
  }
  .dialog-form, .sheet-body { padding: 16px 16px calc(18px + env(safe-area-inset-bottom)); }
  .sheet-grabber { display: block; }
  .dialog-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .dialog-actions > * { width: 100%; }
  .dialog-actions > :only-child { grid-column: 1 / -1; }
}

@media (max-width: 349px) {
  .entry-grid { grid-template-columns: 1fr; }
}
