/*
 * 工具箱 — a pegboard (洞洞板) launcher.
 * A plain wall carries the sign (title + status line); below it hangs a full-width pegboard
 * where every tool is a tag, and the spare holes are room for the next one.
 * System fonts only: no external requests of any kind.
 * The tools' own theme-colors are not used (spec §5.6): light ones such as #EFF0EB have too little contrast
 * on this page, and a favicon drawn in its theme-color would vanish on it (see .icon).
 */

:root {
  color-scheme: light dark;
  --wall: #eef1ec;
  --board: #e1e7df;
  --board-edge: #cdd5cb;
  --hole: #c9d1c7;
  --hole-lit: #f4f7f3;
  --card: #ffffff;
  --card-hover: #f8faf7;
  --card-edge: #cdd5cb;
  --card-lip: #b4beb2;
  --tap: rgb(23 34 28 / 0.12);
  --outline: #94a092;
  --ink: #17221c;
  --muted: #4b5a51;
  --plate: #edf1ec;
  --icon-ring: rgb(23 34 28 / 0.1);
  --sticker: #f3c33a;
  --sticker-ink: #17221c;
  --down-bg: #fbe4dd;
  --down-ink: #9b2c1f;
  --focus: #1e4d3e;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Noto Sans CJK TC",
    "Microsoft JhengHei", system-ui, sans-serif;
  --pitch: 28px;
  --gutter: max(16px, env(safe-area-inset-left), env(safe-area-inset-right));
}

@media (prefers-color-scheme: dark) {
  :root {
    --wall: #121a16;
    --board: #18211c;
    --board-edge: #26302a;
    --hole: #0c120f;
    --hole-lit: #232d27;
    --card: #202a24;
    --card-hover: #25302a;
    --card-edge: #2f3b34;
    --card-lip: #0b100d;
    --tap: rgb(230 237 232 / 0.14);
    --outline: #56665c;
    --ink: #e6ede8;
    --muted: #a5b3aa;
    /* Stays light, dimmed: most favicons are drawn for a light tab bar, so transparent dark
       artwork keeps its contrast in dark mode too. */
    --plate: #d5ddd7;
    --icon-ring: rgb(230 237 232 / 0.12);
    --down-bg: #3d231e;
    --down-ink: #ffb4a4;
    --focus: #f3c33a;
  }
}

html {
  background-color: var(--wall);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  font-kerning: normal;
}

.masthead,
.colophon,
.tools,
.empty {
  box-sizing: border-box;
  width: min(1100px, 100% - 2 * var(--gutter));
  margin-inline: auto;
}

/* The sign above the board. */
.masthead {
  padding-top: max(28px, env(safe-area-inset-top));
  padding-bottom: 22px;
}

.site-title {
  margin: 0;
  font-size: 2.25rem;
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: 0.08em;
  /* A long unbroken title from config wraps instead of scrolling sideways. */
  overflow-wrap: anywhere;
}

.meta {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

/* The pegboard: punched holes with a lit lower rim, on a fixed pitch from its top edge. */
.board {
  flex: 1 0 auto;
  padding-top: 24px;
  padding-bottom: 32px;
  border-block: 1px solid var(--board-edge);
  background-color: var(--board);
  background-image:
    radial-gradient(circle at 50% calc(50% - 0.5px), var(--hole) 0 2.8px, transparent 3.4px),
    radial-gradient(circle at 50% calc(50% + 0.75px), var(--hole-lit) 0 2.8px, transparent 3.4px);
  background-size: var(--pitch) var(--pitch);
  background-position: 50% 0;
}

/* Tools: tags hung on the board. */
.tools {
  margin-block: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.tool {
  display: flex;
  min-width: 0;
}

.card {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  display: flex;
  gap: 14px;
  padding: 16px 16px 15px;
  border: 1px solid var(--card-edge);
  border-radius: 16px;
  background-color: var(--card);
  box-shadow: 0 3px 0 var(--card-lip);
  color: inherit;
  text-decoration: none;
  /* iOS Safari never applies :active on a page without touch listeners (this one has no script), so this tinted
     flash is the only press feedback a tap gets there. */
  -webkit-tap-highlight-color: var(--tap);
  transition: transform 90ms ease-out, box-shadow 90ms ease-out;
}

.card:hover {
  background-color: var(--card-hover);
  border-color: var(--card-lip);
}

/* Pressing a tag pushes it onto the board. */
.card:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--card-lip);
}

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

.icon {
  flex: none;
  align-self: flex-start;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  object-fit: contain;
  /* Always the neutral plate, never the tool's theme-color: a favicon drawn in its own brand color,
     which is often its theme-color too, would vanish on it. The plate is light in both modes (see --plate), so
     adaptive SVG favicons are asked for the artwork they draw on a light tab bar. */
  background-color: var(--plate);
  color-scheme: light;
  outline: 1px solid var(--icon-ring);
  outline-offset: -1px;
}

.is-down .icon {
  filter: grayscale(1);
  opacity: 0.55;
}

.info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

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

.name {
  min-width: 0;
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1.45;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

/* Status stickers: 新 is the yellow price-tag sticker; 暫時連不上 is a quiet warning tag. */
.badge {
  flex: none;
  padding: 0 7px;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.75;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.badge-new {
  background-color: var(--sticker);
  color: var(--sticker-ink);
}

.badge-down {
  background-color: var(--down-bg);
  color: var(--down-ink);
}

.desc {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

/* The domain sits on the tag's bottom edge, so a row of tags lines up. */
.host {
  margin: auto 0 0;
  padding-top: 8px;
  display: flex;
  align-items: baseline;
  gap: 4px;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.4;
}

.domain {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.arrow {
  flex: none;
}

/* Empty board: the painted outline of a tool that is not there yet, as on a shadow board. */
.empty {
  margin-block: 0;
  padding: 32px 16px;
  border: 2px dashed var(--outline);
  border-radius: 16px;
  background-color: var(--board);
  color: var(--muted);
  text-align: center;
  /* Break after 。 rather than inside a word; still wrap anywhere on very narrow screens. */
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.colophon {
  padding-top: 20px;
  padding-bottom: max(28px, env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

.colophon p {
  margin: 0;
}

@media (min-width: 720px) {
  :root {
    --gutter: max(28px, env(safe-area-inset-left), env(safe-area-inset-right));
  }

  .masthead {
    padding-top: max(48px, env(safe-area-inset-top));
    padding-bottom: 30px;
  }

  .site-title {
    font-size: 2.75rem;
  }

  .board {
    padding-top: 32px;
    padding-bottom: 40px;
  }

  .tools {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }
}

@media (min-width: 1080px) {
  .tools {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .card {
    transition: none;
  }

  .card:active {
    transform: none;
  }
}

/* Windows contrast themes. The icon keeps its light plate: forced to Canvas (black in a dark theme), it would hide
   the dark artwork it asks adaptive SVGs for. Badges lose their fill, so an outline keeps them chips. */
@media (forced-colors: active) {
  .icon {
    forced-color-adjust: none;
  }

  .badge {
    border: 1px solid CanvasText;
  }
}
