:root {
  --shell: #c8362e;
  --shell-deep: #9e2820;
  --shell-edge: #e05a4e;
  --screen: #17130f;
  --screen-cell: #221c16;
  --screen-cell-line: #322a22;
  --ink-lcd: #f4e9d8;
  --ink-lcd-dim: #b7a88f;
  --ink-lcd-faint: #6e6353;
  --amber: #f5c518;
  --led-blue: #7ec8e3;
  --led-green: #7fd68a;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--shell-deep);
}

body {
  min-width: 0;
  margin: 0;
  background: var(--shell-deep);
  color: var(--ink-lcd);
  font-family: "PingFang SC", "Hiragino Sans GB", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.device {
  width: min(calc(100% - 32px), 1080px);
  margin: 24px auto 48px;
  padding: 22px 22px 26px;
  overflow: hidden;
  background: linear-gradient(
    175deg,
    var(--shell-edge),
    var(--shell) 18%,
    var(--shell) 82%,
    var(--shell-deep)
  );
  border-radius: 26px;
  box-shadow: 0 14px 40px rgb(0 0 0 / 45%);
}

header {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 18px;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

.lens {
  width: 44px;
  height: 44px;
  flex: none;
  background: radial-gradient(circle at 35% 30%, #cfefff, var(--led-blue) 45%, #2b7fa8 80%);
  border: 4px solid rgb(255 255 255 / 20%);
  border-radius: 50%;
  box-shadow: 0 2px 6px rgb(0 0 0 / 40%);
}

.leds {
  display: flex;
  flex: none;
  gap: 7px;
}

.led {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  box-shadow: inset 0 -1px 2px rgb(0 0 0 / 40%);
}

.led-amber { background: var(--amber); }
.led-green { background: var(--led-green); }
.led-blue { background: var(--led-blue); }

h1 {
  margin: 0;
  color: #fff;
  font-size: 22px;
  letter-spacing: 0.14em;
  text-shadow: 0 1px 0 rgb(0 0 0 / 35%);
}

.h-sub {
  color: #ffd9d4;
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.lcd {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: var(--screen);
  border: 3px solid rgb(0 0 0 / 33%);
  border-radius: 14px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.lcd .num {
  color: var(--amber);
  font-size: 30px;
  font-variant-numeric: tabular-nums;
}

.lcd .num small {
  color: var(--ink-lcd-dim);
  font-size: 14px;
}

.meter {
  display: flex;
  flex: 1 1 160px;
  height: 12px;
  gap: 2px;
  padding: 2px;
  overflow: hidden;
  background: var(--screen-cell);
  border-radius: 3px;
}

.meter i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--amber);
  border-radius: 1px;
  transition: width 0.3s steps(12);
}

.lcd .pct {
  color: var(--ink-lcd-dim);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tab-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.actions {
  display: flex;
  flex: none;
  gap: 8px;
}

.action-button {
  min-height: 44px;
  padding: 7px 13px;
  border: 1px solid rgb(255 255 255 / 28%);
  border-radius: 8px;
  background: rgb(84 20 16 / 48%);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}

.action-button.primary { background: var(--amber); color: #4a3000; }
.action-button:disabled { cursor: wait; opacity: 0.62; }
.action-button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.tab {
  min-height: 44px;
  padding: 7px 18px;
  border: 1px solid rgb(0 0 0 / 20%);
  border-radius: 8px;
  background: var(--shell-deep);
  box-shadow: inset 0 -2px 0 rgb(0 0 0 / 25%);
  color: #ffd9d4;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  letter-spacing: 0.08em;
}

.tab[aria-pressed="true"] {
  background: var(--amber);
  box-shadow: inset 0 -2px 0 rgb(0 0 0 / 15%);
  color: #4a3000;
}

.tab:disabled {
  cursor: wait;
  opacity: 0.72;
}

.tab:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.tab .n {
  margin-left: 5px;
  opacity: 0.8;
  font-variant-numeric: tabular-nums;
}

.screen {
  min-width: 0;
  padding: 14px;
  background: var(--screen);
  border: 3px solid rgb(0 0 0 / 33%);
  border-radius: 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}

.card {
  position: relative;
  min-width: 0;
  min-height: 112px;
  padding: 8px 4px 9px;
  border: 1px solid var(--screen-cell-line);
  border-radius: 8px;
  background: var(--screen-cell);
  color: inherit;
  cursor: default;
  font: inherit;
  text-align: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card:hover {
  border-color: var(--screen-cell-line);
}

.editing .card { cursor: pointer; }
.editing .card:hover { border-color: var(--amber); }

.card:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}

.card img {
  display: block;
  width: 68px;
  height: 68px;
  margin: 0 auto 5px;
  object-fit: contain;
}

.card .number {
  display: block;
  color: var(--ink-lcd-faint);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.card .name {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
  color: var(--ink-lcd-faint);
  font-size: 12px;
}

.card img {
  opacity: 0.8;
  filter: brightness(0) invert(0.28);
}

.card.captured {
  border-color: transparent;
  background: var(--type);
}

.card.captured img {
  opacity: 1;
  filter: drop-shadow(0 3px 4px rgb(0 0 0 / 35%));
}

.card.captured .number { color: rgb(255 255 255 / 80%); }
.card.captured .name { color: #fff; font-weight: 600; }
.card.captured:hover {
  box-shadow: none;
  transform: none;
}

.editing .card.captured:hover {
  border-color: transparent;
  box-shadow: 0 6px 20px var(--type-glow);
  transform: translateY(-3px);
}

.card.saving {
  opacity: 0.62;
}

.saving-label {
  position: absolute;
  top: 5px;
  right: 5px;
  padding: 2px 4px;
  border-radius: 3px;
  background: rgb(0 0 0 / 68%);
  color: #fff;
  font-size: 9px;
}

.saving-label::before { content: "· "; color: var(--amber); }

@keyframes ignite {
  from { filter: brightness(2.1); }
  to { filter: brightness(1); }
}

.card.just-captured {
  animation: ignite 0.45s ease-out;
}

.empty-state {
  grid-column: 1 / -1;
  min-height: 88px;
  margin: 0;
  padding: 30px 12px;
  color: var(--ink-lcd-dim);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-align: center;
}

.error-state {
  color: var(--ink-lcd);
  font-weight: 600;
}

footer {
  margin-top: 16px;
  color: #ffd9d4;
  font-size: 12px;
  letter-spacing: 0.05em;
  line-height: 1.8;
  opacity: 0.85;
  text-align: center;
}

.toast {
  position: fixed;
  z-index: 10;
  right: 20px;
  bottom: 20px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 11px 14px;
  border: 1px solid rgb(255 255 255 / 18%);
  border-radius: 8px;
  background: #1d211a;
  box-shadow: 0 7px 24px rgb(0 0 0 / 38%);
  color: #eaf6df;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.error { background: #471a17; color: #ffe0dc; }
.toast.visible { opacity: 1; transform: translateY(0); }

@media (max-width: 520px) {
  .device {
    width: calc(100% - 16px);
    margin: 8px auto 24px;
    padding: 16px 12px 18px;
    border-radius: 18px;
  }

  header { gap: 12px; }
  .lcd { gap: 10px; padding: 12px; }
  .lcd .num { font-size: 26px; }
  .screen { padding: 10px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  /* 手机：筛选键与编辑图标同一行 */
  .tab-row { gap: 10px; }
  .tabs { flex: 1 1 auto; min-width: 0; }
  .tab { flex: 1 1 0; padding-inline: 6px; white-space: nowrap; }

  /* 手机：导出隐藏；编辑压缩为图标按钮（文本保留在无障碍树里） */
  #export-button { display: none; }
  #edit-button { min-width: 44px; padding: 7px 12px; font-size: 0; }
  #edit-button::before { content: "✎"; font-size: 17px; line-height: 1; }
  body.editing #edit-button::before { content: "✕"; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
