:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --secondary: #8e8e93;
  --separator: rgba(60, 60, 67, 0.12);
  --fill: rgba(118, 118, 128, 0.12);
  --blue: #007aff;
  --green: #34c759;
  --orange: #ff9500;
  --purple: #af52de;
  --red: #ff3b30;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
  --radius: 16px;
  --pad: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.app {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding:
    calc(12px + env(safe-area-inset-top))
    calc(var(--pad) + env(safe-area-inset-right))
    calc(28px + env(safe-area-inset-bottom))
    calc(var(--pad) + env(safe-area-inset-left));
}

.nav { margin-bottom: 12px; }
h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.sub {
  margin: 4px 0 0;
  color: var(--secondary);
  font-size: 13px;
}

.search-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--fill);
  width: 100%;
}
.search-icon { color: var(--secondary); flex-shrink: 0; }
.search-field input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  height: 44px;
}
.search-field input::placeholder { color: var(--secondary); }

.primary {
  width: 100%;
  height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--blue);
  color: #fff;
  font: inherit;
  font-size: 16px;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.primary:active { opacity: 0.86; }

.error {
  margin: 0;
  color: var(--red);
  font-size: 12px;
}

.engines {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.card-top img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: block;
  flex-shrink: 0;
}

.card-top h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.badge {
  display: inline-block;
  margin-top: 1px;
  font-size: 11px;
  color: var(--secondary);
  font-weight: 500;
}

.query {
  background: var(--bg);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
  min-width: 0;
}
.query small {
  display: block;
  color: var(--secondary);
  font-size: 11px;
  margin-bottom: 2px;
}
.query code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  color: var(--blue);
  word-break: break-all;
}

.desc {
  margin: 0 0 12px;
  color: var(--secondary);
  font-size: 13px;
  line-height: 1.45;
  flex: 1;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.actions a {
  text-decoration: none;
  text-align: center;
  border-radius: 10px;
  padding: 10px 8px;
  font-size: 13px;
  font-weight: 650;
  min-height: 40px;
  display: grid;
  place-items: center;
  -webkit-tap-highlight-color: transparent;
}
.actions a.filled {
  background: var(--blue);
  color: #fff;
}
.actions a.tinted {
  background: rgba(0, 122, 255, 0.12);
  color: var(--blue);
}

.group { margin-top: 18px; }
.group h2 {
  margin: 0 0 6px 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--secondary);
  letter-spacing: 0.02em;
}

.list {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.row {
  display: flex;
  gap: 10px;
  padding: 12px;
  align-items: flex-start;
}
.row + .row { border-top: 0.5px solid var(--separator); }
.row strong {
  display: block;
  font-size: 14px;
  font-weight: 650;
}
.row p {
  margin: 2px 0 0;
  color: var(--secondary);
  font-size: 12px;
  line-height: 1.45;
}

.row-icon {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}
.row-icon.blue { background: var(--blue); }
.row-icon.green { background: var(--green); }
.row-icon.orange { background: var(--orange); }
.row-icon.purple { background: var(--purple); }

@media (min-width: 640px) {
  :root { --pad: 20px; }
  .app { padding-top: calc(16px + env(safe-area-inset-top)); }
  h1 { font-size: 28px; }
  .engines { grid-template-columns: 1fr 1fr; }
  .search-card {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .search-field { flex: 1; width: auto; }
  .primary { width: auto; }
  .error { width: 100%; }
}

@media (min-width: 960px) {
  :root { --pad: 24px; }
  .app { padding: 20px 24px 40px; }
  h1 { font-size: 30px; }
  .sub { font-size: 14px; }
  .engines { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
  .search-field,
  .search-field input,
  .primary { height: 40px; min-height: 40px; font-size: 14px; }
  .card { padding: 12px; }
  .card-top img { width: 28px; height: 28px; }
  .card-top h3 { font-size: 14px; }
  .desc { font-size: 12px; }
  .query code { font-size: 12px; }
  .actions a { min-height: 34px; padding: 7px 6px; font-size: 12px; }
  .list {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .row + .row { border-top: 0; }
  .row:nth-child(odd) { border-right: 0.5px solid var(--separator); }
  .row:nth-child(n + 3) { border-top: 0.5px solid var(--separator); }
}

.friends { margin-top: 18px; }
.friends h2 {
  margin: 0 0 6px 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--secondary);
  letter-spacing: 0.02em;
}
.friend-list {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.friend-list a {
  color: var(--blue);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(0, 122, 255, 0.08);
}
.friend-list a:active { opacity: 0.8; }
.empty-links {
  color: var(--secondary);
  font-size: 13px;
  padding: 6px 4px;
}

@media (hover: hover) and (pointer: fine) {
  .primary:hover { filter: brightness(1.05); }
  .actions a:hover { opacity: 0.9; }
  .friend-list a:hover { background: rgba(0, 122, 255, 0.14); }
}
