/* ランダムリンク再発見 — 主役は「🎲 ランダムに開く」。装飾は控えめに。 */

:root {
  --bg: #f6f3ec;
  --surface: #fffdf8;
  --surface-2: #efeae0;
  --ink: #1f2029;
  --ink-2: #545562;
  --ink-3: #85868f;
  --line: #e1dbcf;
  --accent: #2f3a8f;
  --accent-2: #4652b8;
  --accent-ink: #ffffff;
  --accent-soft: #e6e8f7;
  --ok: #1f6f43;
  --warn: #8a5a00;
  --no: #a1302a;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --focus: #e8a400;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 32, 41, .06), 0 6px 20px rgba(31, 32, 41, .06);
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171d;
    --surface: #1f2028;
    --surface-2: #272832;
    --ink: #ecebe6;
    --ink-2: #b6b5bd;
    --ink-3: #85858f;
    --line: #34353f;
    --accent: #8f9bff;
    --accent-2: #a9b2ff;
    --accent-ink: #12132a;
    --accent-soft: #2a2d4d;
    --ok: #6fd39b;
    --warn: #f0c060;
    --no: #ff8f86;
    --danger: #ff8f86;
    --danger-soft: #3a2224;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

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

.visually-hidden, .offscreen {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }

/* ---------- 上部 ---------- */
.topbar {
  max-width: 880px; margin: 0 auto; padding: 14px 16px 0;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { font-size: 15px; font-weight: 600; letter-spacing: .08em; margin: 0; color: var(--ink-2); }
.brand-mark { color: var(--accent); margin-right: .35em; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid transparent;
  background: transparent; color: var(--ink-2); display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

main { max-width: 880px; margin: 0 auto; padding: 8px 16px 32px; }

/* ---------- 主役ボタン ---------- */
.hero { text-align: center; padding: 18px 0 8px; }
.dice-btn {
  width: 100%; max-width: 560px; min-height: 120px;
  border: 0; border-radius: 26px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 18px;
  background: linear-gradient(160deg, var(--accent-2), var(--accent));
  color: var(--accent-ink);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .12), 0 14px 34px -10px color-mix(in srgb, var(--accent) 70%, transparent);
  transition: transform .12s ease, box-shadow .12s ease, filter .2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.dice-btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.dice-btn:active { transform: translateY(2px) scale(.99); box-shadow: 0 0 0 rgba(0, 0, 0, .1), 0 6px 16px -8px var(--accent); }
.dice-btn:focus-visible { outline-offset: 4px; border-radius: 26px; }
.dice { font-size: 52px; line-height: 1; display: inline-block; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .25)); }
.dice-label { font-size: clamp(24px, 6vw, 32px); font-weight: 700; letter-spacing: .06em; }
.dice.rolling { animation: roll .55s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes roll {
  0% { transform: rotate(0) scale(1); }
  40% { transform: rotate(250deg) scale(1.18); }
  100% { transform: rotate(360deg) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .dice.rolling { animation: none; }
  .dice-btn { transition: none; }
}
.count-line { margin: 12px 0 0; font-size: 15px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.scope-line { margin: 2px 0 0; font-size: 13px; color: var(--ink-3); min-height: 1.4em; font-variant-numeric: tabular-nums; }

/* ---------- 今回の1件 ---------- */
.result {
  max-width: 560px; margin: 8px auto 4px; padding: 18px 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: rise .35s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .result { animation: none; } }
.result-kicker { margin: 0; font-size: 12px; letter-spacing: .12em; color: var(--ink-3); }
.result-title { margin: 4px 0 2px; font-size: 20px; line-height: 1.45; word-break: break-word; }
.result-link { color: var(--ink); text-decoration: none; }
.result-link:hover { text-decoration: underline; }
.result-url { margin: 0; color: var(--ink-3); font-size: 13px; word-break: break-all; }
.result-memo { margin: 10px 0 0; padding: 8px 12px; border-left: 3px solid var(--line); color: var(--ink-2); font-size: 14px; white-space: pre-wrap; }
.result-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin-top: 10px; font-size: 13px; color: var(--ink-2); }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.result-empty p { margin: 0; text-align: center; }
.result-empty p + p { color: var(--ink-2); font-size: 14px; margin-top: 4px; }

/* ---------- 抽選の設定 ---------- */
.controls {
  max-width: 560px; margin: 14px auto 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px;
}
.control { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.control label { font-size: 12px; color: var(--ink-3); letter-spacing: .04em; }
select, input[type="text"], input[type="search"], textarea {
  width: 100%; min-height: 44px; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
select {
  appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
  text-overflow: ellipsis;
}
textarea { min-height: 0; resize: vertical; line-height: 1.5; }
.cap-note { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 2px; }
.cap { margin: 0; display: flex; gap: 8px; align-items: baseline; font-size: 13px; color: var(--ink-2); }
.cap-mark { font-weight: 700; width: 1.1em; text-align: center; flex: none; }
.cap.ok .cap-mark { color: var(--ok); }
.cap.warn .cap-mark { color: var(--warn); }
.cap.no .cap-mark { color: var(--no); }

/* ---------- 初回 ---------- */
.welcome { text-align: center; margin: 30px 0 4px; }
.welcome-lead { font-size: 19px; font-weight: 600; line-height: 1.7; margin: 0; }
.welcome-sub { margin: 4px 0 0; color: var(--ink-2); font-size: 14px; }

/* ---------- 追加 ---------- */
.add-actions {
  max-width: 560px; margin: 26px auto 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.add-btn {
  display: flex; align-items: center; gap: 10px; text-align: left;
  min-height: 52px; padding: 10px 14px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.add-btn:hover { border-color: var(--accent); }
.add-btn strong { display: block; font-size: 15px; font-weight: 600; }
.add-btn small { display: block; font-size: 12px; color: var(--ink-3); line-height: 1.4; }
.add-btn .add-ico { font-size: 20px; width: 26px; text-align: center; flex: none; }
.add-btn.primary small { display: block; }
.add-btn:not(.primary) small { display: none; }
.is-empty .add-btn.primary { border: 2px solid var(--accent); background: var(--accent-soft); grid-column: 1 / -1; min-height: 64px; }
.drop-hint { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--ink-3); text-align: center; }
@media (hover: none) { .drop-hint { display: none; } }

/* ---------- 履歴 ---------- */
h2 { font-size: 15px; font-weight: 700; letter-spacing: .04em; margin: 0; }
.history { max-width: 560px; margin: 30px auto 0; }
.history-list { list-style: none; margin: 8px 0 0; padding: 0; border-top: 1px solid var(--line); }
.history-item {
  width: 100%; display: flex; gap: 14px; align-items: baseline; text-align: left;
  min-height: 44px; padding: 9px 4px; background: none; border: 0; border-bottom: 1px solid var(--line); cursor: pointer;
}
.history-item:hover:not(:disabled) { background: var(--surface); }
.history-item:disabled { cursor: default; color: var(--ink-3); }
.h-time { flex: none; width: 7.5em; font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.h-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 一覧 ---------- */
.list-sec { margin-top: 38px; }
.list-head { display: flex; align-items: baseline; gap: 10px; }
.list-count { color: var(--ink-3); font-size: 13px; font-variant-numeric: tabular-nums; }
.search-row { position: relative; margin-top: 10px; }
.search-ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 14px; opacity: .7; pointer-events: none; }
.search-row input { padding-left: 36px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; min-height: 40px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
#searchScopeWrap { margin-top: 4px; }

.bulk-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px;
  margin-top: 8px; padding: 4px 0; border-bottom: 1px solid var(--line);
}
.sel-count { font-size: 13px; color: var(--accent); font-weight: 600; }
.bulk-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }

.link-list { display: flex; flex-direction: column; }
.row {
  display: grid; grid-template-columns: 32px minmax(0, 1fr) 150px 120px auto; gap: 4px 12px; align-items: start;
  padding: 12px 4px; border-bottom: 1px solid var(--line);
}
.row.selected { background: var(--accent-soft); }
.row-check { padding-top: 3px; }
.row-check input { width: 18px; height: 18px; accent-color: var(--accent); }
.row-main { min-width: 0; display: flex; flex-direction: column; }
.row-title { color: var(--ink); text-decoration: none; font-weight: 600; word-break: break-word; }
.row-title:hover { text-decoration: underline; color: var(--accent); }
.row-url { color: var(--ink-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-memo { color: var(--ink-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-cat { min-width: 0; padding-top: 2px; }
.row-meta { display: flex; flex-direction: column; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; line-height: 1.5; }
.row-actions { display: flex; gap: 6px; }
.chip {
  display: inline-block; max-width: 100%; padding: 1px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle;
}
.muted { color: var(--ink-3); }
.list-empty { color: var(--ink-3); text-align: center; padding: 24px 0; margin: 0; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 14px; font-size: 14px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ---------- ボタン ---------- */
.btn {
  min-height: 44px; padding: 8px 16px; border-radius: 10px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  font-size: 15px; font-weight: 500;
}
.btn:hover:not(:disabled) { border-color: var(--ink-3); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); border-color: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.danger { color: var(--danger); }
.btn.danger:hover:not(:disabled) { border-color: var(--danger); background: var(--danger-soft); }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { .btn.danger-solid { color: #2a0f0d; } }
.linklike { background: none; border: 0; padding: 4px; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: 14px; }

/* ---------- ダイアログ ---------- */
dialog {
  border: 0; padding: 0; border-radius: 18px; background: var(--surface); color: var(--ink);
  width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog:has(.wide) { width: min(640px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(20, 20, 28, .45); backdrop-filter: blur(2px); }
.dlg { padding: 22px 22px 18px; }
.dlg h2 { font-size: 18px; margin-bottom: 12px; }
.dlg h3 { font-size: 14px; margin: 22px 0 8px; color: var(--ink-2); letter-spacing: .04em; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--ink-2); }
.req { font-size: 11px; background: var(--accent-soft); color: var(--accent); padding: 0 6px; border-radius: 4px; margin-left: 4px; }
.err { margin: 0; color: var(--danger); font-size: 13px; min-height: 0; }
.err:empty { display: none; }
.ok-msg { margin: 8px 0 0; color: var(--ok); font-size: 14px; font-weight: 600; }
.ok-msg:empty { display: none; }
.hint { color: var(--ink-2); font-size: 13px; margin: 0 0 10px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.dlg-actions.stack { flex-direction: column; align-items: stretch; }
#fText { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; margin-bottom: 12px; }

.import-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 12px; }
.import-stats .hint { grid-column: 1 / -1; margin: 0; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px 14px; }
.stat dt { font-size: 12px; color: var(--ink-2); }
.stat dd { margin: 0; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.new dd { color: var(--accent); }
details summary { cursor: pointer; padding: 8px 0; color: var(--accent); font-weight: 600; font-size: 14px; }
.import-preview { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.ip { display: flex; gap: 10px; padding: 7px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
.ip:last-child { border-bottom: 0; }
.ip-badge { flex: none; font-size: 11px; padding: 1px 6px; border-radius: 4px; height: fit-content; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.ip.dup .ip-badge, .ip.dupbatch .ip-badge { background: var(--surface-2); color: var(--ink-3); }
.ip.dup, .ip.dupbatch { color: var(--ink-3); }
.ip-main { min-width: 0; display: flex; flex-direction: column; }
.ip-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ip-url { color: var(--ink-3); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ip-cat { color: var(--ink-2); font-size: 11px; }
.ip.more { justify-content: center; color: var(--ink-3); }

.fallback-body p { margin: 0 0 6px; }
.fallback-body .strong, .strong { font-weight: 700; }
.fallback-body .small { font-size: 13px; color: var(--ink-2); margin-top: 8px; }
.fallback-link { margin-top: 12px; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; }
.fl-title { margin: 0; font-weight: 600; font-size: 14px; word-break: break-word; }
.fl-url { margin: 2px 0 0; font-size: 12px; color: var(--ink-2); word-break: break-all; user-select: all; -webkit-user-select: all; }
.confirm-body { margin: 0; color: var(--ink-2); }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin-bottom: 6px; }
.data-btns { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100vw - 24px); width: max-content;
  display: flex; align-items: center; gap: 14px;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25); z-index: 50; font-size: 14px;
}
.toast-btn { background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; min-height: 32px; }

.drop-overlay {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 22%, transparent); backdrop-filter: blur(3px);
  border: 4px dashed var(--accent); pointer-events: none;
}
.drop-overlay p { background: var(--surface); padding: 20px 28px; border-radius: 16px; text-align: center; font-weight: 700; font-size: 18px; box-shadow: var(--shadow); }
.drop-overlay small { font-weight: 400; color: var(--ink-2); font-size: 13px; }

.foot { max-width: 880px; margin: 0 auto; padding: 12px 16px 40px; color: var(--ink-3); font-size: 12px; text-align: center; }
.foot p { margin: 4px 0; }

/* ---------- スマートフォン ---------- */
@media (max-width: 720px) {
  .row {
    grid-template-columns: 28px minmax(0, 1fr) auto;
    grid-template-areas: "c m a" "c k k" "c t t";
    gap: 2px 10px;
  }
  .row-check { grid-area: c; }
  .row-main { grid-area: m; }
  .row-actions { grid-area: a; flex-direction: column; }
  .row-cat { grid-area: k; padding: 0; }
  .row-cat:has(.muted) { display: none; }
  .row-meta { grid-area: t; flex-direction: row; flex-wrap: wrap; gap: 2px 12px; }
  .row-memo { display: none; }
  .meta-src { display: none; }
}
@media (max-width: 520px) {
  main { padding: 4px 12px 28px; }
  .hero { padding-top: 8px; }
  .dice-btn { min-height: 104px; border-radius: 22px; gap: 14px; }
  .dice { font-size: 44px; }
  .controls { gap: 8px 10px; }
  .controls select { min-height: 42px; font-size: 15px; }
  .add-actions { grid-template-columns: 1fr; }
  .add-btn.primary small { display: block; }
  .bulk-actions { margin-left: 0; width: 100%; }
  .bulk-actions .btn { flex: 1; }
  .settings-grid { grid-template-columns: 1fr; }
  .dlg { padding: 18px 16px 14px; }
  .h-time { width: 6.5em; }
}

/* ---------- 入口（購入者コード） ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.gate-loading { color: var(--ink-3); font-size: 14px; }
.gate-card {
  width: 100%; max-width: 480px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px 24px 22px; box-shadow: var(--shadow);
}
.gate-brand { margin: 0 0 14px; font-size: 13px; letter-spacing: .1em; color: var(--ink-2); font-weight: 600; }
.gate-title { font-size: clamp(16px, 4.5vw, 21px); line-height: 1.6; margin: 0 0 10px; }
.gate-lead { margin: 0 0 18px; color: var(--ink-2); font-size: 14px; }
#gateCode { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 18px; letter-spacing: .06em; text-transform: uppercase; }
.gate-terms { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; font-size: 13px; color: var(--ink-2); margin: 4px 0 6px; }
.gate-terms p { margin: 0; }
.gate-terms ul { margin: 6px 0 0; padding-left: 1.2em; }
.gate-terms li { margin: 3px 0; }
.gate-terms-link { margin-top: 6px !important; }
.gate-agree { margin: 4px 0; }
.gate-submit { width: 100%; min-height: 52px; font-size: 17px; margin-top: 8px; }
.gate-note { margin: 10px 0 0; font-size: 12px; color: var(--ink-3); text-align: center; }
.gate-note:empty { display: none; }
.license-banner { max-width: 880px; margin: 8px auto 0; padding: 10px 14px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: 13px; }

/* ---------- 利用規約ページ ---------- */
.terms { max-width: 720px; margin: 0 auto; padding: 32px 18px 60px; }
.terms h1 { font-size: 22px; margin: 0 0 16px; }
.terms h2 { font-size: 16px; margin: 26px 0 6px; }
.terms p, .terms li { font-size: 15px; color: var(--ink); }
.terms ol { padding-left: 1.4em; }
.terms-date { margin-top: 28px; color: var(--ink-2); }
