:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --surface-3: #e2e7ec;
  --text: #16212b;
  --muted: #5f6c78;
  --border: #d8dee4;
  --accent: #1c7f55;
  --accent-hover: #166a47;
  --accent-soft: #e2f3ea;
  --accent-text: #ffffff;
  --ok: #1c7f55;
  --ok-soft: #e2f3ea;
  --ng: #c2333d;
  --ng-soft: #fbe7e8;
  --warn-soft: #fff5d6;
  --warn-text: #6b5300;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 6px 20px rgba(16, 24, 32, .08);
  --radius: 14px;
  --radius-sm: 9px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1317;
    --surface: #172027;
    --surface-2: #1f2a32;
    --surface-3: #2a3640;
    --text: #e6ecf1;
    --muted: #94a2ae;
    --border: #2d3a44;
    --accent: #38b57d;
    --accent-hover: #4cc58e;
    --accent-soft: #173828;
    --accent-text: #08130d;
    --ok: #4cc58e;
    --ok-soft: #173828;
    --ng: #f06b73;
    --ng-soft: #3a1c1f;
    --warn-soft: #3a3115;
    --warn-text: #f1d77a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1317;
  --surface: #172027;
  --surface-2: #1f2a32;
  --surface-3: #2a3640;
  --text: #e6ecf1;
  --muted: #94a2ae;
  --border: #2d3a44;
  --accent: #38b57d;
  --accent-hover: #4cc58e;
  --accent-soft: #173828;
  --accent-text: #08130d;
  --ok: #4cc58e;
  --ok-soft: #173828;
  --ng: #f06b73;
  --ng-soft: #3a1c1f;
  --warn-soft: #3a3115;
  --warn-text: #f1d77a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans JP", system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}
img { max-width: 100%; }
h2, h3 { margin: 0; line-height: 1.3; }
.muted { color: var(--muted); }
.grow { flex: 1; }

/* ---------- ボタン・入力 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 700; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--ng); border-color: var(--ng); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--ng); }
.btn-danger-ghost:hover { background: var(--ng-soft); }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn-lg { min-height: 48px; padding: 0 28px; font-size: 16px; }
.btn-round { width: 48px; height: 48px; padding: 0; border-radius: 50%; font-size: 18px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-size: 13px; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.icon-btn { background: none; border: 0; width: 36px; height: 36px; border-radius: 50%; color: var(--muted); font-size: 16px; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.input, .select, input[type=text], input[type=email], input[type=password], input[type=search], textarea {
  width: 100%; min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { resize: vertical; line-height: 1.6; }
.select { width: auto; padding-right: 32px; }
.input:focus, .select:focus, input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 500; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px 2px 6px; border-radius: 999px;
  background: var(--surface-2); font-size: 13px; line-height: 1.6; white-space: nowrap;
}
.chip-more { padding-left: 10px; color: var(--muted); }
.chip-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 13px; padding: 4px 12px; cursor: pointer; }
.chip-btn:hover { background: var(--surface-2); }
.chip-btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip-removable { padding-right: 4px; background: var(--accent-soft); }
.chip-removable button { border: 0; background: none; color: var(--muted); cursor: pointer; width: 22px; height: 22px; border-radius: 50%; font-size: 11px; }
.chip-removable button:hover { background: var(--surface-3); color: var(--text); }
.flag { width: 20px; height: 14px; object-fit: cover; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .12); flex: none; }
.kbd, .kbd-inline {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 5px;
  border: 1px solid var(--border); border-radius: 5px; font-size: 12px; color: var(--muted); background: var(--surface-2);
}
.kbd-inline { margin-left: 8px; background: transparent; border-color: currentColor; color: inherit; opacity: .7; }

/* ---------- ログイン ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { width: 100%; max-width: 380px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 32px 28px; display: flex; flex-direction: column; gap: 18px; text-align: center; }
.login-box form { text-align: left; }
.login-error { margin: 0; min-height: 1.2em; color: var(--ng); font-size: 14px; }

/* ---------- ヘッダー ---------- */
.brand { display: flex; align-items: center; gap: 8px; font-weight: 900; letter-spacing: .02em; }
.brand-lg { justify-content: center; font-size: 22px; }
.brand-mark { font-size: 1.3em; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs a {
  padding: 8px 14px; border-radius: var(--radius-sm); color: var(--muted);
  text-decoration: none; font-weight: 500; white-space: nowrap;
}
.tabs a:hover { background: var(--surface-2); color: var(--text); }
.tabs a.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.user-area { display: flex; align-items: center; gap: 10px; }
.user-label { font-size: 12px; color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.demo-banner { background: var(--warn-soft); color: var(--warn-text); font-size: 13px; padding: 8px 24px; text-align: center; }

.view { max-width: 1100px; margin: 0 auto; padding: 20px 24px 64px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar-sub { margin-top: -4px; }
.counter { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.progress { height: 4px; background: var(--surface-3); border-radius: 2px; overflow: hidden; margin-bottom: 18px; }
.progress-bar { height: 100%; background: var(--accent); transition: width .25s; }
.hint { text-align: center; color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.empty { text-align: center; color: var(--muted); padding: 56px 16px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.section-title { margin: 28px 0 12px; font-size: 16px; }

/* ---------- カード表面・裏面 ---------- */
.front-img { position: relative; flex: 1; min-height: 0; background: #0b0f12; border-radius: var(--radius-sm); overflow: hidden; }
.front-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.img-missing { position: absolute; inset: 0; display: grid; place-items: center; color: #8996a1; }

/* ---------- 拡大・移動 ---------- */
.zoomable { touch-action: none; user-select: none; -webkit-user-select: none; }
.zoomable img { transform-origin: 0 0; will-change: transform; }
.zoomable.is-zoomed { cursor: grab; }
.zoomable.is-dragging { cursor: grabbing; }
.zoom-ctrls {
  position: absolute; right: 10px; bottom: 10px; z-index: 2; display: flex; gap: 2px;
  padding: 3px; border-radius: 10px; background: rgba(10, 14, 18, .62); backdrop-filter: blur(6px);
  opacity: .55; transition: opacity .15s;
}
.zoomable:hover .zoom-ctrls, .zoom-ctrls:focus-within, .zoomable.is-zoomed .zoom-ctrls { opacity: 1; }
.zoom-ctrls button {
  width: 34px; height: 34px; border: 0; border-radius: 7px; background: transparent;
  color: #fff; font-size: 17px; line-height: 1; cursor: pointer;
}
.zoom-ctrls button:hover { background: rgba(255, 255, 255, .18); }
@media (hover: none) { .zoom-ctrls { opacity: 1; } }

.viewer {
  width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0;
  border: 0; background: #05080a; overflow: hidden;
}
.viewer::backdrop { background: #05080a; }
.viewer-stage { position: absolute; inset: 0; }
.viewer-close {
  position: absolute; top: 14px; right: 14px; z-index: 3; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: rgba(255, 255, 255, .14); color: #fff; font-size: 18px; cursor: pointer;
}
.viewer-close:hover { background: rgba(255, 255, 255, .26); }
.viewer-hint {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 2; margin: 0;
  padding: 6px 14px; border-radius: 999px; background: rgba(10, 14, 18, .6); color: #c9d2da; font-size: 12px;
  pointer-events: none; white-space: nowrap; max-width: calc(100vw - 96px); overflow: hidden; text-overflow: ellipsis;
}
.front-desc { margin: 14px 4px 0; font-size: 16px; line-height: 1.7; flex: none; max-height: 7.2em; overflow-y: auto; }

.answer { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 22px; font-weight: 900; line-height: 1.25; }
.answer-country { display: inline-flex; align-items: center; gap: .35em; }
.answer-lg { font-size: clamp(30px, 5.5vw, 52px); }
.answer-lg.answer-many { font-size: clamp(22px, 3.6vw, 34px); }
.answer-md { font-size: clamp(24px, 3.6vw, 36px); justify-content: flex-start; }
.answer-sm { font-size: 22px; justify-content: flex-start; }
.flag-answer { width: 1.25em; height: .875em; border-radius: 3px; }
.answer-area { margin: 8px 0 0; font-size: 18px; font-weight: 700; color: var(--muted); text-align: center; }
.answer-regions { margin: 6px 0 0; font-size: 13px; color: var(--muted); text-align: center; }
.answer-md ~ .answer-area, .answer-md ~ .answer-regions, .answer-sm ~ .answer-area, .answer-sm ~ .answer-regions { text-align: left; }
.notes {
  margin-top: 18px; padding: 14px 16px; border-radius: var(--radius-sm);
  background: var(--surface-2); line-height: 1.8; text-align: left; overflow-wrap: anywhere;
}

/* ---------- 暗記カード ---------- */
.flash-wrap { perspective: 3600px; }
.flashcard {
  position: relative; height: min(72vh, 680px); min-height: 360px;
  transform-style: preserve-3d; cursor: pointer; outline: none;
}
.flashcard:focus-visible .face { box-shadow: 0 0 0 3px var(--accent), var(--shadow); }
.flashcard.is-flipped { transform: rotateY(180deg); }
/* めくる: 少し持ち上げながら回転して、着地で軽く弾む */
.flashcard.anim-to-back { animation: flip-to-back .36s cubic-bezier(.3, .7, .25, 1) both; }
.flashcard.anim-to-front { animation: flip-to-front .36s cubic-bezier(.3, .7, .25, 1) both; }
/* 回転の途中は手前の辺が遠近で大きく見えるので、少し縮めて枠からはみ出さないようにする */
@keyframes flip-to-back {
  0%   { transform: rotateY(0) scale(1); }
  50%  { transform: rotateY(90deg) scale(.86); }
  100% { transform: rotateY(180deg) scale(1); }
}
@keyframes flip-to-front {
  0%   { transform: rotateY(180deg) scale(1); }
  50%  { transform: rotateY(90deg) scale(.86); }
  100% { transform: rotateY(0) scale(1); }
}
.flashcard.anim-to-back .face, .flashcard.anim-to-front .face { animation: flip-shadow .36s ease both; }
@keyframes flip-shadow {
  50% { box-shadow: 0 14px 30px rgba(0, 0, 0, .22); }
}
/* 万一重なってもボタン類が上に来るように */
.view > .toolbar, .view > .study-nav, .view > .hint { position: relative; z-index: 2; }
.flash-wrap { position: relative; z-index: 1; }
/* 前後のカードへ移動するときのスライド */
.flash-wrap.enter-next .flashcard { animation: slide-in-right .34s cubic-bezier(.2, .8, .2, 1) both; }
.flash-wrap.enter-prev .flashcard { animation: slide-in-left .34s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes slide-in-right { from { transform: translateX(70px) rotate(1.5deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slide-in-left { from { transform: translateX(-70px) rotate(-1.5deg); opacity: 0; } to { transform: none; opacity: 1; } }
.feedback { animation: pop-in .28s ease-out both; }
@keyframes pop-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; display: flex; flex-direction: column;
  border-top: 6px solid var(--cat, transparent);
}
.face-back { transform: rotateY(180deg); overflow-y: auto; padding: 28px; }
.back-actions { position: absolute; top: 14px; right: 14px; z-index: 3; display: flex; gap: 6px; }
.back-country-wrap { position: relative; }
.back-menu {
  position: absolute; top: calc(100% + 4px); right: 0; min-width: 180px; max-height: 260px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 4px; display: flex; flex-direction: column; z-index: 4;
}
.back-menu button {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 0; border-radius: 6px;
  background: none; color: var(--text); font: inherit; font-size: 14px; text-align: left; cursor: pointer; white-space: nowrap;
}
.back-menu button:hover, .back-menu button:focus-visible { background: var(--surface-2); outline: none; }
.back-inner { margin: auto 0; width: 100%; }
.back-answer { padding: 12px 0; }
.face-back .notes { max-width: 760px; margin-left: auto; margin-right: auto; }
.study-nav { display: flex; justify-content: center; align-items: center; gap: 16px; margin-top: 18px; }
.study-nav .btn-primary { min-width: 140px; min-height: 48px; }

/* ---------- タイル ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.tile {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: transform .15s, box-shadow .15s;
}
.tile:hover, .tile:focus-visible { transform: translateY(-2px); box-shadow: var(--shadow); outline: none; }
.tile-img { position: relative; aspect-ratio: 4 / 3; background: #0b0f12; overflow: hidden; }
.tile-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.tile-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.tile-countries { display: flex; flex-wrap: wrap; gap: 4px; }
.tile-desc { margin: 0; font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile-given { margin: 0; font-size: 12px; color: var(--ng); }
.tile-actions { display: flex; gap: 6px; margin-top: auto; padding-top: 4px; }
.tile-actions .btn { flex: 1; }

/* ---------- 検索 ---------- */
.search-bar { margin-bottom: 12px; }
.search-input { min-height: 52px !important; font-size: 17px !important; padding: 10px 18px !important; border-radius: 999px !important; }
.region-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.result-count { margin: 0 0 12px; font-size: 13px; }

/* ---------- クイズ ---------- */
.quiz-setup { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.setup-block { display: flex; flex-direction: column; gap: 10px; }
.setup-label { display: flex; align-items: baseline; gap: 12px; font-weight: 700; }
.setup-actions { display: flex; gap: 12px; margin-left: auto; }
.setup-row { display: flex; gap: 28px; flex-wrap: wrap; }
.region-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.region-check {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; font-size: 14px;
}
.region-check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.region-check input { accent-color: var(--accent); }
.region-check .count { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.region-check.is-empty { opacity: .6; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--text); font: inherit; padding: 8px 16px; cursor: pointer; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: var(--accent-text); font-weight: 700; }
.setup-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 6px; border-top: 1px solid var(--border); padding-top: 18px; }

.quiz-card {
  height: min(58vh, 560px); min-height: 280px; display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px;
}
.quiz-prompt { text-align: center; font-weight: 700; margin: 18px 0 10px; }
.choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; max-width: 760px; margin: 0 auto; }
.choice {
  display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 8px 14px;
  border: 2px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  font: inherit; font-size: 16px; font-weight: 700; cursor: pointer; text-align: left;
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice .flag { width: 26px; height: 18px; }
.choice.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.wrong { border-color: var(--ng); background: var(--ng-soft); }
.choice.dim { opacity: .5; }
.choice:disabled { cursor: default; }
.input-answer { display: flex; gap: 8px; max-width: 560px; margin: 0 auto; }
.input-answer input { min-height: 48px; font-size: 16px; }
.feedback {
  max-width: 760px; margin: 18px auto 0; padding: 18px 20px; border-radius: var(--radius);
  border: 2px solid; background: var(--surface); display: flex; flex-direction: column; gap: 6px;
}
.feedback.ok { border-color: var(--ok); }
.feedback.ng { border-color: var(--ng); }
.feedback-title { font-size: 18px; font-weight: 900; }
.feedback.ok .feedback-title { color: var(--ok); }
.feedback.ng .feedback-title { color: var(--ng); }
.feedback .notes { margin-top: 8px; }
.feedback-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.feedback-head .btn { flex: none; }
.feedback-head .feedback-title { flex: 1; min-width: 0; }
.feedback-head { flex-wrap: nowrap; gap: 8px; }

.result { text-align: center; max-width: 560px; margin: 0 auto; }
.score { font-size: 64px; font-weight: 900; line-height: 1.1; font-variant-numeric: tabular-nums; }
.score span { font-size: 28px; color: var(--muted); }
.score-pct { color: var(--muted); margin-bottom: 20px; }
.result-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------- モーダル ---------- */
.modal {
  padding: 0; border: 0; border-radius: var(--radius); background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto;
}
.modal::backdrop { background: rgba(8, 12, 16, .6); }
.modal-wide { width: min(1080px, calc(100vw - 32px)); }
.modal-sm { width: min(440px, calc(100vw - 32px)); }
.modal-inner { padding: 20px 24px 24px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { font-size: 18px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

.detail { display: grid; grid-template-columns: 1.5fr 1fr; gap: 24px; }
.detail-front { display: flex; flex-direction: column; height: min(66vh, 620px); min-height: 300px; }
.detail-back { overflow-y: auto; max-height: min(66vh, 620px); }

/* ---------- エディタ ---------- */
.editor { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.editor-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.side-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.dropzone {
  position: relative; aspect-ratio: 4 / 3; border: 2px dashed var(--border); border-radius: var(--radius-sm);
  display: grid; place-items: center; overflow: hidden; cursor: pointer; background: var(--surface-2); text-align: center;
}
.dropzone:hover, .dropzone.over, .dropzone:focus-visible { border-color: var(--accent); outline: none; }
.dropzone img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #0b0f12; }
.dropzone-hint { color: var(--text); font-size: 14px; line-height: 1.9; padding: 16px; }
.selected-chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 30px; align-items: center; font-size: 13px; }
.picker { display: flex; flex-direction: column; gap: 8px; }
.picker-list { max-height: 300px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.picker-region { border-bottom: 1px solid var(--border); }
.picker-region:last-child { border-bottom: 0; }
.picker-region summary {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; cursor: pointer; list-style: none;
  font-weight: 700; font-size: 14px; position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.picker-region summary::-webkit-details-marker { display: none; }
.picker-region summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
.picker-region[open] summary::before { transform: rotate(90deg); }
.picker-region summary:hover { background: var(--surface-2); }
.picker-sel-count { font-size: 12px; font-weight: 500; color: var(--accent); }
.picker-all { margin-left: auto; }
.picker-countries { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 2px; padding: 4px 8px 10px; }
.picker-country { display: flex; align-items: center; gap: 7px; padding: 5px 6px; border-radius: 6px; font-size: 14px; cursor: pointer; }
.picker-country:hover { background: var(--surface-2); }
.picker-country input { accent-color: var(--accent); flex: none; }
.picker-country:has(input:checked) { background: var(--accent-soft); }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 1000;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--ng); color: #fff; }

/* ---------- スマホ ---------- */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 8px 16px; gap: 6px 12px; }
  .brand-text { font-size: 15px; }
  .tabs { order: 3; flex-basis: 100%; }
  .tabs a { padding: 6px 10px; font-size: 14px; }
  .user-area { margin-left: auto; }
  .user-label { display: none; }
  .view { padding: 14px 16px 48px; }
  .demo-banner { padding: 8px 16px; }
  .flashcard { height: 68vh; min-height: 320px; }
  .face { padding: 10px; }
  .face-back { padding: 18px; }
  .front-desc { font-size: 15px; }
  .choices { grid-template-columns: 1fr; }
  .detail, .editor { grid-template-columns: 1fr; }
  .detail-front { height: 46vh; }
  .detail-back { max-height: none; }
  .modal { max-height: calc(100vh - 16px); width: calc(100vw - 16px) !important; }
  .modal-inner { padding: 16px; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .panel { padding: 18px 16px; }
  .setup-foot { flex-direction: column; align-items: stretch; }
  .input-answer { flex-direction: column; }
}

/* ---------- カテゴリー ---------- */
.small { font-size: 13px; }
.cat-badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px;
  background: var(--cat); color: var(--cat-text, #fff); font-size: 12px; font-weight: 700; line-height: 1.5;
  white-space: nowrap; box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.cat-on-img { position: absolute; top: 10px; left: 10px; z-index: 2; pointer-events: none; }
.cat-on-back { position: absolute; top: 16px; left: 16px; z-index: 2; }
.tile { border-top: 4px solid var(--cat, var(--border)); }
.tile .cat-on-img { top: 6px; left: 6px; font-size: 11px; padding: 2px 8px; }
.quiz-card { border-top: 6px solid var(--cat, transparent); }
.cat-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--cat); flex: none; box-shadow: 0 0 0 1px rgba(0, 0, 0, .15); }
.chip-cat { display: inline-flex; align-items: center; gap: 6px; }
.chip-cat.on { background: var(--cat); border-color: var(--cat); color: var(--cat-text); }
.chip-cat.on .cat-dot { box-shadow: 0 0 0 2px var(--cat-text); }
.cat-check:has(input:checked) { border-color: var(--cat); background: color-mix(in srgb, var(--cat) 14%, var(--surface)); }
.cat-check input { accent-color: var(--cat); }
.cat-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-opt {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--border); font-size: 13px; cursor: pointer; user-select: none;
}
.cat-opt input { position: absolute; opacity: 0; pointer-events: none; }
.cat-opt:hover { background: var(--surface-2); }
.cat-opt:has(input:checked) { background: var(--cat); border-color: var(--cat); color: var(--cat-text); font-weight: 700; }
.cat-opt:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.modal-md { width: min(640px, calc(100vw - 32px)); }
.cat-rows { display: flex; flex-direction: column; gap: 6px; margin: 12px 0 16px; }
.cat-row { display: flex; align-items: center; gap: 6px; }
.cat-row .cat-name { flex: 1; min-width: 0; }
.cat-count { font-size: 12px; min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }
.cat-color { width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; background: none; cursor: pointer; flex: none; }
.cat-color::-webkit-color-swatch-wrapper { padding: 0; }
.cat-color::-webkit-color-swatch { border: 2px solid var(--surface); border-radius: 50%; box-shadow: 0 0 0 1px var(--border); }
.cat-color::-moz-color-swatch { border: 2px solid var(--surface); border-radius: 50%; }
.cat-add { display: flex; gap: 6px; align-items: center; padding-top: 12px; border-top: 1px dashed var(--border); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-danger:hover { background: var(--ng-soft); }

/* ---------- 地図 ---------- */
.map-hint { margin-left: auto; }
.map-layout { display: grid; grid-template-columns: 1fr 360px; gap: 14px; height: calc(100vh - 170px); height: calc(100dvh - 170px); min-height: 460px; }
.map-box { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); }
.map { position: absolute; inset: 0; }
/* タイルの読み込み前に見える背景を海の色に（白く抜けて見えないように） */
.map-box, .map.leaflet-container { background: #aad3df; }
.map-dark.leaflet-container { background: #1d2c33; }
:root[data-theme="dark"] .map-box { background: #1d2c33; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .map-box { background: #1d2c33; } }
.leaflet-tile-container img { outline: 1px solid transparent; } /* タイル間の細い隙間対策 */
.map-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); z-index: 500; }
.map-panel { overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.panel-title { display: flex; align-items: center; gap: 8px; font-size: 15px; margin: 0 0 10px; }
.panel-country + .panel-country { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.map-country-list { display: flex; flex-wrap: wrap; gap: 6px; }
.map-country-list .chip-btn { display: inline-flex; align-items: center; gap: 6px; }
.tiles-compact { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tiles-compact .tile-desc { -webkit-line-clamp: 1; }
.map-tip { font-family: inherit; font-weight: 700; }
.ext-link {
  margin-left: auto; display: inline-grid; place-items: center; width: 28px; height: 28px; flex: none;
  border-radius: 6px; color: var(--muted); text-decoration: none;
}
.ext-link:hover { color: var(--accent); background: var(--surface-2); }
/* Leaflet の .leaflet-marker-icon { display:block } に負けないよう詳細度を上げる */
.leaflet-marker-icon.map-count {
  display: flex; align-items: center; justify-content: center; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 11px; line-height: 1;
  border: 1.5px solid var(--surface); box-shadow: 0 1px 5px rgba(0, 0, 0, .35); cursor: pointer;
  transition: transform .15s; font-variant-numeric: tabular-nums;
}
.leaflet-marker-icon.map-count span { display: block; text-align: center; }
.leaflet-marker-icon.map-count:hover { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent), 0 1px 5px rgba(0, 0, 0, .35); }
.map-thumbs-icon { overflow: visible; }
.map-thumbs {
  background: var(--surface); color: var(--text); border-radius: 10px; padding: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .35); cursor: default;
  transform-origin: 50% 20px; transform: scale(.58); transition: transform .2s ease-out;
}
.map-thumbs-head { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 0 2px 5px; white-space: nowrap; cursor: pointer; }
.map-thumbs-head .flag { width: 16px; height: 11px; }
.map-thumbs-n { margin-left: auto; background: var(--accent); color: var(--accent-text); border-radius: 999px; padding: 0 7px; font-size: 11px; }
.map-thumbs-grid { display: grid; gap: 4px; }
.map-thumb {
  position: relative; z-index: 0; aspect-ratio: 4 / 3; border-radius: 5px; overflow: hidden; background: #0b0f12; cursor: pointer;
  border: 2px solid var(--cat, transparent);
  transition: transform .18s cubic-bezier(.2, .8, .2, 1.2), box-shadow .18s;
}
.map-thumb:hover { transform: scale(1.12); z-index: 1; box-shadow: 0 4px 12px rgba(0, 0, 0, .4); }
.map-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.map-thumbs-more { font-size: 11px; color: var(--muted); text-align: right; padding: 4px 2px 0; cursor: pointer; }
.leaflet-container { font-family: inherit; }
.map-dark .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9); }

@media (max-width: 760px) {
  .map-layout { grid-template-columns: 1fr; grid-template-rows: 58vh auto; height: auto; }
  .map-panel { max-height: none; }
  .map-hint { display: none; }
  .cat-row { flex-wrap: wrap; }
}

/* ---------- 国の基本情報 ---------- */
.country-link {
  display: inline-flex; align-items: center; gap: 8px; padding: 2px 6px; margin: -2px -6px;
  border: 0; border-radius: 6px; background: none; color: inherit; font: inherit; cursor: pointer;
  text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 4px;
}
.country-link:hover { background: var(--surface-2); text-decoration-color: var(--accent); color: var(--accent); }
.cinfo-hero { display: flex; gap: 18px; align-items: center; margin-bottom: 18px; }
.cinfo-flag { width: 120px; height: auto; max-height: 90px; object-fit: contain; border-radius: 4px; box-shadow: 0 0 0 1px var(--border), 0 2px 8px rgba(0, 0, 0, .12); flex: none; }
.cinfo-name { font-size: 28px; font-weight: 900; line-height: 1.2; }
.cinfo-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.cinfo-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { font-size: 12px; padding: 1px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.info-list { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.info-row { padding: 10px 0; border-top: 1px solid var(--border); min-width: 0; }
.info-row-wide { grid-column: 1 / -1; }
.info-row dt { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.info-row dd { margin: 0; overflow-wrap: anywhere; }
.info-row code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; font-weight: 700; background: var(--surface-2); padding: 1px 6px; border-radius: 5px; }
.drive { font-weight: 900; font-size: 16px; }
.drive-left { color: var(--ng); }
.drive-right { color: var(--accent); }
.nb-btn { display: inline-flex; align-items: center; gap: 6px; margin: 0 4px 4px 0; }
.lang-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.lang-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 14px; font-weight: 700;
  padding: 4px 12px; border-radius: 999px; cursor: pointer;
}
.lang-btn::after { content: " ▾"; color: var(--muted); font-size: 11px; }
.lang-btn:hover { border-color: var(--accent); }
.lang-btn[aria-expanded="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.lang-btn[aria-expanded="true"]::after { content: " ▴"; color: inherit; }
.info-row-wide dd { position: relative; }
.lang-pop {
  --pop-bg: color-mix(in srgb, var(--accent) 12%, var(--surface));
  position: absolute; z-index: 20; padding: 14px 16px; border-radius: var(--radius-sm);
  background: var(--pop-bg); border: 1.5px solid var(--accent); box-shadow: 0 12px 32px rgba(0, 0, 0, .28);
  animation: pop-in .16s ease-out both;
}
.lang-pop::before {
  content: ""; position: absolute; top: -8px; left: calc(var(--arrow-x, 24px) - 7px);
  width: 13px; height: 13px; background: var(--pop-bg);
  border-left: 1.5px solid var(--accent); border-top: 1.5px solid var(--accent); transform: rotate(45deg);
}
.lang-pop .lg-title { color: var(--accent); }
.lang-pop-close { position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; font-size: 13px; }
.lang-pop .lg-title { padding-right: 28px; }
.lg-title { font-weight: 900; font-size: 16px; margin-bottom: 8px; }
.lg-list { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.lg-list dt { font-size: 12px; color: var(--muted); }
.lg-list dd { margin: 0; line-height: 1.7; }
.lg-chars { font-size: 20px; letter-spacing: .04em; }
.lg-countries-btn { margin-top: 12px; font-size: 13px; }
.lg-countries {
  display: flex; flex-wrap: wrap; align-content: flex-start; margin-top: 8px; max-height: 200px; padding-right: 4px;
  overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; /* 一覧の中だけスクロールし、端まで来ても詳細画面を動かさない */
}
.lg-countries::-webkit-scrollbar { display: block; width: 6px; }
.lg-countries::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.lg-countries .nb-btn { font-size: 13px; }
.lg-countries .is-current { opacity: .55; }
@media (max-width: 760px) {
  .info-list { grid-template-columns: 1fr; }
  .cinfo-flag { width: 84px; }
  .cinfo-name { font-size: 22px; }
}

/* ---------- 画面の高さに収めるレイアウト（暗記カード・クイズ出題中） ---------- */
.tab-short { display: none; }
#app.app-fit { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
#app.app-fit .topbar, #app.app-fit .demo-banner { flex: none; }
.view.view-fit { flex: 1; min-height: 0; width: 100%; display: flex; flex-direction: column; padding-bottom: 14px; }
.view-fit > .toolbar, .view-fit > .progress, .view-fit > .study-nav, .view-fit > .hint { flex: none; }
.view-fit .flash-wrap { flex: 1; min-height: 0; display: flex; }
.view-fit .flashcard { flex: 1; height: auto; min-height: 0; max-height: 720px; margin: 0 auto; width: 100%; }
.view-fit .empty { flex: 1; }
.view-fit .quiz-card { flex: 1; height: auto; min-height: 140px; max-height: 620px; }
.view-fit .quiz-bottom { flex: none; max-height: 55%; overflow-y: auto; overscroll-behavior: contain; padding: 2px 2px 0; }
.view-fit .quiz-prompt { margin: 12px 0 8px; }
.view-fit .feedback { margin-top: 10px; }
.quiz-bottom.is-answered .choices { margin-top: 12px; }

@media (max-width: 760px) {
  .tab-long { display: none; }
  .tab-short { display: inline; }
  /* ヘッダーを1行に */
  .topbar { flex-wrap: nowrap; padding: 6px 10px; gap: 6px; }
  .brand-text { display: none; }
  .tabs { order: 0; flex: 1; flex-basis: auto; gap: 2px; }
  .tabs a { padding: 6px 9px; font-size: 14px; }
  .user-area { margin-left: 0; }
  #logout-btn { min-height: 34px; padding: 0 10px; }
  .demo-banner { padding: 4px 12px; font-size: 12px; }

  .view-fit { padding: 10px 10px 10px; }
  .view-fit .toolbar { gap: 6px; margin-bottom: 8px; flex-wrap: nowrap; }
  .view-fit .toolbar .select { flex: 1 1 0; min-width: 0; min-height: 36px; font-size: 13px; padding: 4px 26px 4px 8px; }
  .view-fit .toolbar .btn { min-height: 36px; padding: 0 10px; }
  .view-fit .counter { font-size: 13px; white-space: nowrap; }
  .view-fit .progress { margin-bottom: 10px; }
  .view-fit .flashcard { min-height: 0; }
  .face { padding: 8px; }
  .face-back { padding: 44px 16px 16px; }
  .front-desc { font-size: 14px; margin-top: 8px; max-height: 4.8em; }
  .answer-lg { font-size: clamp(26px, 8vw, 40px); }
  .view-fit .study-nav { margin-top: 10px; gap: 12px; }
  .view-fit .study-nav .btn-round { width: 44px; height: 44px; }
  .view-fit .study-nav .btn-primary { min-height: 44px; min-width: 120px; }
  .view-fit .hint { margin-top: 6px; font-size: 11px; }

  .view-fit .quiz-card { padding: 8px; min-height: 120px; }
  .view-fit .quiz-prompt { margin: 8px 0 6px; font-size: 14px; }
  .view-fit .choices { grid-template-columns: 1fr 1fr; gap: 6px; }
  .view-fit .choice { min-height: 46px; padding: 6px 8px; font-size: 14px; gap: 6px; }
  .view-fit .choice .kbd { display: none; }
  .view-fit .choice .flag { width: 22px; height: 15px; }
  .view-fit .input-answer { flex-direction: row; }
  .view-fit .input-answer input { min-height: 44px; }
  .view-fit .feedback { padding: 12px 14px; margin-top: 8px; }
  .view-fit .feedback .kbd-inline { display: none; }
  .view-fit .feedback .notes { margin-top: 6px; padding: 10px 12px; font-size: 14px; }
  .answer-sm { font-size: 18px; }
}

/* ---------- クイズ: 複数回答 ---------- */
.multi-input {
  flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  min-height: 48px; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); cursor: text;
}
.multi-input:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.multi-input input { flex: 1; min-width: 140px; border: 0 !important; outline: none !important; min-height: 32px !important; padding: 0 4px !important; background: transparent; font-size: 16px; }
.q-chips { display: contents; }
.multi-note { text-align: center; margin: 8px 0 0; }
.given-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; max-width: 760px; margin: 12px auto 0; }
.given { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; font-weight: 700; font-size: 14px; border: 2px solid; }
.given small { font-weight: 400; }
.given-hit { border-color: var(--ok); background: var(--ok-soft); }
.given-miss { border-color: var(--border); border-style: dashed; color: var(--muted); }
.given-wrong { border-color: var(--ng); background: var(--ng-soft); text-decoration: line-through; text-decoration-thickness: 1px; }
.feedback.fb-ok { border-color: var(--ok); }
.feedback.fb-ok .feedback-title { color: var(--ok); }
.feedback.fb-ng { border-color: var(--ng); }
.feedback.fb-ng .feedback-title { color: var(--ng); }
.feedback.fb-partial { border-color: #e8a317; }
.feedback.fb-partial .feedback-title { color: #c98a00; }
.feedback-title small { font-size: 14px; font-weight: 700; }

/* ---------- モーダルの戻る・国情報のカード一覧 ---------- */
.modal-head { gap: 8px; }
.modal-head h2 { flex: 1; }
.modal-back { flex: none; padding: 0 10px; max-width: 45%; overflow: hidden; text-overflow: ellipsis; }
.answer .country-link { margin: 0; padding: 2px 6px; font-weight: 900; }
.detail-hint { margin: 6px 0 0; }
.tag-link { text-decoration: none; color: var(--accent); background: var(--accent-soft); }
.tag-link:hover { text-decoration: underline; }
.cinfo-cards { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.cinfo-cards-title { font-size: 15px; margin-bottom: 10px; }
.cinfo-cards .cat-chips { margin-bottom: 12px; }

@media (max-width: 760px) {
  .view-fit .multi-input { min-height: 44px; }
  .view-fit .multi-note { font-size: 12px; margin-top: 4px; }
  .view-fit .given-list { margin-top: 6px; }
  .view-fit .given { font-size: 13px; padding: 3px 10px; }
}

/* ---------- スクロールバーを非表示（スクロール自体はできる） ---------- */
* { scrollbar-width: none; -ms-overflow-style: none; }
*::-webkit-scrollbar { display: none; width: 0; height: 0; }

/* ---------- アニメーション オフ ---------- */
.no-anim *, .no-anim *::before, .no-anim *::after {
  animation-duration: 0s !important; animation-delay: 0s !important;
  transition-duration: 0s !important; transition-delay: 0s !important; scroll-behavior: auto !important;
}

/* ---------- 設定 ---------- */
.gear-btn { display: inline-grid; place-items: center; }
.gear-btn svg { display: block; transform-origin: 50% 50%; }
/* ホバー中はゆっくり回り続け、押すと1回転（アニメーション設定オフのときは止まる） */
.gear-btn:hover svg { animation: gear-spin 2.4s linear infinite; }
.gear-btn:active svg { animation: gear-spin .5s cubic-bezier(.3, .7, .3, 1) 1; }
@keyframes gear-spin { to { transform: rotate(360deg); } }

.modal-settings { width: min(520px, calc(100vw - 32px)); }
.modal-settings .modal-head { margin-bottom: 18px; }
.set-group-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 0 8px 4px; letter-spacing: .02em; }
.set-group {
  background: var(--surface-2); border-radius: var(--radius); padding: 2px 18px; margin-bottom: 22px;
}
.set-item { display: flex; align-items: center; gap: 20px; padding: 16px 0; }
.set-item + .set-item { border-top: 1px solid var(--border); }
.set-item-stacked { flex-direction: column; align-items: stretch; gap: 12px; }
.set-text { flex: 1; min-width: 0; }
.set-title { font-weight: 700; font-size: 15px; }
.set-desc { font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.5; }
.set-item .seg { display: flex; width: 100%; background: var(--surface); }
.set-item .seg button { flex: 1; padding: 9px 8px; font-size: 14px; }
.set-note { text-align: center; margin: -6px 0 0; }
.set-foot { margin-top: 16px; }
.switch { position: relative; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { display: block; width: 50px; height: 30px; border-radius: 999px; background: var(--surface-3); transition: background .2s; position: relative; }
.switch-thumb { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 760px) {
  .set-group { padding: 2px 14px; }
  .gear-btn { width: 34px; height: 34px; }
}

/* ---------- キー割り当て ---------- */
.set-key { padding: 10px 0; }
.set-key .set-title { font-weight: 500; font-size: 14px; }
.keycap {
  min-width: 56px; height: 34px; padding: 0 12px; flex: none;
  border: 1px solid var(--border); border-bottom-width: 3px; border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; font-weight: 700; font-size: 14px; cursor: pointer;
}
.keycap:hover { border-color: var(--accent); }
.keycap.is-capturing { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); animation: key-blink 1s ease-in-out infinite; }
@keyframes key-blink { 50% { opacity: .55; } }
.set-key-note { padding: 10px 0 14px; border-top: 1px solid var(--border); }

/* ---------- 検索（Spotlight 風） ---------- */
.spot-trigger {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 8px 0 12px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); color: var(--muted);
  font: inherit; font-size: 13px; cursor: pointer; transition: border-color .15s, color .15s;
}
.spot-trigger:hover { border-color: var(--accent); color: var(--text); }
.spot-trigger kbd {
  font-family: inherit; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 5px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
}
.spotlight {
  padding: 0; border: 0; background: transparent; color: var(--text); overflow: visible;
  width: min(920px, calc(100vw - 32px)); max-width: none; max-height: none;
  margin: 8vh auto auto; position: fixed; inset: 0; height: fit-content;
}
.spotlight::backdrop { background: rgba(8, 12, 16, .35); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.spotlight[open] { animation: spot-in .22s cubic-bezier(.2, .9, .3, 1.1) both; }
.spotlight[open]::backdrop { animation: fade-in .2s ease-out both; }
.spotlight.closing { animation: spot-out .15s ease-in both; }
.spotlight.closing::backdrop { animation: fade-out .15s ease-in both; }
@keyframes spot-in { from { opacity: 0; transform: translateY(-14px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes spot-out { to { opacity: 0; transform: translateY(-8px) scale(.97); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
.spot-inner {
  display: flex; flex-direction: column; max-height: 80vh; max-height: 80dvh;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 30px 80px rgba(0, 0, 0, .35); overflow: hidden;
}
.spot-bar { display: flex; align-items: center; gap: 10px; padding: 14px 16px 12px 20px; border-bottom: 1px solid var(--border); }
.spot-icon { color: var(--muted); flex: none; }
.spot-input {
  flex: 1; min-width: 0; border: 0 !important; outline: none !important; background: transparent !important;
  font-size: 22px !important; padding: 4px 0 !important; min-height: 40px !important;
}
.spot-filters { padding: 12px 18px 4px; display: flex; flex-direction: column; gap: 8px; }
.spot-filters .region-chips { margin: 0; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
.spot-filters .chip-btn { flex: none; }
.spot-results { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 18px 16px; overscroll-behavior: contain; }
.spot-results .tiles { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.spot-results .tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.spot-foot { font-size: 11px; text-align: center; padding: 8px; border-top: 1px solid var(--border); }
@media (max-width: 760px) {
  .spotlight { margin-top: 8px; width: calc(100vw - 16px); }
  .spot-inner { max-height: calc(100dvh - 16px); border-radius: 14px; }
  .spot-input { font-size: 17px !important; }
  .spot-bar { padding: 10px 10px 8px 14px; }
  .spot-filters { padding: 10px 12px 2px; }
  .spot-results { padding: 8px 12px 12px; }
  .spot-results .tiles { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .spot-foot { display: none; }
  .spot-trigger { width: 34px; padding: 0; justify-content: center; }
}

/* ---------- キー重複の警告 ---------- */
.keycap.is-dup { border-color: var(--ng); color: var(--ng); background: var(--ng-soft); box-shadow: 0 0 0 2px color-mix(in srgb, var(--ng) 35%, transparent); }
.key-dup-warn { margin: 6px 0 0; padding: 8px 12px; border-radius: 8px; background: var(--ng-soft); color: var(--ng); font-size: 13px; font-weight: 700; }

/* ---------- キーのリセット ---------- */
.key-reset { width: 30px; height: 30px; font-size: 16px; flex: none; }
.key-reset:disabled { visibility: hidden; }
.key-reset-all-row { display: flex; justify-content: flex-end; padding: 10px 0 2px; border-top: 1px solid var(--border); }
.key-reset-all-row .btn:disabled { opacity: .4; }

/* ---------- 横スクロールのチップ列 ---------- */
.hscroll { position: relative; }
.hscroll .region-chips { cursor: grab; user-select: none; -webkit-user-select: none; }
.hscroll .region-chips.is-dragging { cursor: grabbing; }
.hscroll .region-chips.is-dragging .chip-btn { pointer-events: none; }
.hscroll.can-left .region-chips { -webkit-mask-image: linear-gradient(to right, transparent 0, #000 48px); mask-image: linear-gradient(to right, transparent 0, #000 48px); }
.hscroll.can-right .region-chips { -webkit-mask-image: linear-gradient(to left, transparent 0, #000 48px); mask-image: linear-gradient(to left, transparent 0, #000 48px); }
.hscroll.can-left.can-right .region-chips { -webkit-mask-image: linear-gradient(to right, transparent 0, #000 48px, #000 calc(100% - 48px), transparent 100%); mask-image: linear-gradient(to right, transparent 0, #000 48px, #000 calc(100% - 48px), transparent 100%); }
.hs-btn {
  position: absolute; top: 50%; z-index: 2; width: 28px; height: 28px; margin-top: -15px;
  border: 1px solid var(--border); border-radius: 50%; background: var(--surface); color: var(--text);
  font-size: 18px; line-height: 1; cursor: pointer; box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
  display: none; place-items: center; padding: 0 0 2px;
}
.hs-btn:hover { border-color: var(--accent); color: var(--accent); }
.hs-left { left: -4px; }
.hs-right { right: -4px; }
.hscroll.can-left .hs-left, .hscroll.can-right .hs-right { display: grid; }
@media (hover: none) { .hs-btn { display: none !important; } }

.tile-snippet { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile-snippet mark { background: color-mix(in srgb, #f5c400 45%, transparent); color: var(--text); border-radius: 3px; padding: 0 1px; }

/* ---------- 入力欄のインライン補完（PC: 検索・クイズ） ---------- */
.spot-field { position: relative; flex: 1; min-width: 0; display: flex; }
.ghost-field { position: relative; flex: 1; min-width: 0; display: flex; }
.ghost-field > input { position: relative; z-index: 1; flex: 1; min-width: 0; background: transparent !important; }
.ghost {
  position: absolute; inset: 0; display: flex; align-items: center; pointer-events: none;
  white-space: pre; overflow: hidden; z-index: 0;
}
.g-typed { color: transparent; }
.g-rest { color: var(--muted); opacity: .6; }
.g-hint { color: var(--muted); opacity: .75; font-size: .75em; margin-left: .4em; }
.g-tab {
  margin-left: 10px; font-family: inherit; font-size: 11px; font-weight: 700; color: var(--muted);
  padding: 1px 6px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface-2); line-height: 1.4;
}
.spot-input::-webkit-search-cancel-button { position: relative; z-index: 2; }
.multi-input .ghost-field { min-width: 160px; }

/* ---------- 起動エラー表示 ---------- */
.boot-error { max-width: 560px; margin: 12vh auto; padding: 24px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--ng); box-shadow: var(--shadow); }
.boot-error h2 { color: var(--ng); margin-bottom: 10px; }
.boot-error pre, .err-pre { white-space: pre-wrap; font-size: 12px; background: var(--surface-2); padding: 10px; border-radius: 8px; text-align: left; overflow-wrap: anywhere; }

/* ---------- 地図の国検索バー ---------- */
.map-search {
  position: absolute; top: 10px; left: 56px; z-index: 1001; width: min(360px, calc(100% - 70px));
  display: flex; align-items: center; gap: 8px; padding: 0 8px 0 12px; height: 40px;
  background: var(--surface); color: var(--muted); border: 1px solid var(--border); border-radius: 999px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
}
.map-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent), 0 2px 10px rgba(0, 0, 0, .18); }
.map-search svg { flex: none; }
.map-search input { flex: 1; min-width: 0; border: 0 !important; outline: none !important; background: transparent !important; padding: 0 !important; min-height: 36px !important; font-size: 15px; color: var(--text); }
.map-search .ghost-field { flex: 1; }
.map-search-help {
  flex: none; width: 20px; height: 20px; display: grid; place-items: center; border-radius: 50%;
  border: 1px solid var(--border); font-size: 11px; font-weight: 700; cursor: help;
}
@media (max-width: 760px) {
  .map-search { left: 50px; height: 38px; }
}

/* ---------- 地図の右パネル: 上段 = 国の情報、下段 = カード / 表示中の国 ---------- */
.map-panel { display: flex; flex-direction: column; padding: 0 !important; overflow: hidden !important; }
.pinfo {
  flex: 0 0 36%; min-height: 0; overflow-y: auto; padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border); background: var(--surface-2); position: relative;
}
.pinfo-empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--muted); text-align: center; font-weight: 700; }
.pinfo-empty small { font-weight: 400; font-size: 12px; opacity: .8; }
.pinfo-globe { font-size: 32px; opacity: .6; }
.plist { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 14px 14px; }
.plist .focus-cats { margin-bottom: 10px; }
.list-title { font-size: 13px; color: var(--muted); margin: 0 0 8px; font-weight: 700; }
.clist { display: flex; flex-direction: column; gap: 2px; }
.crow { padding: 6px 6px; border-radius: 8px; }
.crow:hover { background: var(--surface-2); }
.crow-head { display: flex; align-items: center; gap: 6px; }
.crow-name {
  display: inline-flex; align-items: center; gap: 7px; min-width: 0; flex: 1; padding: 2px 0; border: 0; background: none;
  color: var(--text); font: inherit; font-weight: 700; font-size: 14px; cursor: pointer; text-align: left;
}
.crow-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crow-name:hover { color: var(--accent); }
.crow-n { font-size: 12px; color: var(--muted); flex: none; font-variant-numeric: tabular-nums; }
.crow .ext-link { width: 24px; height: 24px; margin-left: 0; }
.crow-thumbs { display: flex; gap: 4px; margin-top: 5px; overflow: hidden; }
.crow-thumb {
  position: relative; flex: none; width: 52px; height: 39px; padding: 0; border-radius: 5px; overflow: hidden; cursor: pointer;
  border: 2px solid var(--cat, var(--border)); background: #0b0f12; transition: transform .15s;
}
.crow-thumb:hover { transform: scale(1.08); }
.crow-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.crow-more { flex: none; height: 39px; padding: 0 8px; border: 1px dashed var(--border); border-radius: 5px; background: none; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; }
@media (max-width: 760px) {
  .map-panel { overflow: visible !important; }
  .pinfo { flex: none; }
  .pinfo.is-empty { display: none; }
  .plist { overflow: visible; }
}
.sum-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.sum-flag { width: 44px; height: auto; max-height: 32px; object-fit: contain; border-radius: 3px; box-shadow: 0 0 0 1px var(--border); flex: none; }
.sum-names { flex: 1; min-width: 0; }
.sum-name { font-size: 18px; font-weight: 900; line-height: 1.2; }
.sum-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sum-head .ext-link { margin-left: 0; }
.sum-more { flex: none; min-height: 28px; padding: 0 10px; }
.sum-list { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 13px; align-items: baseline; }
.sum-row { display: contents; }
.sum-row dt { color: var(--muted); font-size: 12px; white-space: nowrap; }
.sum-row dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.sum-row code { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; background: var(--surface); padding: 0 5px; border-radius: 4px; }
.sum-row .drive { font-size: 13px; }
.sum-row .chip-btn { padding: 1px 9px; font-size: 12px; margin: 0 3px 3px 0; display: inline-flex; align-items: center; gap: 5px; }
.sum-row .chip-btn .flag { width: 16px; height: 11px; }
@media (max-width: 760px) {
      }
.pinfo-close { position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; font-size: 13px; z-index: 1; }
.pinfo:has(.pinfo-close) .sum-head { padding-right: 32px; }

/* 右パネル上段: 選んでいる国は黄、プレビューの吹き出しは青 */
.pinfo { transition: background .15s, box-shadow .15s; }
.pinfo.is-focused {
  background: color-mix(in srgb, #f5c400 13%, var(--surface));
  box-shadow: inset 4px 0 0 #f5c400;
}
/* ---------- 地図: プレビューの吹き出し（カーソル追尾） ---------- */
/* 外側は透明な入れ物。見た目は .hb-body が持つ（扇状のカードを本体の後ろに置くため） */
.hover-bubble {
  position: fixed; left: 0; top: 0; z-index: 3000; pointer-events: none;
  opacity: 0; visibility: hidden; transition: opacity .12s;
}
.hover-bubble.show { opacity: 1; visibility: visible; }
.hb-body {
  position: relative; z-index: 1; color: var(--text);
  background: color-mix(in srgb, #3b82f6 11%, var(--surface));
  border: 1px solid color-mix(in srgb, #3b82f6 45%, var(--border)); border-left: 4px solid color-mix(in srgb, #3b82f6 75%, transparent);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .28);
}
.hover-bubble.is-compact { width: max-content; max-width: 320px; }
.hb-compact { display: flex; align-items: center; gap: 7px; font-size: 13px; white-space: nowrap; padding: 5px 10px; }
.hb-compact .flag { width: 20px; height: 14px; }
.hb-n { font-size: 11px; color: var(--muted); }
.hover-bubble.is-full { width: 300px; }
/* 小さい表示から詳しい表示へ: カーソル側を起点に広がる */
.hover-bubble .hb-body { transform-origin: var(--origin, top left); }
.hover-bubble.anim-in .hb-body { animation: hb-expand .22s cubic-bezier(.2, .8, .25, 1) both; }
.hover-bubble.anim-out .hb-body { animation: hb-collapse .18s cubic-bezier(.2, .8, .25, 1) both; }
@keyframes hb-collapse { from { transform: scale(1.9); opacity: .25; } }
@keyframes hb-expand { from { transform: scale(.35); opacity: .2; } }
.hover-bubble.is-full .hb-body { padding: 12px 14px; }
.hover-bubble.has-fan { padding-top: 52px; }
@keyframes hb-grow { from { opacity: .4; } }
.hover-bubble .sum-more, .hover-bubble .ext-link { display: none; }
.hover-bubble .sum-row .chip-btn { pointer-events: none; }
.hover-bubble.has-fan .sum-head { padding-right: 120px; }
/* 扇状のカード: 下端より下を軸に回転させて広げ、下半分は本体に隠れる */
.hb-fan { position: absolute; top: 0; right: 40px; width: 110px; height: 60px; z-index: 0; }
.hb-card {
  position: absolute; left: 50%; top: 0; width: 56px; height: 62px; margin-left: -28px;
  border-radius: 6px; overflow: hidden; background: #0b0f12;
  border: 2px solid var(--cat, var(--border)); box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
  transform-origin: 50% 230%; transform: rotate(var(--a));
  animation: hb-fan-in .28s cubic-bezier(.2, .8, .25, 1.1) both;
}
.hb-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
@keyframes hb-fan-in { from { transform: rotate(0deg) translateY(16px); opacity: 0; } }
.hb-fan-more {
  position: absolute; right: -14px; top: 6px; z-index: 9; font-size: 11px; font-weight: 700;
  background: var(--surface); color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 0 6px;
}
.pinfo-close { right: 8px; }

/* お知らせはポップオーバー（最前面の層）。ブラウザ既定の popover の配置を打ち消す */
.toast[popover] { inset: auto; left: 50%; bottom: 24px; top: auto; margin: 0; border: 0; overflow: visible; }

/* ---------- 地図のサムネイル: 状態ごとの見え方 ---------- */
.map-thumbs { transition: transform .2s ease-out, opacity .2s; }
.map-thumbs.is-dim { opacity: .5; }
.map-thumbs.is-dim:hover { opacity: 1; }
.map-thumbs-more { user-select: none; }
.map-thumbs-more:hover { color: var(--accent); }
/* 「ほか N 枚」で広げたとき: 1 行 3 枚、長いときは欄の中でスクロール */
.map-thumbs.is-expanded .map-thumbs-grid { max-height: 210px; overflow-y: auto; overscroll-behavior: contain; padding: 2px; scrollbar-width: thin; }
.map-thumbs.is-expanded .map-thumbs-grid::-webkit-scrollbar { display: block; width: 6px; }
.map-thumbs.is-expanded .map-thumbs-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.map-thumbs.is-expanded .map-thumb:hover { transform: scale(1.06); }

/* ---------- 地図の右パネル: カードは 1 行 3 枚 ---------- */
.plist .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.plist .tile-body { padding: 6px 7px 8px; gap: 4px; }
.plist .tile .chip { font-size: 11px; padding: 1px 7px 1px 4px; }
.plist .tile .chip .flag { width: 15px; height: 10px; }
.plist .tile-desc { font-size: 11.5px; -webkit-line-clamp: 2; }
.plist .tile .cat-on-img { font-size: 10px; padding: 1px 6px; top: 4px; left: 4px; }

/* ---------- 国のメモ ---------- */
.cinfo-memo { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.memo-input { width: 100%; min-height: 72px; line-height: 1.7; background: color-mix(in srgb, #f5c400 6%, var(--surface)); }
.memo-view { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); line-height: 1.7; overflow-wrap: anywhere; }
.memo-status { font-weight: 400; margin-left: 6px; }
.sum-memo {
  margin-top: 8px; padding: 6px 9px; border-radius: 7px; font-size: 12.5px; line-height: 1.6;
  background: color-mix(in srgb, #f5c400 14%, var(--surface)); border-left: 3px solid #f5c400; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}

/* ---------- チャット形式のメモ（右下） ---------- */
.chat-fab {
  position: fixed; inset: auto 20px 20px auto; margin: 0; z-index: 4000;
  width: 54px; height: 54px; border-radius: 50%; border: 0; padding: 0;
  display: grid; place-items: center; cursor: pointer;
  background: var(--accent); color: var(--accent-text);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .3); transition: transform .15s, box-shadow .15s;
  overflow: visible;
}
.chat-fab:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 10px 24px rgba(0, 0, 0, .35); }
.chat-fab.active { transform: rotate(-8deg); }
.chat-fab[hidden] { display: none; }
.chat-badge { position: absolute; top: 2px; right: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--ng); border: 2px solid var(--surface); }
.chat-panel {
  position: fixed; inset: auto 20px 86px auto; margin: 0; z-index: 4000; padding: 0;
  width: min(380px, calc(100vw - 24px)); height: min(560px, calc(100vh - 120px)); height: min(560px, calc(100dvh - 120px));
  display: none; flex-direction: column; overflow: hidden;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
}
.chat-panel.open { display: flex; animation: chat-in .2s cubic-bezier(.2, .8, .25, 1.1) both; transform-origin: bottom right; }
@keyframes chat-in { from { opacity: 0; transform: translateY(12px) scale(.94); } }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--border); }
.chat-head b { font-size: 15px; }
.chat-count { font-size: 12px; margin-right: auto; }
.chat-list { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 12px 6px; background: var(--surface-2); display: flex; flex-direction: column; gap: 6px; overscroll-behavior: contain; }
.chat-empty { margin: auto; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.8; }
.chat-day { display: flex; justify-content: center; margin: 6px 0 2px; }
.chat-day span { font-size: 11px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 1px 10px; }
.chat-msg { display: flex; flex-direction: column; max-width: 86%; }
.chat-msg.mine { align-self: flex-end; align-items: flex-end; }
.chat-msg.other { align-self: flex-start; }
.chat-author { font-size: 11px; color: var(--muted); margin: 0 0 2px 4px; }
.chat-row { display: flex; align-items: flex-end; gap: 5px; }
.chat-msg.mine .chat-row { flex-direction: row-reverse; }
.chat-bubble {
  padding: 8px 12px; border-radius: 16px; line-height: 1.6; font-size: 14px; overflow-wrap: anywhere; white-space: normal;
  background: var(--surface); border: 1px solid var(--border);
}
.chat-msg.mine .chat-bubble { background: var(--accent); color: var(--accent-text); border-color: var(--accent); border-bottom-right-radius: 5px; }
.chat-msg.other .chat-bubble { border-bottom-left-radius: 5px; }
.chat-msg.mine .chat-bubble a { color: inherit; }
.chat-meta { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; color: var(--muted); flex: none; }
.chat-del { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 11px; width: 20px; height: 20px; border-radius: 50%; opacity: 0; transition: opacity .15s; }
.chat-msg:hover .chat-del, .chat-del:focus-visible { opacity: 1; }
.chat-del:hover { background: var(--ng-soft); color: var(--ng); }
@media (hover: none) { .chat-del { opacity: .6; } }
.chat-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.chat-input { flex: 1; min-height: 40px !important; max-height: 140px; resize: none; border-radius: 20px !important; padding: 9px 14px !important; line-height: 1.5; }
.chat-send { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text); cursor: pointer; display: grid; place-items: center; }
.chat-send:hover { filter: brightness(1.08); }
@media (max-width: 760px) {
  .chat-fab { inset: auto 14px 14px auto; width: 50px; height: 50px; }
  .chat-panel { inset: auto 8px 74px 8px; width: auto; height: min(70dvh, calc(100dvh - 90px)); }
  /* 暗記カード・クイズ（画面いっぱい）のときは、ボタンを少し小さく半透明に */
  .app-fit ~ .chat-fab { opacity: .85; }
}

.chat-me { border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); font: inherit; font-size: 12px; border-radius: 999px; padding: 2px 10px; cursor: pointer; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-me:hover { color: var(--text); border-color: var(--accent); }
