:root {
  --bg: #0e1117;
  --surface: #161b23;
  --surface-2: #1d232d;
  --border: #2a323f;
  --text: #e6edf3;
  --muted: #8b97a8;
  --accent: #5eead4;
  --accent-2: #38bdf8;
  --danger: #f87171;
  --ok: #4ade80;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
    "Yu Gothic UI", "Noto Sans JP", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  min-height: 100dvh;
}

.hidden { display: none !important; }

.screen { max-width: 640px; margin: 0 auto; padding: 16px 16px 48px; }

/* ---- ヘッダ ---- */
header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0 14px;
}
header h1 { font-size: 18px; margin: 0; letter-spacing: .02em; }
.whoami {
  flex: 1;
  font-size: 13px;
  color: var(--muted);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
header .ghost { width: 40px; height: 40px; padding: 0; font-size: 17px; }

.logo {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background:
    radial-gradient(circle at 50% 50%, var(--accent-2) 0 12%, transparent 13%),
    conic-gradient(from 200deg, var(--accent) 0 55%, var(--accent-2) 55% 78%, transparent 78%);
  -webkit-mask: radial-gradient(circle at 50% 50%, #000 0 14%, transparent 15% 38%, #000 39% 62%, transparent 63%);
  mask: radial-gradient(circle at 50% 50%, #000 0 14%, transparent 15% 38%, #000 39% 62%, transparent 63%);
}
.logo.small { width: 28px; height: 28px; }

/* ---- カード ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

details.card > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  list-style: none;
  user-select: none;
}
details.card > summary::after { content: " ▾"; }
details.card[open] > summary { margin-bottom: 12px; }
details.card[open] > summary::after { content: " ▴"; }
summary::-webkit-details-marker { display: none; }

/* ---- フォーム ---- */
.field { display: block; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field > span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}
.field em { font-style: normal; color: var(--accent); margin-left: 8px; }

input[type=text], input[type=password], input[type=date], select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  padding: 12px 13px;
  appearance: none;
}
textarea { resize: vertical; font-variant-numeric: tabular-nums; line-height: 1.7; }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 34px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(94, 234, 212, .15);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  font-size: 14px;
  cursor: pointer;
}
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }

/* ---- ボタン ---- */
button {
  font: inherit;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  padding: 11px 16px;
}
button:disabled { opacity: .5; cursor: default; }

.primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #05201d;
  font-weight: 700;
  border: none;
}
.primary.big { padding: 16px; font-size: 17px; margin-bottom: 14px; }

.ghost {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}
.ghost.sm { padding: 7px 12px; font-size: 13px; }
.ghost.danger { color: var(--danger); }

.row { display: flex; gap: 8px; margin-top: 10px; }

/* ---- タブ ---- */
.tabs {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 14px;
}
.tab {
  flex: 1;
  background: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 9px;
}
.tab.active { background: var(--surface-2); color: var(--text); }

/* ---- テキスト ---- */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 14px; }
h1 { font-size: 22px; }

/* ---- 結果 ---- */
.result .status { font-weight: 700; font-size: 16px; margin: 0 0 8px; }
.result .status.ok { color: var(--ok); }
.result .status.ng { color: var(--danger); }
.result pre {
  background: #0b0e13;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 11.5px;
  line-height: 1.55;
  overflow-x: auto;
  white-space: pre;
  max-height: 45vh;
  margin: 10px 0 0;
}
.meta {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 10px;
  word-break: break-all;
  white-space: pre-line;
}
.note { font-size: 12.5px; color: var(--accent); margin: 0 0 8px; }

a.dl {
  display: block;
  text-align: center;
  text-decoration: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #05201d;
  font-weight: 700;
  padding: 15px;
  border-radius: 10px;
  margin-bottom: 10px;
}

a.alt-dl {
  display: block;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}

/* ---- 履歴 ---- */
.hist {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  margin-bottom: 10px;
}
.hist .name { font-weight: 600; font-size: 14px; word-break: break-all; }
.hist .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.hist .row { margin-top: 10px; }
.hist .row > * { flex: 1; text-align: center; text-decoration: none; }
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  margin-right: 6px;
  vertical-align: 1px;
}
.badge.ok { background: rgba(74, 222, 128, .15); color: var(--ok); }
.badge.ng { background: rgba(248, 113, 113, .15); color: var(--danger); }

/* ---- オーバーレイ / トースト ---- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(14, 17, 23, .82);
  backdrop-filter: blur(3px);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; z-index: 50;
}
.overlay p { color: var(--muted); margin: 0; }
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 14px;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
}

/* ---- ログイン ---- */
.login-card { margin-top: 12vh; text-align: center; padding: 28px 22px; }
.login-card .logo { margin: 0 auto 14px; width: 52px; height: 52px; }
.login-card h1 { margin: 0 0 4px; }
.login-card p { margin: 0 0 20px; font-size: 14px; }
.login-card input { margin-bottom: 12px; text-align: center; }

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f0f3f7;
    --border: #dde3ec;
    --text: #16202e;
    --muted: #5f6b7d;
    --accent: #0d9488;
    --accent-2: #0284c7;
    --ok: #15803d;
    --danger: #dc2626;
  }
  .primary, a.dl { color: #fff; }
  .result pre { background: #f7f9fc; }
}
