  :root {
    --maxw: 1200px;
    --pad: 18px;
    --border: #dbe3ee;
    --muted: #556070;
    --bg: #f6f8fb;
    --panel: #fff;
    --shadow: 0 1px 0 rgba(0,0,0,.04);
    --accent: #3d6fb6;
    --accent-weak: #e7f0fb;
  }
  * { box-sizing: border-box; }
  body {
    margin: 0;
    font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans JP","Hiragino Kaku Gothic ProN","Yu Gothic",sans-serif;
    line-height: 1.65;
    color: #111;
    background: var(--bg);
  }
  a { color: inherit; text-decoration: none; }
  a:hover { text-decoration: underline; }

  header { background: #fff; border-bottom: 1px solid var(--border); }
  .wrap {
    max-width: var(--maxw);
    margin: 0 auto;
    padding: var(--pad);
    /* iOS Safari safe-area (notch) handling: prevents subtle left/right offset on some devices */
    padding-left: max(var(--pad), env(safe-area-inset-left));
    padding-right: max(var(--pad), env(safe-area-inset-right));
  }

  .toprow { display:flex; align-items:center; justify-content:space-between; gap: 12px; flex-wrap: wrap; }
  .brand { display:flex; align-items: center; gap: 12px; min-width: 0; }
  .brand h1 { font-size: 28px; margin: 0; font-weight: 800; letter-spacing: .02em; line-height: 1.1; }
  .brand a { text-decoration: none; }
  .brand a:hover { text-decoration: none; }
  .brand .sub { font-size: 12px; color: var(--muted); }

  form.site-search { display:flex; align-items:center; gap: 8px; flex: 1; justify-content: flex-end; }
  .site-search input[type="text"] {
    width: min(440px, 55vw);
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    font-size: 13px;
  }
  .site-search button {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
  }

  main { padding: var(--pad) 0 28px; }

  .panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: var(--pad);
    box-shadow: var(--shadow);
  }

  .content { display: grid; gap: 20px; align-items: start; }
  .content.has-sidebar.has-aside { grid-template-columns: 260px minmax(0, 1fr) 320px; }
  .content.has-sidebar:not(.has-aside) { grid-template-columns: 260px minmax(0, 1fr); }
  .content:not(.has-sidebar).has-aside { grid-template-columns: minmax(0, 1fr) 320px; }
  .content:not(.has-sidebar):not(.has-aside) { grid-template-columns: minmax(0, 1fr); }

  @media (max-width: 980px) {
    .content.has-sidebar.has-aside { grid-template-columns: 1fr; }
    .content.has-sidebar:not(.has-aside) { grid-template-columns: 1fr; }
    .content:not(.has-sidebar).has-aside { grid-template-columns: 1fr; }
    .sidebar { order: 2; }
    .aside { order: 3; }
  }

  /* Item page: show right-column info in main on mobile (same order as desktop aside) */
  .aside-mobile { display: none; }
  @media (max-width: 980px) {
    .aside-mobile { display: block; }
    .aside { display: none; }
  }

  /* AdSense: collapse empty slots to avoid mysterious whitespace (e.g., no-fill) */
  ins.adsbygoogle[data-ad-status="unfilled"] { display: none !important; }

  .sidebar .side-title,
  .aside .side-title { font-size: 13px; color: #222; margin: 0 0 10px; display:flex; align-items:center; gap: 6px; }

  .catlist { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
  .catlist a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    overflow: hidden;
    min-height: 44px;
  }
  .catlist a:hover { text-decoration: none; border-color: #c7d4e5; }
  .catlist a.active {
    border-color: var(--accent);
  }
  .catlabel { display:flex; align-items:center; gap: 8px; min-width: 0; overflow: hidden; flex: 1 1 auto; }
  .catlabel span.name { display:block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .catcount {
    font-size: 11px;
    color: #2f4f7a;
    background: #eaf1fb;
    border: 1px solid #c9d9f2;
    padding: 2px 8px;
    border-radius: 999px;
    min-width: 40px;
    text-align: center;
  }

  .grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
  @media (max-width: 920px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
  @media (max-width: 640px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

  .card { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.03); }
  .card img { width: 100%; height: auto; display: block; background: #f2f2f2; }
  .card .meta { padding: 12px; }
  .card .title { font-size: 13px; margin: 0 0 4px; font-weight: 600; }
  .card .small { font-size: 12px; color: var(--muted); }

  .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
  .tag {
    display: inline-flex;
    align-items: center;
    font-size: 11px;
    padding: 3px 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    background: #fff;
  }
  .tag--cat { background: #eef4ff; border-color: #c7d9f7; color: #2d5aa6; }
  .tag--lang { background: #e9f6fb; border-color: #b7e3f4; color: #1d6c86; }

  .badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    padding: 3px 9px;
    border: 1px solid #c7d9f7;
    border-radius: 999px;
    color: #2d5aa6;
    background: #eef4ff;
  }
  a.badge { text-decoration: none; }
  a.badge:hover { text-decoration: none; border-color: #a9c2ee; }

  .kvs { display: grid; grid-template-columns: 120px 1fr; gap: 10px 14px; margin: 12px 0 0; }
  @media (max-width: 640px) { .kvs { grid-template-columns: 1fr; } }
  .kvs dt { font-weight: 700; color: #222; }
  .kvs dd { margin: 0; color: #222; }

  .actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
  .btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    font-size: 13px;
  }
  .btn:hover { text-decoration: none; border-color: #cfcfcf; }
  .btn-dl {
    font-size: 22px;
    padding: 14px 14px;
    font-weight: 700;
    line-height: 1.1;
  }
  .btn-pdf { border-color: #d93025; }
  .btn-jpg { border-color: #1a73e8; }
  .btn-pdf:hover { border-color: #d93025; }
  .btn-jpg:hover { border-color: #1a73e8; }

  .heroimg { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background:#fff; }
  .heroimg img { width: 100%; height: auto; display:block; background:#f2f2f2; }

  .box { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background:#fff; }
  .box h3 { margin: 0 0 8px; font-size: 13px; }
  .box p { margin: 0; color: #222; font-size: 13px; }
  .aside { font-size: 15px; }
  .aside .box h3 { font-size: 15px; }
  .aside .box p { font-size: 15px; }
  .aside .btn { font-size: 14px; }
  .aside .btn.btn-dl { font-size: 22px; }

  .box + .box { margin-top: 14px; }

  .grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
  @media (max-width: 920px) { .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
  @media (max-width: 420px) { .grid3 { grid-template-columns: 1fr; } }

  .pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 18px; }
  .pager a { flex: 1; text-align: center; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: #fff; }
  .pager .spacer { flex: 1; }

  footer { color: var(--muted); font-size: 12px; padding: 24px 0; text-align: center; }

  @media (max-width: 640px) {
    .toprow { flex-direction: column; align-items: stretch; }
    .brand { width: 100%; }
    form.site-search { width: 100%; justify-content: space-between; }
    .site-search input[type="text"] { width: 100%; flex: 1; }
    .site-search button { flex: 0 0 auto; }
  }

  @media (max-width: 420px) {
    .grid { grid-template-columns: 1fr; }
  }