:root {
  color-scheme: dark;
  --bg: #0e1013;
  --surface: #16191e;
  --surface-subtle: #1c2026;
  --surface-hover: #242932;
  --surface-pass: #121519;
  --ink: #f1f3f5;
  --ink-secondary: #a6b0bd;
  --ink-muted: #7d8794;
  --border: #262b33;
  --border-strong: #39414e;
  --accent: #60a5fa;
  --accent-soft: #17253d;
  --pachi: #93c5fd;
  --pachi-soft: #152842;
  --pachi-border: #274875;
  --slot: #6ee7b7;
  --slot-soft: #122f26;
  --slot-border: #205745;
  --star: #f59e0b;
  --star-empty: #3d4554;
  --score-high: #f87171;
  --buy-bg: #33191d;
  --buy-fg: #fca5a5;
  --buy-border: #6b2b33;
  --consider-bg: #16253b;
  --consider-fg: #93c5fd;
  --consider-border: #284b78;
  --hold-bg: #2f2312;
  --hold-fg: #fcd34d;
  --hold-border: #664c1f;
  --pass-bg: #22262e;
  --pass-fg: #9ca3af;
  --pass-border: #3a414d;
  --danger: #f87171;
  --btn-invert-bg: #eef0f3;
  --btn-invert-fg: #0e1013;
  --btn-invert-hover: #ffffff;
  --radius-sm: 4px;
  --radius-md: 8px;
  --shadow-popover: 0 10px 28px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

::selection {
  background: #1e3a5f;
  color: var(--ink);
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans JP", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

::placeholder {
  color: var(--ink-muted);
  opacity: 1;
}

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

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

.ui-icon {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.ui-icon-xs {
  width: 13px;
  height: 13px;
}

.wrap {
  max-width: none;
  margin: 0 auto;
  padding: 0 clamp(12px, 2vw, 28px);
}

/* Sticky header + control bar */
.sticky-head {
  position: sticky;
  top: 0;
  z-index: 30;
  padding-top: env(safe-area-inset-top);
  background: rgba(14, 16, 19, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar {
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.app-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.month-nav {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.month-nav button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.month-step-btn {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.12s ease, color 0.12s ease;
}

@media (hover: hover) and (pointer: fine) {
  .month-step-btn:hover:not(:disabled) {
    background: var(--surface-hover);
    color: var(--ink);
  }

  .month-picker-btn:hover {
    background: var(--surface-hover);
  }
}

.month-step-btn:active:not(:disabled) {
  background: var(--surface-subtle);
  color: var(--ink);
}

.month-step-btn:disabled {
  color: var(--ink-muted);
  opacity: 0.25;
  cursor: not-allowed;
}

.month-picker-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  background: transparent;
  color: var(--ink);
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0 7px;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.12s ease;
}

.month-picker-btn:active {
  background: var(--surface-subtle);
}

.month-picker-btn.is-global {
  background: var(--surface-hover);
  color: var(--ink);
}

.topbar-right {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.auth-login-pill {
  background: var(--surface);
  color: var(--ink-secondary);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.auth-login-pill:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.account-wrap {
  position: relative;
}

.auth-avatar-btn {
  position: relative;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  padding: 0;
  background: var(--surface-hover);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.auth-avatar-btn:hover {
  border-color: var(--ink-secondary);
}

.auth-avatar-btn.auth-login-pill {
  width: auto;
  font-size: 13px;
  height: auto;
  padding: 5px 12px;
  border-radius: 999px;
}

.auth-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.auth-avatar-img[hidden],
.account-menu .menu-item[hidden] {
  display: none;
}

.auth-avatar-fallback {
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
}

.sync-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  background: var(--ink-muted);
}

.sync-dot[data-kind="saved"] {
  background: #22c55e;
}

.sync-dot[data-kind="saving"] {
  background: #f59e0b;
}

.sync-dot[data-kind="error"] {
  background: #ef4444;
}

.account-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 224px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-popover);
  padding: 12px;
  z-index: 40;
}

.account-name {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
}

.account-email {
  font-size: 13px;
  color: var(--ink-muted);
  word-break: break-all;
}

.account-sync {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-secondary);
}

.account-sync[data-kind="saved"] {
  color: #4ade80;
}

.account-sync[data-kind="saving"] {
  color: #fbbf24;
}

.account-sync[data-kind="error"] {
  color: var(--danger);
}

.account-note {
  max-width: 240px;
  color: var(--ink-muted);
  font-size: 13px;
  line-height: 1.5;
}

.menu-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0 6px;
}

.menu-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 7px 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.menu-item:hover {
  background: var(--surface-hover);
}

/* Main */
.main-content {
  padding-top: 12px;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

/* Control row & Accordion (inside sticky-head) */
.control-shell {
  padding: 7px 0;
}

.control-wrap {
  position: relative;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

.control-left {
  order: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  min-width: 0;
  flex: 1 1 auto;
}

.control-right {
  order: 2;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.control-search {
  order: 3;
  flex: 1 0 100%;
  display: none;
  padding-top: 6px;
}

.control-search.is-open {
  display: block;
}

.count-summary {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.control-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
}

.accordion-trigger {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

@media (hover: hover) and (pointer: fine) {
  .control-icon-btn:hover,
  .accordion-trigger:hover {
    background: var(--surface-hover);
    border-color: var(--border-strong);
  }
}

.control-icon-btn[aria-expanded="true"],
.accordion-trigger[aria-expanded="true"] {
  background: var(--btn-invert-bg);
  color: var(--btn-invert-fg);
  border-color: var(--btn-invert-bg);
}

.control-icon-btn.has-active,
.accordion-trigger.has-active {
  border-color: var(--ink-secondary);
  color: var(--ink);
}

.control-icon-btn[aria-expanded="true"].has-active,
.accordion-trigger[aria-expanded="true"].has-active {
  border-color: var(--btn-invert-bg);
  color: var(--btn-invert-fg);
}

.accordion-chevron {
  transition: transform 0.16s ease;
}

.accordion-trigger[aria-expanded="true"] .accordion-chevron {
  transform: rotate(180deg);
}

/* Browser-only install bar */
.install-shell {
  margin-bottom: 10px;
}

.install-shell:not(:has(.install-bar:not([hidden]), .install-guide:not([hidden]))) {
  margin-bottom: 0;
}

.install-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 4px 2px 2px;
}

.install-bar[hidden] {
  display: none;
}

.install-action {
  flex: 1;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 10px;
  border: none;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.install-action:hover {
  background: var(--surface-hover);
}

.install-dismiss {
  width: 28px;
  height: 28px;
}

.install-guide {
  margin-top: 6px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--ink-secondary);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.install-guide[hidden] {
  display: none;
}

.filter-panel {
  display: none;
  position: absolute;
  right: clamp(12px, 2vw, 28px);
  top: calc(100% + 10px);
  width: min(360px, calc(100% - 24px));
  max-height: calc(100dvh - 110px);
  overflow-y: auto;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-popover);
  flex-direction: column;
  gap: 10px;
  z-index: 40;
}

.filter-panel.is-open {
  display: flex;
}

.filter-panel-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tools-menu {
  position: absolute;
  right: clamp(12px, 2vw, 28px);
  top: calc(100% + 10px);
  width: min(340px, calc(100% - 24px));
  max-height: calc(100dvh - 110px);
  overflow-y: auto;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-popover);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 40;
}

.tools-menu[hidden] {
  display: none;
}

.tools-menu-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-muted);
}

.tools-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tools-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0;
}

.view-mode-seg {
  display: flex;
  width: 100%;
}

.view-mode-seg .seg-btn {
  flex: 1;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 10px;
}

.search-wrap {
  position: relative;
  width: 100%;
  min-width: 0;
}

.search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-muted);
  pointer-events: none;
}

.search-wrap input[type="search"] {
  width: 100%;
  height: 34px;
  padding: 0 28px 0 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
}

.search-wrap input[type="search"]:hover {
  border-color: var(--border-strong);
}

.search-wrap input[type="search"]:focus,
.search-wrap input[type="search"]:focus-visible {
  outline: none;
  border-color: var(--ink-muted);
  background: var(--bg);
}

.search-wrap input[type="search"]::-webkit-search-decoration,
.search-wrap input[type="search"]::-webkit-search-cancel-button,
.search-wrap input[type="search"]::-webkit-search-results-button,
.search-wrap input[type="search"]::-webkit-search-results-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

.search-clear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--ink-muted);
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.search-clear[hidden] {
  display: none;
}

.tools-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.external-links-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.external-tool-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-secondary);
  text-decoration: none;
}

.external-tool-link:hover {
  color: var(--ink);
  text-decoration: underline;
}

/* Buttons & segmented controls */
.btn,
.compact-select {
  height: 34px;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-hover);
}

.compact-select {
  height: 30px;
  padding: 0 8px;
  font-size: 13px;
  font-weight: 500;
  border-color: var(--border);
  background: var(--surface-subtle);
}

.compact-select:hover {
  border-color: var(--border-strong);
}

.compact-select:focus,
.compact-select:focus-visible,
.comment-input:focus,
.comment-input:focus-visible,
.memo-input:focus,
.memo-input:focus-visible,
.field input:focus,
.field input:focus-visible,
.field select:focus,
.field select:focus-visible {
  outline: none;
  border-color: var(--ink-muted);
}

.btn-primary {
  background: var(--btn-invert-bg);
  border-color: var(--btn-invert-bg);
  color: var(--btn-invert-fg);
}

.btn-primary:hover {
  background: var(--btn-invert-hover);
  border-color: var(--btn-invert-hover);
}

.btn-danger {
  color: var(--buy-fg);
  border-color: var(--buy-border);
  background: var(--buy-bg);
}

.btn-danger:hover {
  background: #462026;
}

.btn-sm {
  height: 30px;
  font-size: 13px;
  padding: 0 10px;
}

.btn.is-disabled,
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.seg-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}

.seg-btn {
  height: 30px;
  border: none;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--ink-secondary);
  font-size: 13px;
  font-weight: 600;
  padding: 0 10px;
  cursor: pointer;
}

.seg-btn:last-child {
  border-right: none;
}

.seg-btn:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.seg-btn.active {
  background: var(--btn-invert-bg);
  color: var(--btn-invert-fg);
}

/* Filter chips */
.stats-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-chip-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-row-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-secondary);
  margin-right: 2px;
  flex-shrink: 0;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.stat-pill b {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.stat-pill.zero {
  color: var(--ink-muted);
  background: transparent;
}

.stat-pill:hover {
  border-color: var(--border-strong);
}

.stat-pill.active {
  background: var(--btn-invert-bg);
  color: var(--btn-invert-fg);
  border-color: var(--btn-invert-bg);
}

.stat-pill.status-stat.st-buy.active {
  background: var(--buy-bg);
  border-color: var(--buy-fg);
  color: var(--buy-fg);
}

.stat-pill.status-stat.st-consider.active {
  background: var(--consider-bg);
  border-color: var(--consider-fg);
  color: var(--consider-fg);
}

.stat-pill.status-stat.st-hold.active {
  background: var(--hold-bg);
  border-color: var(--hold-fg);
  color: var(--hold-fg);
}

.stat-pill.status-stat.st-pass.active {
  background: var(--pass-bg);
  border-color: var(--pass-fg);
  color: var(--pass-fg);
}

/* Active filter chips bar */
.active-filters-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.active-filters-bar[hidden] {
  display: none;
}

.active-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  max-width: 100%;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.active-filter-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.active-filter-chip:hover {
  border-color: var(--ink-secondary);
}

.active-filter-chip.is-type-p {
  background: var(--pachi-soft);
  border-color: var(--pachi-border);
  color: var(--pachi);
}

.active-filter-chip.is-type-s {
  background: var(--slot-soft);
  border-color: var(--slot-border);
  color: var(--slot);
}

.active-filter-chip.st-buy {
  background: var(--buy-bg);
  border-color: var(--buy-border);
  color: var(--buy-fg);
}

.active-filter-chip.st-consider {
  background: var(--consider-bg);
  border-color: var(--consider-border);
  color: var(--consider-fg);
}

.active-filter-chip.st-hold {
  background: var(--hold-bg);
  border-color: var(--hold-border);
  color: var(--hold-fg);
}

.active-filter-chip.st-pass {
  background: var(--pass-bg);
  border-color: var(--pass-border);
  color: var(--pass-fg);
}

.active-filter-clear {
  height: 28px;
  padding: 0 6px;
  border: none;
  background: transparent;
  color: var(--ink-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.active-filter-clear:hover {
  color: var(--ink);
  text-decoration: underline;
}

/* Badges & identity */
.card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 700;
  background: var(--pachi-soft);
  color: var(--pachi);
  border: 1px solid var(--pachi-border);
}

.badge.slot {
  background: var(--slot-soft);
  color: var(--slot);
  border-color: var(--slot-border);
}

.maker {
  font-size: 13px;
  color: var(--ink-secondary);
  font-weight: 500;
}

.delivery-tag {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-secondary);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 0 5px;
  border-radius: 3px;
  line-height: 18px;
}

.custom-tag {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-secondary);
  background: var(--surface-hover);
  padding: 0 6px;
  border-radius: 3px;
  line-height: 20px;
}

.meta-link {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-secondary);
  text-decoration: none;
  padding: 0 4px;
  border-radius: 3px;
}

.meta-link:hover {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-secondary);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 6px;
  height: 20px;
  cursor: pointer;
}

.meta-pill:hover {
  border-color: var(--border-strong);
  color: var(--ink);
}

.machine-name {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--ink);
}

.machine-name.compact {
  font-size: 15px;
}

/* Fixed-height status tag & inline score */
.card-aside {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  height: 24px;
  flex-shrink: 0;
}

.score-inline {
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.score-inline.tier-high {
  color: var(--score-high);
}

.score-inline.tier-low {
  color: var(--ink-secondary);
}

.status-tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status-tag.st-buy {
  background: var(--buy-bg);
  color: var(--buy-fg);
  border-color: var(--buy-border);
}

.status-tag.st-consider {
  background: var(--consider-bg);
  color: var(--consider-fg);
  border-color: var(--consider-border);
}

.status-tag.st-hold {
  background: var(--hold-bg);
  color: var(--hold-fg);
  border-color: var(--hold-border);
}

.status-tag.st-pass {
  background: var(--pass-bg);
  color: var(--pass-fg);
  border-color: var(--pass-border);
}

/* Rating box (copy scope) */
.rating-panel {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
}

.rating-rows {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rating-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
}

.rating-label {
  width: 4.5em;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  flex-shrink: 0;
}

.star-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.star-btn {
  border: none;
  background: transparent;
  padding: 1px 2px;
  font-size: 22px;
  line-height: 1;
  color: var(--star-empty);
  cursor: pointer;
  border-radius: 3px;
}

.star-btn:hover {
  color: #fbbf24;
}

.star-btn.filled {
  color: var(--star);
}

.rating-num {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-secondary);
  min-width: 14px;
  text-align: right;
}

.overall-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.overall-star {
  display: inline-block;
  padding: 1px 2px;
  font-size: 22px;
  line-height: 1;
  color: var(--star-empty);
}

.overall-star.filled {
  color: var(--star);
}

.overall-value {
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.overall-bar.tier-high .overall-value {
  color: var(--score-high);
}

.overall-value:empty {
  display: none;
}

.comment-input {
  width: 100%;
  min-height: 54px;
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--ink);
  resize: vertical;
}

.rating-panel-footer {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.clear-rating-btn,
.copy-review-btn,
.image-review-btn {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--ink);
}

.clear-rating-btn:hover {
  background: var(--buy-bg);
  border-color: var(--buy-border);
  color: var(--buy-fg);
}

.copy-review-btn:hover,
.image-review-btn:hover {
  background: var(--btn-invert-bg);
  border-color: var(--btn-invert-bg);
  color: var(--btn-invert-fg);
}

/* Status bar (between overall score and comment) */
.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.status-caption {
  color: var(--ink);
}

.status-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.status-pill {
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--ink-secondary);
  cursor: pointer;
}

.status-pill:hover {
  border-color: var(--border-strong);
  color: var(--ink);
}

.status-pill.st-buy.active {
  background: var(--buy-bg);
  border-color: var(--buy-fg);
  color: var(--buy-fg);
}

.status-pill.st-consider.active {
  background: var(--consider-bg);
  border-color: var(--consider-fg);
  color: var(--consider-fg);
}

.status-pill.st-hold.active {
  background: var(--hold-bg);
  border-color: var(--hold-fg);
  color: var(--hold-fg);
}

.status-pill.st-pass.active {
  background: var(--pass-bg);
  border-color: var(--pass-fg);
  color: var(--pass-fg);
}

/* Card view */
.machine-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr));
  gap: 14px;
  align-items: start;
}

@media (min-width: 840px) {
  .install-shell {
    display: none;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.card.is-selectable {
  cursor: pointer;
  user-select: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.card.is-selectable:hover {
  border-color: var(--border-strong);
}

.card.is-selectable.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.card.is-selectable > * {
  pointer-events: none;
}

.select-circle {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: var(--bg);
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  color: transparent;
}

.select-circle.checked {
  background: var(--accent);
  border-color: var(--accent);
  color: #0e1013;
}

.card.st-pass {
  background: var(--surface-pass);
}

.card.st-pass .machine-name {
  color: var(--ink-secondary);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.card-identity {
  min-width: 0;
  flex: 1;
}

/* Compact list mode */
.machine-list.is-compact {
  gap: 8px;
}

.card.is-compact {
  padding: 10px 12px;
}

.card.is-compact:not(.is-expanded):not(.is-selectable) {
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}

.card.is-compact:not(.is-expanded):not(.is-selectable):hover {
  border-color: var(--border-strong);
  background: var(--surface-subtle);
}

.card.is-compact .card-head {
  margin-bottom: 0;
  gap: 8px;
  cursor: pointer;
}

.card.is-compact.is-expanded .card-head {
  margin-bottom: 12px;
}

.card.is-compact .card-meta {
  gap: 5px;
  margin-bottom: 3px;
}

.card.is-compact .machine-name {
  font-size: 15px;
  line-height: 1.35;
}

.card.is-compact .card-aside {
  gap: 6px;
  height: 22px;
}

.card.is-compact .score-inline {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 16px;
}

.score-star {
  color: var(--star);
  font-size: 14px;
  line-height: 1;
}

.meta-note-dot {
  display: inline-flex;
  align-items: center;
  color: var(--ink-muted);
}

.compact-toggle-btn {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  flex-shrink: 0;
}

.compact-toggle-btn:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.compact-toggle-btn .ui-icon {
  transition: transform 0.16s ease;
}

.card.is-expanded .compact-toggle-btn .ui-icon {
  transform: rotate(180deg);
}

.compact-snippet {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--ink-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.compact-snippet.is-memo {
  color: var(--ink-muted);
}

.memoline {
  display: block;
  width: 100%;
  text-align: left;
  margin-top: 12px;
  padding: 9px 11px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.memoline > span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.memoline:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.memoline.empty {
  color: var(--ink-muted);
}

/* Inline memo editor */
.editor {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.memo-input {
  width: 100%;
  min-height: 96px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--ink);
  resize: vertical;
}

.file-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 14px;
}

.file-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  text-decoration: none;
  min-width: 0;
  overflow: hidden;
}

.file-link:hover {
  color: var(--accent);
}

.file-link:hover .file-name {
  text-decoration: underline;
}

.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.upload-error {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--buy-bg);
  border: 1px solid var(--buy-border);
  color: var(--buy-fg);
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}

.upload-error a {
  display: inline-block;
  margin-top: 4px;
  color: var(--accent);
  font-weight: 600;
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.btn-close-editor {
  margin-left: auto;
  background: var(--btn-invert-bg);
  color: var(--btn-invert-fg);
  border-color: var(--btn-invert-bg);
}

.btn-close-editor:hover {
  background: var(--btn-invert-hover);
}

.editor-hint {
  margin-top: 6px;
  font-size: 13px;
  color: var(--ink-muted);
}

/* Empty & footer */
.empty-state {
  text-align: center;
  padding: 40px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--ink-secondary);
}

.legend {
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--ink-muted);
}

.legend p {
  margin: 4px 0;
}

/* Modal */
.modal {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 20px;
  max-width: 440px;
  width: 92vw;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-popover);
}

.modal-sm {
  max-width: 340px;
}

.confirm-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}

.confirm-sub {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--ink-secondary);
  word-break: break-word;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.68);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.field {
  display: block;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 600;
}

.field .req {
  color: var(--danger);
  font-style: normal;
}

.field input,
.field select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  font-weight: 400;
}

.form-error {
  color: var(--buy-fg);
  background: var(--buy-bg);
  border: 1px solid var(--buy-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  margin-bottom: 10px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.modal-lg {
  max-width: 780px;
}

.json-dialog-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.json-dialog-actions .btn {
  width: 100%;
  justify-content: center;
}

/* Month drum wheel picker */
.modal-picker {
  padding: 18px 20px 20px;
}

.wheel-headings {
  display: grid;
  grid-template-columns: 1fr 24px 1fr;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}

.wheel-stage {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 24px 1fr;
  height: 200px;
  margin-top: 4px;
  user-select: none;
  overflow: hidden;
}

.wheel-highlight {
  position: absolute;
  left: 0;
  right: 0;
  top: 80px;
  height: 40px;
  background: var(--surface-hover);
  border-top: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  pointer-events: none;
  display: grid;
  place-items: center;
  z-index: 1;
}

.wheel-slash {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink-secondary);
  line-height: 1;
}

.wheel-col {
  position: relative;
  z-index: 2;
  height: 200px;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: none;
  cursor: grab;
}

.wheel-col::-webkit-scrollbar {
  display: none;
}

.wheel-col.is-dragging {
  scroll-snap-type: none;
  cursor: grabbing;
}

.wheel-col:focus-visible {
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}

#monthPickerYearCol {
  grid-column: 1;
}

#monthPickerMonthCol {
  grid-column: 3;
}

.wheel-list {
  padding: 80px 0;
}

.wheel-item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 40px;
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  font-size: 19px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  scroll-snap-align: center;
  cursor: pointer;
  padding: 0;
  will-change: transform, opacity;
}

.wheel-item.is-active {
  color: var(--ink);
  font-weight: 700;
}

.wheel-fade {
  position: absolute;
  left: 0;
  right: 0;
  height: 68px;
  z-index: 3;
  pointer-events: none;
}

.wheel-fade-top {
  top: 0;
  background: linear-gradient(to bottom, var(--surface) 10%, rgba(22, 25, 30, 0));
}

.wheel-fade-bottom {
  bottom: 0;
  background: linear-gradient(to top, var(--surface) 10%, rgba(22, 25, 30, 0));
}

.wheel-preview {
  margin-top: 12px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-secondary);
  font-variant-numeric: tabular-nums;
  min-height: 18px;
}

.wheel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
}

.wheel-footer-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

#imageExportDlg {
  padding-top: 12px;
}

#imageExportDlg .modal-head {
  position: sticky;
  top: 0;
  z-index: 1;
  margin-bottom: 4px;
  background: var(--surface);
}

#imageExportClose {
  width: 44px;
  height: 44px;
  flex: none;
}

.image-preset-row {
  display: flex;
  margin-top: 10px;
}

.image-export-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.image-export-toolbar:empty {
  display: none;
}

.image-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  margin-top: 14px;
  max-height: 55dvh;
  overflow-y: auto;
  padding-right: 2px;
}

.image-preview-grid.is-single {
  grid-template-columns: minmax(0, 1fr);
}

.image-preview-grid.is-single .image-preview-thumb {
  width: auto;
  max-width: 100%;
  max-height: 46dvh;
  margin: 0 auto;
}

.image-preview-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.image-preview-thumb {
  width: 100%;
  height: auto;
  border-radius: 4px;
  display: block;
}

.image-preview-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

/* Fixed bottom selection bar */
body.is-selecting .main-content {
  padding-bottom: calc(104px + env(safe-area-inset-bottom));
}

body.is-selecting .toast {
  bottom: calc(82px + env(safe-area-inset-bottom));
}

.selection-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 45;
  background: rgba(22, 25, 30, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border-strong);
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.45);
}

.selection-bar[hidden] {
  display: none;
}

.selection-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.selection-bar-info,
.selection-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.selection-mode-badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--pachi-border);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.selection-count {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--btn-invert-bg);
  color: var(--btn-invert-fg);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-popover);
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* Responsive */
@media (min-width: 1024px) {
  .control-row {
    flex-wrap: nowrap;
    gap: 10px;
  }

  .control-left {
    order: 0;
    flex: 0 0 auto;
  }

  .control-search {
    display: block;
    order: 0;
    flex: 1 1 200px;
    max-width: 380px;
    min-width: 160px;
    padding-top: 0;
  }

  .search-wrap input[type="search"] {
    height: 32px;
    font-size: 14px;
  }

  .filter-panel {
    display: flex;
    order: 0;
    position: static;
    width: auto;
    max-height: none;
    overflow: visible;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .filter-panel .filter-row-label {
    display: none;
  }

  .filter-panel .stats-bar {
    flex-direction: row;
    align-items: center;
  }

  .filter-panel .filter-chip-group {
    flex-wrap: nowrap;
    gap: 4px;
  }

  .filter-panel .compact-select {
    height: 32px;
    font-size: 13px;
    padding: 0 8px;
  }

  .filter-panel .stat-pill {
    height: 32px;
    padding: 0 8px;
  }

  .search-toggle-btn,
  .filter-toggle-btn {
    display: none;
  }

  .control-right {
    order: 0;
    margin-left: auto;
  }
}

@media (max-width: 1023px) {
  .comment-input,
  .memo-input,
  .field input,
  .field select {
    font-size: 15px;
  }
}

@media (max-width: 600px) {
  .wrap {
    padding: 0 12px;
  }

  .topbar-inner {
    gap: 6px;
  }

  .topbar-left {
    gap: 6px;
  }

  .app-title {
    font-size: 14px;
  }

  .month-nav {
    gap: 1px;
  }

  .month-step-btn {
    width: 25px;
    height: 30px;
  }

  .month-picker-btn {
    height: 30px;
    padding: 0 6px;
    font-size: 14px;
  }

  .auth-login-pill {
    padding: 4px 9px;
    font-size: 12px;
  }

  .control-row,
  .control-left {
    gap: 4px;
  }

  .seg-btn {
    padding: 0 6px;
  }

  .count-summary {
    font-size: 12px;
  }

  .control-icon-btn {
    width: 30px;
    height: 30px;
  }

  .accordion-trigger {
    height: 30px;
    padding: 0 7px;
    gap: 3px;
    font-size: 12px;
  }

  .accordion-trigger .accordion-chevron {
    display: none;
  }

  .card {
    padding: 14px;
  }

  .card.is-compact {
    padding: 9px 11px;
  }

  .star-btn,
  .overall-star {
    font-size: 24px;
    padding: 2px 3px;
  }

  .modal-picker {
    margin: auto 0 0 0;
    width: 100%;
    max-width: none;
    border-radius: 16px 16px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
}
