/* ============================================================
   app-ui.css — standaloneアプリ共通デザインシステム
   DESIGN.md (Google Minimal) 準拠。
   対象: mplay / ncs / oiia / bin-magic / ezypy 他
   旧BeerCSSのクラス名をそのまま受け付ける互換レイヤー。
   JSの変更なしでUIだけ載せ替えるためのCSS。
   ============================================================ */

:root {
  --color-primary: #0b57d0;
  --color-secondary: #3c4043;
  --color-tertiary: #5f6368;
  --color-neutral: #1f1f1f;
  --color-surface: #ffffff;
  --color-surface-2: #f8f9fa;
  --color-border: #e5e7eb;
  --color-on-surface: #1f1f1f;
  --color-on-primary: #ffffff;
  --color-link: #1a0dab;
  --color-error: #d93025;

  --font-app: 'Roboto', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "Hiragino Kaku Gothic ProN", "Hiragino Sans",
    "Noto Sans JP", sans-serif;
  --font-label: 'Google Sans', 'Product Sans', 'Roboto', ui-sans-serif, system-ui,
    -apple-system, "Segoe UI", "Noto Sans JP", sans-serif;

  --radius-buttons: 9999px;
  --radius-cards: 8px;
  --radius-nested: 8px;
  --radius-small: 4px;
  --radius-xl: 20px;

  --shadow-subtle: none;

  /* Legacy aliases */
  --color-canvas: var(--color-surface);
  --color-paper: var(--color-surface);
  --color-surface-alt: var(--color-surface-2);
  --color-ink: var(--color-on-surface);
  --color-ink-soft: var(--color-secondary);
  --color-mid-gray: var(--color-tertiary);
  --color-hairline: var(--color-border);
  --color-ember: var(--color-error);
}

/* Dark mode — approximate inversion (light-first per DESIGN.md) */
html.dark {
  --color-primary: #7cacf8;
  --color-secondary: #e3e3e3;
  --color-tertiary: #9aa0a6;
  --color-neutral: #e8eaed;
  --color-surface: #1f1f1f;
  --color-surface-2: #2a2e33;
  --color-border: #3c4043;
  --color-on-surface: #e8eaed;
  --color-on-primary: #062e6f;
  --color-link: #8ab4f8;
  --color-error: #f28b82;

  --shadow-subtle: none;

  --color-canvas: var(--color-surface);
  --color-paper: #202124;
  --color-surface-alt: var(--color-surface-2);
  --color-ink: var(--color-on-surface);
  --color-ink-soft: var(--color-secondary);
  --color-mid-gray: var(--color-tertiary);
  --color-hairline: var(--color-border);
  --color-ember: var(--color-error);
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

html {
  -webkit-text-size-adjust: 100%;
  color-scheme: light;
}
html.dark { color-scheme: dark; }

body {
  margin: 0;
  padding: 0;
  background: var(--color-surface);
  color: var(--color-on-surface);
  font-family: var(--font-app);
  font-size: 14px;
  line-height: 20px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

body:has(> main) > main,
body:has(> main) > main.max { flex: 1 0 auto; width: 100%; }
body:has(> main) > footer { margin-top: auto; }

h1, h2, h3, h4, h5, h6 { margin: 0; }
h1 { font-size: 32px; line-height: 38px; font-weight: 700; letter-spacing: 0; }
h3 { font-size: 20px; line-height: 24px; font-weight: 600; letter-spacing: 0; }
h5 { font-size: 18px; line-height: 22px; font-weight: 600; }
h6 { font-size: 16px; line-height: 1.5; }
h6.small { font-size: 14px; font-weight: 500; font-family: var(--font-label); }
p { margin: 0; }
a { color: var(--color-link); }
img { max-width: 100%; }
::selection { background: var(--color-primary); color: var(--color-on-primary); }

:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
[hidden] { display: none !important; }
.hide { display: none !important; }

/* Material Symbols (outlined, thin) */
i {
  font-family: 'Material Symbols Outlined';
  font-weight: 400;
  font-style: normal;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  user-select: none;
  overflow: hidden;
  flex: none;
}
i.extra { font-size: 44px; }

/* ---------- layout utils ---------- */
main.responsive {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}
main.responsive.max { max-width: 1280px; }

.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.no-wrap { flex-wrap: nowrap !important; }
.max { flex: 1 1 auto; min-width: 0; }
.middle-align { align-items: center; }
.center-align { text-align: center; }
nav.center-align, div.center-align.row { display: flex; justify-content: center; align-items: center; gap: 8px; }
.text-small, small.small, p.small { font-size: 12px; }
p.large { font-size: 16px; line-height: 1.5; }
.helper { display: block; font-size: 12px; color: var(--color-tertiary); margin-top: 4px; }
.padding { padding: 16px; }
.padding-horizontal { padding-left: 16px; padding-right: 16px; }
.padding-bottom { padding-bottom: 16px; }
.small-padding { padding: 12px 16px; }
.small-space { gap: 8px; }
div.space { height: 16px; min-height:16px; }
.no-margin { margin: 0 !important; }
.no-padding { padding: 0 !important; }
.no-round { border-radius: 0 !important; }
.bottom-round { border-radius: 0 0 var(--radius-cards) var(--radius-cards) !important; }
img.responsive { width: 100%; height: auto; display: block; }
img.round { border-radius: var(--radius-buttons); }
img.small-width { max-width: 340px; margin-inline: auto; }
.primary-text { color: var(--color-on-surface); }
.error-text { color: var(--color-error); }
.large-height { min-height: 56vh; }

/* grid (12-col) */
.grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.grid.space { gap: 16px; }
.s12 { grid-column: span 1; }
@media (min-width: 600px) {
  .grid { grid-template-columns: repeat(12, 1fr); }
  .s12 { grid-column: span 12; }
  .m6 { grid-column: span 6; }
}
@media (min-width: 1024px) {
  .l6 { grid-column: span 6; }
}

/* page screens (bin-magic) */
.page { display: none; }
.page.active { display: block; }

/* ---------- header: flat white utility bar ---------- */
header.fixed, header.primary-container, dialog header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
header.fixed, header.primary-container {
  position: sticky;
  top: 0;
  z-index: 50;
}
header nav {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 12px;
  min-height: 60px;
}
header nav h5, header nav h6 { font-size: 18px; letter-spacing: 0; }

/* ---------- shared brand ---------- */
[data-brand-slot] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  flex: none;
}
.apphdr-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 40px;
  min-height: 40px;
  padding: 0 6px;
  border-radius: var(--radius-buttons);
  text-decoration: none;
  font-family: var(--font-label);
  font-weight: 500;
  font-size: 14px;
  line-height: 20px;
  color: var(--color-neutral);
}
.apphdr-brand:hover { background: var(--color-surface-2); }
.apphdr-brand img { width: 28px; height: 28px; border-radius: 50%; display: block; }
@media (max-width: 719.98px) {
  .apphdr-brand span { display: none; }
}
header.viz-header .apphdr-brand { color: #fff; }
header.viz-header .apphdr-brand:hover { background: rgba(255, 255, 255, 0.12); }

/* ---------- buttons: full pill, single blue accent ---------- */
button, .button, label.button {
  font-family: var(--font-label);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 10px 12px;
  border-radius: var(--radius-buttons);
  border: 1px solid transparent;
  background: var(--color-surface-2);
  color: var(--color-secondary);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
label.button { cursor: pointer; }
button:hover, .button:hover, label.button:hover { background: #f1f3f4; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button i, .button i, label.button i { font-size: 20px; }

button.primary, .button.primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-on-primary);
}
button.primary:hover, .button.primary:hover { background: #0a4ebe; border-color: #0a4ebe; }
button.fill { background: var(--color-surface-2); color: var(--color-secondary); }
button.transparent, a.transparent { background: transparent; color: var(--color-neutral); }
button.transparent:hover, a.transparent:hover { background: var(--color-surface-2); }
button.small { min-height: 32px; padding: 4px 12px; font-size: 13px; }
button.border { background: transparent; border-color: var(--color-border); color: var(--color-neutral); }
button.border:hover { background: var(--color-surface-2); }

button.circle, a.circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px; min-height: 0; padding: 0;
  border-radius: 50%;
  line-height: 1;
}
a.circle i { display: inline-flex; align-items: center; justify-content: center; line-height: 1; }
button.circle.fill { background: var(--color-surface-2); }
button.circle.fill.active { background: var(--color-primary); color: var(--color-on-primary); }
button.square.round.extra {
  width: 64px; height: 64px; min-height: 0; padding: 0;
  border-radius: var(--radius-xl);
}
button.square.round.extra.primary i { font-size: 32px; }

button.error.text { background: transparent; color: var(--color-error); }
button.error.text:hover { background: var(--color-surface-2); }

button.round, a.round { border-radius: var(--radius-buttons); }

/* bin-magic: カード画像と回答UIのずれ解消 (スコープ限定) */
#screen-card .card-layout { align-items: center; }
#screen-card .card-media { display: flex; justify-content: center; }
#screen-card #card-image {
  width: 100%;
  max-width: 340px;
  height: auto;
  aspect-ratio: 3 / 4;
  object-fit: contain;
  background: var(--color-surface-2);
  margin-inline: auto;
}
#screen-card .card-answer {
  display: grid;
  gap: 12px;
  justify-items: center;
  align-content: center;
  text-align: center;
  padding: 16px;
}
#screen-card .answer-row { display: flex; justify-content: center; align-items: center; gap: 8px; flex-wrap: wrap; }

/* segmented group */
nav.group { display: inline-flex; max-width: 100%; }
nav.group button { border-radius: 0; min-width: 0; }
nav.group button:first-child, button.left-round {
  border-radius: var(--radius-buttons) 0 0 var(--radius-buttons) !important;
}
nav.group button:last-child, button.right-round {
  border-radius: 0 var(--radius-buttons) var(--radius-buttons) 0 !important;
}
nav.group:has(> button:only-child) { display: flex; }
nav.group button:only-child {
  border-radius: var(--radius-buttons) !important;
  flex: 1 1 auto;
  white-space: normal;
  text-align: center;
}

/* ---------- cards / article: white, 8px, flat ---------- */
article {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-cards);
  box-shadow: none;
  padding: 16px;
  margin-bottom: 16px;
}
article.elevate { box-shadow: none; }
article.no-padding { padding: 0; overflow: hidden; }
article.middle-align { display: flex; flex-direction: column; justify-content: center; }
article .padding { padding: 16px; }

/* ---------- footer ---------- */
footer { margin-top: 40px; }
footer.center-align, footer.secondary-container {
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: 24px 20px;
  text-align: center;
}
footer nav { display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
footer nav a { color: var(--color-tertiary); text-decoration: none; font-size: 14px; padding: 6px 10px; border-radius: var(--radius-buttons); }
footer nav a:hover { color: var(--color-neutral); background: var(--color-surface-2); }

/* ---------- standalone footer ---------- */
body > footer {
  margin-top: auto;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: 16px 20px calc(16px + env(safe-area-inset-bottom, 0px));
  font-size: 12px;
  color: var(--color-tertiary);
}
body > footer nav { display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
body > footer nav a {
  color: var(--color-tertiary); text-decoration: none;
  padding: 6px 10px; border-radius: var(--radius-buttons);
}
body > footer nav a:hover { color: var(--color-neutral); background: var(--color-surface-2); }

/* ---------- lists ---------- */
ul.list { list-style: none; margin: 0; padding: 8px; }
ul.list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-nested);
  cursor: default;
}
ul.list li + li { border-top: 1px solid var(--color-border); border-radius: 0; }
ul.list li:first-child { border-top: none; }
#jump-list li, #cache-list li, #fileListPreview li { cursor: pointer; }
#jump-list li:hover, #cache-list li:hover { background: var(--color-surface-2); }
li.active { background: var(--color-surface-2); }
li.search-hidden { display: none !important; }
.info-div { font-size: 12px; color: var(--color-tertiary); margin-top: 2px; }
mark.highlight, .highlight { background: var(--color-surface-2); border-radius: var(--radius-small); font-weight: 600; }

/* ---------- fields / inputs: white pill, 52px ---------- */
.field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-buttons);
  padding: 0 16px;
  min-height: 52px;
}
.field input[type="search"], .field input[type="text"] {
  flex: 1; min-width: 0;
  border: none; background: transparent;
  font-family: var(--font-app); font-size: 14px; color: var(--color-on-surface);
  outline: none;
}
.field input::placeholder { color: var(--color-tertiary); }
.field i { color: var(--color-tertiary); }
.field:focus-within { border-color: var(--color-primary); }
.field > nav { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; }

nav.right-align { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }

.rename-input {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-buttons);
  background: var(--color-surface);
  color: var(--color-on-surface);
  outline: none;
}
.rename-input:focus { border-color: var(--color-primary); }

/* ---------- sliders ---------- */
.slider { display: flex; align-items: center; gap: 8px; }
.slider.medium { margin-block: 4px; }
.slider input[type="range"] {
  flex: 1; min-width: 0;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--color-border);
  outline: none;
  cursor: pointer;
}
.slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--color-primary);
  border: none;
}
.slider input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--color-primary);
  border: none;
}
.slider input[type="range"]::-moz-range-track {
  height: 4px; border-radius: 2px; background: var(--color-border);
}
.slider > span { display: inline-flex; align-items: center; color: var(--color-tertiary); }
.slider > span:empty { display: none; }

/* ---------- dialogs ---------- */
dialog {
  display: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-cards);
  box-shadow: none;
  background: var(--color-surface);
  color: var(--color-on-surface);
  padding: 0;
  width: min(92vw, 80ch);
  max-height: 86vh;
  overflow: auto;
}
dialog[open] { display: block; }
dialog.pad { padding: 16px; }
dialog.active {
  display: block;
  position: fixed;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  z-index: 60;
  margin: 0;
}
@media (max-width: 1000px) { dialog.active { width: min(92vw, 50ch); } }
@media (max-width: 600px) { dialog.active { width: min(94vw, 30ch); } }
body:has(dialog.active)::before {
  content: "";
  position: fixed; inset: 0;
  background: rgba(31, 31, 31, 0.32);
  z-index: 55;
}
dialog header { position: sticky; top: 0; }
dialog footer { border-top: 1px solid var(--color-border); padding: 12px 16px; margin: 0; background: transparent; display: flex; justify-content: flex-end; }
hr.medium { border: none; border-top: 1px solid var(--color-border); margin: 16px 0; }

dialog > * + * { margin-top: 12px; }
dialog > .row,
dialog > nav.group,
dialog > hr.medium { margin-inline: 16px; }
dialog > nav.group:last-child,
dialog > .row:last-child { margin-bottom: 16px; }
dialog > ul.list {
  margin: 0 12px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-nested);
}
.border { border: 1px solid var(--color-border); }

/* ---------- dropdown menu ---------- */
div:has(> menu) { position: relative; }
menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px); right: 0;
  z-index: 70;
  min-width: 200px;
  margin: 0; padding: 8px;
  list-style: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-cards);
  box-shadow: none;
}
menu li { margin: 0; padding: 0; list-style: none; }
menu button.fill { width: 100%; justify-content: flex-start; background: transparent; }
menu button.fill:hover { background: var(--color-surface-2); }
div:has(> menu):hover > menu,
div:has(> menu):focus-within > menu,
menu.active { display: block; }

/* ---------- snackbar (DESIGN.md: neutral pill, label type, no shadow) ---------- */
.snackbar-container { position: fixed; bottom: 24px; right: 24px; z-index: 100; }
.snackbar {
  display: flex; align-items: center; gap: 8px;
  min-height: 40px;
  background: var(--color-neutral);
  color: var(--color-surface);
  border: 1px solid transparent;
  border-radius: var(--radius-cards);
  padding: 10px 12px;
  font-family: var(--font-label);
  font-size: 14px; font-weight: 500; line-height: 20px;
  box-shadow: none;
  opacity: 0; pointer-events: none;
  transform: translateY(8px);
  transition: opacity 150ms ease, transform 150ms ease;
  max-width: min(92vw, 480px);
}
.snackbar.active { opacity: 1; transform: translateY(0); }
.snackbar.error { background: var(--color-error); color: #fff; }
.snackbar .max { display: flex; align-items: center; gap: 8px; min-width: 0; }
.snackbar i { font-size: 20px; }
div.snackbar { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(8px); z-index: 100; }
div.snackbar.active { transform: translateX(-50%) translateY(0); }

/* ---------- misc components ---------- */
#dropArea {
  border: 1px dashed var(--color-tertiary) !important;
  border-radius: var(--radius-cards) !important;
  background: var(--color-surface-2);
}

.chip {
  display: inline-flex; align-items: center;
  padding: 8px 12px;
  border-radius: var(--radius-buttons);
  font-family: var(--font-app);
  font-size: 12px; font-weight: 500; line-height: 16px;
  border: 1px solid transparent;
  background: var(--color-surface-2);
  color: var(--color-secondary);
  min-height: 0;
}
.chip.ready { background: var(--color-primary); color: var(--color-on-primary); }
.chip.error { background: transparent; color: var(--color-error); border-color: var(--color-error); }

label.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
label.switch input { opacity: 0; width: 0; height: 0; }
label.switch span {
  position: absolute; inset: 0;
  background: var(--color-border);
  border-radius: 999px;
  transition: background 150ms ease;
}
label.switch span::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--color-surface);
  box-shadow: none;
  border: 1px solid var(--color-border);
  transition: transform 150ms ease;
}
label.switch input:checked + span { background: var(--color-primary); }
label.switch input:checked + span::after { transform: translateX(18px); background: #fff; border-color: transparent; }

.overlay { display: none; }
.overlay.active { display: block; position: fixed; inset: 0; z-index: 50; background: rgba(31, 31, 31, 0.32); }
