:root {
  color-scheme: light;
  --ink: #444;
  --muted: #7a7a80;
  --line: #b9bbc2;
  --line-soft: #dfe0e5;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-soft: rgba(249, 249, 251, 0.94);
  --bg: #eef0f3;
  --active: #777;
  --accent: #c0392b;
  font-family: "Hiragino Sans", "Yu Gothic", "YuGothic", "Noto Sans JP", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100dvh;
  background:
    linear-gradient(rgba(255,255,255,.56), rgba(255,255,255,.56)),
    repeating-linear-gradient(135deg, #dfe2e6 0 18px, #e8eaed 18px 36px);
  color: var(--ink);
}

a { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.preview-page {
  width: min(100%, 980px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: 14px;
}

.preview-toolbar {
  min-height: 48px;
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto minmax(120px, 1fr);
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.preview-title { min-width: 0; text-align: center; }
.preview-title strong {
  display: block;
  overflow: hidden;
  font-size: 15px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.preview-kicker {
  display: block;
  margin-bottom: 2px;
  color: #8e8f95;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .08em;
}
.orientation-note {
  justify-self: end;
  color: #8b8c92;
  font-size: 10px;
  font-weight: 700;
}
.back-link {
  justify-self: start;
  min-width: 120px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255,255,255,.86);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}
.back-link[hidden] { visibility: hidden; display: block; }

.preview-screen {
  position: relative;
  min-height: min(680px, calc(100dvh - 86px));
  padding: 16px;
  overflow: hidden;
  border: 2px solid #9d9fa6;
  border-radius: 12px;
  background:
    linear-gradient(rgba(245,246,248,.88), rgba(245,246,248,.88)),
    radial-gradient(circle at 30% 20%, #fff 0 8%, transparent 9%),
    #e7e9ec;
  box-shadow: 0 12px 40px rgba(55,60,70,.16);
}

.loading, .error-box {
  margin: 20px;
  color: #6d6e74;
  font-size: 13px;
  font-weight: 700;
}
.error-box {
  padding: 14px;
  border: 1px solid #d7a8a8;
  border-radius: 8px;
  background: #fff5f5;
  color: #8c4545;
}

.screen-heading {
  margin: 2px 0 12px;
  font-size: 12px;
  font-weight: 800;
  color: #66676c;
}
.screen-sub {
  margin: -6px 0 12px;
  color: #8b8c91;
  font-size: 10px;
}

.story-top-list {
  width: min(100%, 780px);
  margin: 12px auto 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.category-card {
  position: relative;
  min-height: 112px;
  display: grid;
  grid-template-columns: 128px 1fr 26px;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border: 1px solid #aaaeb5;
  border-radius: 8px;
  background: var(--panel);
  color: inherit;
  text-decoration: none;
  transition: border-color .12s ease, transform .12s ease, box-shadow .12s ease;
}
.category-card:hover {
  border-color: #777;
  box-shadow: 0 8px 18px rgba(50,55,65,.10);
  transform: translateY(-1px);
}
.category-visual {
  min-height: 78px;
  display: grid;
  place-items: center;
  padding: 8px;
  border: 1px dashed #bfc1c7;
  border-radius: 6px;
  background: #f3f4f6;
  color: #898a90;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
}
.category-title { font-size: 16px; font-weight: 900; }
.category-desc { margin-top: 5px; color: #74767c; font-size: 11px; line-height: 1.55; }
.category-meta { margin-top: 8px; color: #8b8c91; font-size: 10px; }
.category-arrow { color: #aaa; font-size: 24px; text-align: center; }
.opening-badge {
  position: absolute;
  top: -8px;
  left: 170px;
  padding: 3px 12px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
}

.project-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 0 0 10px;
  scrollbar-width: thin;
}
.project-tab, .group-tab {
  flex: 0 0 auto;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255,255,255,.82);
  font-size: 10px;
  font-weight: 800;
  text-decoration: none;
}
.project-tab.active, .group-tab.active {
  border-color: var(--active);
  box-shadow: inset 0 0 0 1px var(--active);
  background: #fff;
}

.two-pane {
  display: grid;
  grid-template-columns: minmax(220px, 31%) minmax(0, 1fr);
  gap: 10px;
  min-height: 520px;
}
.wire-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.panel-header {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 11px;
  border-bottom: 1px solid var(--line-soft);
  background: #f3f4f6;
  font-size: 11px;
  font-weight: 900;
}
.panel-header small { color: #85868b; font-size: 9px; font-weight: 700; }
.wire-list {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  overflow-y: auto;
}
.wire-list-item {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 22px;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  background: #fff;
  color: inherit;
  text-align: left;
  text-decoration: none;
}
.wire-list-item.active {
  border-color: #777;
  box-shadow: inset 0 0 0 1px #777;
}
.li-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid #cfd1d6;
  border-radius: 6px;
  background: #f6f7f8;
  color: #777;
  font-size: 12px;
  font-weight: 900;
}
.li-title {
  color: #4d4f54;
  font-size: 11px;
  font-weight: 900;
  line-height: 1.35;
}
.li-desc {
  margin-top: 3px;
  color: #898a8f;
  font-size: 9px;
  line-height: 1.45;
}
.li-arrow {
  justify-self: end;
  color: #aaa;
  font-size: 16px;
}

.episode-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  gap: 6px;
  align-items: stretch;
}
.detail-btn {
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  background: #f8f8f9;
  color: #686a6f;
  font-size: 9px;
  font-weight: 800;
  cursor: pointer;
}

.bond-layout {
  min-height: 520px;
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "groups members"
    "groups panel";
  gap: 10px;
}
.group-rail {
  grid-area: groups;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.group-tab {
  width: 100%;
  min-height: 48px;
  display: grid;
  place-items: center;
  text-align: center;
}
.member-strip {
  grid-area: members;
  min-width: 0;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 8px;
  scrollbar-width: thin;
}
.member-chip {
  flex: 0 0 58px;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  padding: 5px;
  border: 1px solid #c7c9ce;
  border-radius: 50%;
  background: #fff;
  color: #66686d;
  font-size: 8.5px;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
}
.member-chip.active {
  border: 2px solid #777;
  color: #444;
  box-shadow: 0 3px 10px rgba(60,65,75,.12);
}
.bond-panel { grid-area: panel; }
.member-love { white-space: nowrap; }

.detail-dialog {
  width: min(92vw, 540px);
  border: 1px solid #aaaeb5;
  border-radius: 10px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 18px 60px rgba(35,40,50,.28);
}
.detail-dialog::backdrop { background: rgba(35,40,50,.35); }
.detail-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: #f2f3f5;
}
.detail-dialog-head strong { font-size: 13px; }
.detail-dialog-head button {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: #e4e5e8;
  cursor: pointer;
}
.detail-dialog p {
  margin: 0;
  padding: 16px;
  color: #6f7177;
  font-size: 12px;
  line-height: 1.8;
}

.empty-state {
  padding: 24px;
  color: #85868b;
  font-size: 11px;
  text-align: center;
}

@media (max-width: 700px) {
  .preview-page { padding: 0; }
  .preview-toolbar {
    min-height: 56px;
    grid-template-columns: 92px minmax(0, 1fr) 74px;
    gap: 6px;
    padding: max(8px, env(safe-area-inset-top)) 8px 6px;
    margin: 0;
    background: rgba(245,246,248,.96);
    border-bottom: 1px solid #d6d8dd;
  }
  .back-link {
    min-width: 0;
    width: 92px;
    padding: 7px 5px;
    font-size: 10px;
  }
  .preview-title strong { font-size: 13px; }
  .preview-kicker { font-size: 7px; }
  .orientation-note { font-size: 8px; text-align: right; }

  .preview-screen {
    min-height: calc(100dvh - 56px);
    padding: 10px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: auto;
  }

  .story-top-list { margin-top: 6px; }
  .category-card {
    min-height: 100px;
    grid-template-columns: 82px minmax(0,1fr) 18px;
    gap: 9px;
    padding: 10px;
  }
  .category-visual { min-height: 66px; font-size: 8px; }
  .category-title { font-size: 14px; }
  .category-desc { font-size: 9px; }
  .category-meta { font-size: 8px; }
  .opening-badge { left: 108px; font-size: 8px; }

  .two-pane {
    min-height: 0;
    grid-template-columns: 1fr;
  }
  .two-pane > .wire-panel:first-child .wire-list {
    max-height: 176px;
  }
  .wire-panel { overflow: visible; }
  .wire-list { overflow: visible; }
  .panel-header { position: sticky; top: -10px; z-index: 2; }

  .bond-layout {
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "groups"
      "members"
      "panel";
  }
  .group-rail {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 2px;
  }
  .group-tab { width: auto; min-width: 100px; min-height: 38px; }
  .member-chip { flex-basis: 54px; width: 54px; height: 54px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .preview-page { width: 100%; padding: 6px; }
  .preview-toolbar { min-height: 38px; margin-bottom: 4px; }
  .preview-screen {
    min-height: calc(100dvh - 48px);
    height: calc(100dvh - 48px);
    padding: 9px;
  }
  .two-pane, .bond-layout { min-height: 0; height: calc(100dvh - 74px); }
  .category-card { min-height: 88px; }
  .category-visual { min-height: 62px; }
}
