/* ポータルの見た目。スマホ（幅360〜430px）を基準にして、広い画面では2〜3列に並べる */

:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --card-press: #eceef1;
  --text: #1c1f24;
  --muted: #5f6670;
  --border: #e0e3e7;
  --up: #1b8a4b;
  --down: #c93b3b;
  --pending: #8a9099;
  --badge-bg: #e6ecfb;
  --badge-text: #2a4d9b;
  --notice-bg: #fff6e0;
  --notice-text: #6b4e00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --card: #1b1f24;
    --card-press: #252a31;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --border: #2b3036;
    --up: #3ccf7a;
    --down: #ff6b6b;
    --pending: #7d848c;
    --badge-bg: #1f2a44;
    --badge-text: #a9c1ff;
    --notice-bg: #2e2714;
    --notice-text: #f0d68a;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

/* 画面全体は動かさず、上にタブの帯、その下（.stage）に一覧か開いたページを出す。
   overscroll-behavior: 下に引っ張ったときの「引っ張って更新」を止める（開いているタブが全部読み直しになるため） */
html,
body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.5;
}

/* ---- 上のタブの帯（ポータルの中で開いたページがあるときだけ出る） ---- */

.tabbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 4px;
  padding: calc(4px + env(safe-area-inset-top)) 4px 4px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.tab-home,
.tab-fold,
.tab {
  flex: 0 0 auto;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.tab-home,
.tab-fold {
  width: 44px;
  padding: 0;
  font: inherit;
  font-size: 18px;
  cursor: pointer;
}

/* 帯をたたむ ▲（右端） */
.tab-fold {
  color: var(--muted);
  font-size: 14px;
}

/* たたんだ帯: 細い線（▼）だけ残し、線のどこを押しても戻る。
   浮かぶボタンにしないのは、中で開いたターミナルのタブ画面の右上に出る ▼ と重ならないようにするため */
.tab-unfold {
  display: none;
}

.tabbar.folded {
  padding: env(safe-area-inset-top) 0 0;
}

.tabbar.folded > :not(.tab-unfold) {
  display: none;
}

.tabbar.folded .tab-unfold {
  display: block;
  flex: 1 1 auto;
  height: 16px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 10px;
  line-height: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tabs {
  display: flex;
  flex: 1 1 auto;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  display: flex;
  align-items: center;
  max-width: 200px;
}

.tab-main,
.tab-close {
  height: 100%;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tab-main {
  min-width: 0;
  padding: 0 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* × は選択中のタブにだけ出す（切り替えようとして押し間違えないように） */
.tab-close {
  display: none;
  flex-shrink: 0;
  width: 32px;
  padding: 0;
  border-left: 1px solid var(--border);
}

.tab.on .tab-close {
  display: block;
}

.tab-home.on,
.tab.on {
  border-color: var(--badge-text);
  background: var(--badge-bg);
  color: var(--badge-text);
  font-weight: 600;
}

/* ---- 帯の下: 一覧（.home）と、開いたページ（.frames）を同じ場所に重ねる ---- */

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.home {
  position: absolute;
  inset: 0;
  z-index: 1;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg);
}

.frames {
  position: absolute;
  inset: 0;
}

/* 見えていないタブも大きさは保ったまま裏で動かし続ける（display:none にすると大きさが 0 になり、
   ターミナルが画面の行数を 0 と数え直してしまう） */
.frames iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
  visibility: hidden;
}

.frames iframe.on {
  visibility: visible;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1100px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 0 4px;
}

/* タブの帯が出ているときは、画面上端の余白（ノッチよけ）は帯の側でとる */
.tabbar:not([hidden]) + .stage .top {
  padding-top: 12px;
}

.top h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.recheck {
  flex-shrink: 0;
  min-height: 40px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.recheck:active {
  background: var(--card-press);
}

main {
  max-width: 1100px;
  margin: 0 auto;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 20px 0 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.badge {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 11px;
  font-weight: 600;
}

.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 640px) {
  .cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 960px) {
  .cards {
    grid-template-columns: repeat(3, 1fr);
  }
}

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 100%;
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.card:active {
  background: var(--card-press);
}

.card-icon {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--bg);
  font-size: 22px;
}

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

.card-name {
  font-size: 16px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.card-desc {
  color: var(--muted);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

.lamp {
  display: flex;
  flex-shrink: 0;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 40px;
  font-size: 11px;
}

.lamp-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
}

.lamp-up {
  color: var(--up);
}

.lamp-down {
  color: var(--down);
}

.lamp-pending {
  color: var(--pending);
}

.lamp-pending .lamp-dot {
  opacity: 0.5;
}

.notice {
  max-width: 1100px;
  margin: 20px auto 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--notice-bg);
  color: var(--notice-text);
  font-size: 13px;
}

.error {
  margin: 20px 0;
  color: var(--down);
}

.error p {
  margin: 0 0 12px;
}

.error-reload {
  min-height: 44px;
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.error-reload:active {
  background: var(--card-press);
}

/* ---- PC から届いた URL（受け渡し欄）。持ち主の端末でだけ出る ---- */

.handoff {
  max-width: 1100px;
  margin: 0 auto;
}

.handoff-row {
  display: flex;
  gap: 8px;
  height: 100%;
}

.handoff-row .card {
  flex: 1;
  min-width: 0;
  border-color: var(--badge-text);
}

.handoff-remove {
  flex-shrink: 0;
  width: 44px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
}

.handoff-remove:active {
  background: var(--card-press);
}

.handoff-remove:disabled {
  opacity: 0.4;
}

.badge-new {
  margin-left: 6px;
  vertical-align: 2px;
}

.handoff-empty {
  margin: 0;
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  color: var(--muted);
  font-size: 13px;
}

/* ---- グループの開閉（見出しをタップ） ---- */

.section-title.toggle {
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.section-title.toggle::after {
  content: "▾";
  margin-left: auto;
  padding: 0 4px;
  font-size: 16px;
}

.section-title.toggle.closed::after {
  content: "▸";
}

/* hidden（非表示）を、ほかの表示指定より必ず優先する（開閉で閉じたグループを確実に消すため） */
[hidden] {
  display: none !important;
}
