/* ==========================================================
   ツールボックス 共通スタイル
   CSS変数によるテーマ管理(ライト/ダーク対応)
   ========================================================== */
:root {
    --bg: #f4f6fa;
    --bg-card: #ffffff;
    --bg-soft: #eef1f7;
    --text: #1f2533;
    --text-muted: #6b7280;
    --primary: #3b82f6;
    --primary-strong: #2563eb;
    --primary-soft: #dbeafe;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --border: #dde2ec;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .06);
    --shadow-hover: 0 4px 10px rgba(15, 23, 42, .12), 0 10px 26px rgba(15, 23, 42, .10);
    --radius: 12px;
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
    --bg: #11151f;
    --bg-card: #1a2030;
    --bg-soft: #232b3f;
    --text: #e5e9f2;
    --text-muted: #98a1b3;
    --primary: #60a5fa;
    --primary-strong: #3b82f6;
    --primary-soft: #1e3a5f;
    --border: #303a52;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    --shadow-hover: 0 6px 20px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.main { min-height: 70vh; padding-top: 24px; padding-bottom: 48px; }

/* ---------- ヘッダー ---------- */
.site-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 58px; gap: 12px; }
.brand { font-size: 1.15rem; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.brand-icon { width: 20px; height: 20px; vertical-align: -3px; }
.brand:hover { text-decoration: none; opacity: .85; }
.nav { display: flex; align-items: center; gap: 10px; }
.nav-link { color: var(--text); font-size: .92rem; white-space: nowrap; }
.nav .icon, .btn .icon { width: 16px; height: 16px; vertical-align: -3px; }
.inline-form { display: inline; margin: 0; }

/* ---------- フッター ---------- */
.site-footer {
    border-top: 1px solid var(--border);
    padding: 24px 0;
    text-align: center;
    color: var(--text-muted);
    font-size: .88rem;
}
.site-footer p { margin: 4px 0; }
.footer-links { margin: 8px 0; }
.footer-links a { color: var(--text-muted); text-decoration: underline; }
.powered-by { font-size: .78rem; color: var(--text-muted); opacity: .8; margin-top: 10px; }

/* ---------- SVGアイコン ---------- */
.icon {
    display: inline-block;
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.icon-xs { width: 12px; height: 12px; vertical-align: -2px; }
.icon-sm { width: 14px; height: 14px; vertical-align: -2px; }
.icon-lg { width: 20px; height: 20px; vertical-align: -4px; }
.icon-xl { width: 28px; height: 28px; vertical-align: -6px; }

/* ---------- 広告枠 ---------- */
.ad-slot {
    position: relative;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 22px 16px 16px;
    margin: 18px 0;
    text-align: center;
    background: var(--bg-card);
}
.ad-slot .ad-label {
    position: absolute;
    top: 4px;
    left: 10px;
    font-size: .68rem;
    color: var(--text-muted);
    letter-spacing: 1px;
}
.ad-empty a { color: var(--text-muted); font-size: .88rem; }

/* ---------- ボタン ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    border-radius: 8px;
    padding: 9px 18px;
    font-size: .95rem;
    cursor: pointer;
    transition: background .15s, transform .05s, box-shadow .15s;
    text-decoration: none;
    font-family: inherit;
}
.btn:hover { background: var(--bg-soft); text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary-strong); border-color: var(--primary-strong); color: #fff; }
.btn-primary:hover { background: var(--primary); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; background: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 5px 12px; font-size: .85rem; }
.btn-lg { padding: 13px 28px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- フォーム ---------- */
label { font-weight: 600; font-size: .92rem; display: block; margin-bottom: 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="datetime-local"], input[type="url"], input[type="time"],
select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary);
    outline-offset: 0;
    border-color: var(--primary);
}
textarea { resize: vertical; min-height: 120px; }
textarea.mono, input.mono, .mono { font-family: var(--font-mono); }
.form-group { margin-bottom: 16px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 140px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-weight: normal; cursor: pointer; }
.checkbox-label input { width: auto; }
input[type="range"] { width: 100%; accent-color: var(--primary-strong); }
input[type="color"] { width: 64px; height: 42px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-card); cursor: pointer; }

/* ---------- カード ---------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    margin-bottom: 20px;
}
.card h2 { margin-top: 0; font-size: 1.15rem; }
.card h3 { font-size: 1.02rem; }

/* ---------- ポータルトップ ---------- */
.hero { text-align: center; padding: 36px 0 20px; }
.hero h1 { font-size: 1.9rem; margin: 0 0 8px; }
.hero p { color: var(--text-muted); margin: 0 0 22px; }
.search-box { max-width: 520px; margin: 0 auto; position: relative; }
.search-box input { padding-left: 42px; height: 50px; border-radius: 25px; font-size: 1.05rem; box-shadow: var(--shadow); }
.search-icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--text-muted); width: 18px; height: 18px; }
.search-icon .icon { width: 18px; height: 18px; vertical-align: middle; }

.cat-filter { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 22px 0 8px; }
.chip {
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    border-radius: 999px;
    padding: 6px 16px;
    font-size: .9rem;
    cursor: pointer;
    transition: all .15s;
    font-family: inherit;
}
.chip:hover { border-color: var(--primary); }
.chip.active { background: var(--primary-strong); border-color: var(--primary-strong); color: #fff; }

.cat-section { margin-top: 30px; }
.cat-title { font-size: 1.2rem; margin: 0 0 14px; display: flex; align-items: center; gap: 8px; }
.cat-title .icon { width: 18px; height: 18px; vertical-align: -3px; }
.chip .icon { width: 14px; height: 14px; vertical-align: -2px; }
.app-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 14px;
}
.app-card {
    position: relative;
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 16px 14px;
    color: var(--text);
    box-shadow: var(--shadow);
    transition: transform .12s, box-shadow .12s, border-color .12s;
}
.app-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
    border-color: var(--primary);
    text-decoration: none;
}
.app-card .app-icon { display: block; margin-bottom: 8px; line-height: 1; }
.app-card .app-icon .icon { width: 28px; height: 28px; vertical-align: top; }
.app-card .app-name { font-weight: 700; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.app-card .app-desc { font-size: .83rem; color: var(--text-muted); margin: 4px 0 0; line-height: 1.55; }
.fav-btn {
    position: absolute;
    top: 10px; right: 10px;
    background: none; border: none;
    cursor: pointer;
    opacity: .35;
    transition: opacity .15s, transform .1s;
    padding: 4px;
    line-height: 1;
    color: var(--text);
}
.fav-btn .icon { width: 16px; height: 16px; vertical-align: middle; }
.fav-btn:hover { opacity: .8; transform: scale(1.15); }
.fav-btn.faved { opacity: 1; color: var(--warning); }
.fav-btn.faved .fav-icon { fill: currentColor; }
.badge { font-size: .68rem; padding: 1px 8px; border-radius: 999px; background: var(--primary-soft); color: var(--primary-strong); font-weight: 600; }
#fav-section:not(.has-items) { display: none; }
.no-results { text-align: center; color: var(--text-muted); padding: 40px 0; display: none; }

/* ---------- ツールページ ---------- */
.tool-head { margin-bottom: 22px; }
.tool-head h1 { font-size: 1.55rem; margin: 0 0 4px; }
.tool-desc { color: var(--text-muted); margin: 0; }
.tool-icon { width: 22px; height: 22px; vertical-align: -4px; margin-right: 2px; }
.back-link { font-size: .9rem; }
.hero-icon { width: 28px; height: 28px; vertical-align: -5px; margin-right: 4px; }

.result-box {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    word-break: break-all;
}
.result-big { font-size: 1.7rem; font-weight: 700; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat {
    background: var(--bg-soft);
    border-radius: 10px;
    padding: 14px;
    text-align: center;
}
.stat .stat-value { font-size: 1.6rem; font-weight: 700; }
.stat .stat-label { font-size: .82rem; color: var(--text-muted); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 720px) { .two-col { grid-template-columns: 1fr; } }

.copy-btn { white-space: nowrap; }
.copy-wrap { display: flex; gap: 8px; align-items: flex-start; }
.copy-wrap > :first-child { flex: 1; }

/* テーブル */
table.data-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.data-table th, .data-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.data-table th { font-size: .82rem; color: var(--text-muted); font-weight: 600; }
.data-table tr:hover td { background: var(--bg-soft); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* diff */
.diff-line { font-family: var(--font-mono); font-size: .87rem; white-space: pre-wrap; word-break: break-all; padding: 1px 8px; }
.diff-add { background: rgba(34, 197, 94, .18); }
.diff-del { background: rgba(239, 68, 68, .18); text-decoration: line-through; }

/* タイマー表示 */
.timer-display {
    font-size: clamp(3rem, 12vw, 5.5rem);
    font-weight: 700;
    text-align: center;
    font-variant-numeric: tabular-nums;
    font-family: var(--font-mono);
    letter-spacing: 2px;
    margin: 10px 0;
}
.timer-controls { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* 電卓 */
.calc-pad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; max-width: 360px; margin: 0 auto; }
.calc-pad .btn { font-size: 1.25rem; padding: 16px 0; }
.calc-display {
    max-width: 360px;
    margin: 0 auto 12px;
    background: var(--bg-soft);
    border-radius: 10px;
    padding: 14px 18px;
    text-align: right;
    font-size: 2rem;
    font-family: var(--font-mono);
    overflow-x: auto;
    min-height: 70px;
}
.calc-expr { font-size: .85rem; color: var(--text-muted); min-height: 1.2em; }

/* メッセージ */
.alert { border-radius: 8px; padding: 12px 16px; margin-bottom: 16px; font-size: .95rem; }
.alert-error { background: rgba(239, 68, 68, .12); color: var(--danger); border: 1px solid rgba(239, 68, 68, .35); }
.alert-success { background: rgba(34, 197, 94, .12); color: #15803d; border: 1px solid rgba(34, 197, 94, .35); }
html[data-theme="dark"] .alert-success { color: #4ade80; }
.alert-info { background: var(--primary-soft); color: var(--primary-strong); border: 1px solid var(--primary); }

/* 認証フォーム */
.auth-card { max-width: 440px; margin: 30px auto; }
.auth-card h1 { font-size: 1.4rem; text-align: center; }
.auth-switch { text-align: center; font-size: .9rem; color: var(--text-muted); }

/* ToDo・リスト系 */
.item-list { list-style: none; padding: 0; margin: 0; }
.item-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 6px;
    border-bottom: 1px solid var(--border);
}
.item-list li.done .item-title { text-decoration: line-through; color: var(--text-muted); }
.item-title { flex: 1; word-break: break-all; }
.item-meta { font-size: .8rem; color: var(--text-muted); white-space: nowrap; }
.prio-high { color: var(--danger); font-weight: 700; }
.prio-mid { color: var(--warning); }
.prio-low { color: var(--text-muted); }
.overdue { color: var(--danger); font-weight: 600; }

/* メモ */
.memo-layout { display: grid; grid-template-columns: 260px 1fr; gap: 16px; }
@media (max-width: 760px) { .memo-layout { grid-template-columns: 1fr; } }
.memo-list { max-height: 480px; overflow-y: auto; }
.memo-list-item {
    display: block; width: 100%; text-align: left;
    background: none; border: none; border-bottom: 1px solid var(--border);
    padding: 10px 8px; cursor: pointer; color: var(--text); font-family: inherit; font-size: .92rem;
}
.memo-list-item:hover { background: var(--bg-soft); }
.memo-list-item.active { background: var(--primary-soft); border-radius: 6px; }
.memo-list-item .memo-date { display: block; font-size: .76rem; color: var(--text-muted); }
.save-status { font-size: .82rem; color: var(--text-muted); }

/* 単語帳 */
.fc-card {
    background: var(--bg-card);
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    min-height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    text-align: center;
    cursor: pointer;
    padding: 24px;
    user-select: none;
    box-shadow: var(--shadow);
    word-break: break-word;
}
.fc-hint { text-align: center; color: var(--text-muted); font-size: .85rem; }

/* 習慣トラッカー */
.habit-grid { display: flex; gap: 4px; }
.habit-cell {
    width: 30px; height: 30px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-soft);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: .8rem;
    padding: 0;
}
.habit-cell.checked { background: var(--success); border-color: var(--success); color: #fff; }
.habit-cell:disabled { cursor: default; opacity: .45; }
.streak { font-size: .85rem; color: var(--warning); font-weight: 700; white-space: nowrap; }

/* おみくじ */
.omikuji-result { text-align: center; padding: 18px 0; }
.omikuji-rank { font-size: 4rem; font-weight: 800; margin: 8px 0; }
.omikuji-items { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

/* ルーレット */
.roulette-result { font-size: 2.2rem; font-weight: 800; text-align: center; min-height: 1.4em; }
.dice-face { font-size: 5rem; text-align: center; user-select: none; }

/* QR */
#qr-output { display: flex; justify-content: center; padding: 18px; background: #fff; border-radius: 10px; }
#qr-output img, #qr-output canvas { image-rendering: pixelated; }

/* カラープレビュー */
.color-preview { width: 100%; height: 90px; border-radius: 10px; border: 1px solid var(--border); }
.palette { display: flex; gap: 6px; margin-top: 10px; }
.palette div { flex: 1; height: 46px; border-radius: 8px; cursor: pointer; border: 1px solid var(--border); }

/* Markdownプレビュー */
.md-preview { overflow-wrap: break-word; }
.md-preview h1, .md-preview h2 { border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.md-preview pre { background: var(--bg-soft); padding: 12px; border-radius: 8px; overflow-x: auto; }
.md-preview code { background: var(--bg-soft); padding: 1px 5px; border-radius: 4px; font-family: var(--font-mono); font-size: .9em; }
.md-preview pre code { padding: 0; background: none; }
.md-preview blockquote { border-left: 4px solid var(--border); margin-left: 0; padding-left: 14px; color: var(--text-muted); }
.md-preview table { border-collapse: collapse; }
.md-preview th, .md-preview td { border: 1px solid var(--border); padding: 5px 10px; }

/* ---------- ファイル系ツール ---------- */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px 18px;
    text-align: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: border-color .15s, background .15s;
    background: var(--bg-soft);
}
.dropzone:hover { border-color: var(--primary); }
.dropzone.dragover { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-strong); }
.dropzone .dz-icon { display: block; margin: 0 auto 8px; }
.dropzone .dz-icon .icon { width: 34px; height: 34px; }
.dropzone input[type="file"] { display: none; }

.file-list { list-style: none; padding: 0; margin: 16px 0 0; }
.file-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 6px;
    border-bottom: 1px solid var(--border);
}
.file-thumb {
    width: 48px; height: 48px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-soft);
    flex-shrink: 0;
}
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: .9rem; word-break: break-all; }
.file-meta { font-size: .78rem; color: var(--text-muted); }
.file-remove {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; padding: 4px; line-height: 1;
}
.file-remove:hover { color: var(--danger); }
.file-badge { font-size: .72rem; color: var(--success); white-space: nowrap; }
.file-arrow { color: var(--text-muted); }
.processing-note { font-size: .82rem; color: var(--text-muted); }
.size-down { color: var(--success); font-weight: 700; }
.size-up { color: var(--warning); font-weight: 700; }

/* ユーティリティ */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .86rem; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }

@media (max-width: 600px) {
    .hero h1 { font-size: 1.45rem; }
    .nav-link { display: none; }
    .nav-link:first-child { display: inline; }
    .card { padding: 16px; }
}
