/* ===== デザイントークン（写真 de KY と共通の考え方） ===== */
:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #eef0f3;
    --ink: #161a20;
    --ink-2: #4b5563;
    --ink-3: #8a93a0;
    --line: #e3e6ea;
    --brand: #2563eb;
    --primary: #161a20;
    --primary-ink: #ffffff;
    --focus: #2563eb;

    --ok: #15803d;
    --ok-bg: #ecfdf3;
    --ng: #dc2626;
    --ng-bg: #fef2f2;
    --warn: #c2410c;
    --warn-bg: #fff7ed;
    --muted: #64748b;
    --muted-bg: #f1f5f9;

    --radius: 18px;
    --radius-sm: 12px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
    --dock-h: 88px;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #22262e;
    --ink: #f1f3f5;
    --ink-2: #b4bcc8;
    --ink-3: #7c8594;
    --line: #2a2f38;
    --brand: #60a5fa;
    --primary: #60a5fa;
    --primary-ink: #0b1220;
    --focus: #93c5fd;

    --ok: #4ade80;
    --ok-bg: #0f2418;
    --ng: #f87171;
    --ng-bg: #2a1517;
    --warn: #fb923c;
    --warn-bg: #2a1c12;
    --muted: #94a3b8;
    --muted-bg: #1e232b;

    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--ink);
    font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP",
        "Yu Gothic UI", Meiryo, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

a {
    color: var(--brand);
}

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

[hidden] {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ===== ヘッダー ===== */
.appbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.brand-mark {
    width: 34px;
    height: 34px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--brand);
    color: #fff;
    font-size: 18px;
}

.brand-name {
    font-weight: 800;
    font-size: 17px;
    letter-spacing: .02em;
    white-space: nowrap;
}

.appbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--ink-2);
    font-size: 20px;
    cursor: pointer;
    text-decoration: none;
}

.icon-btn:hover {
    background: var(--surface-2);
    color: var(--ink);
}

/* アカウントメニュー */
.menu {
    position: relative;
}

.menu>summary {
    list-style: none;
}

.menu>summary::-webkit-details-marker {
    display: none;
}

.menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 240px;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

.menu-email {
    padding: 8px 10px 10px;
    font-size: 13px;
    color: var(--ink-3);
    border-bottom: 1px solid var(--line);
    margin-bottom: 6px;
    word-break: break-all;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ink);
    text-decoration: none;
    cursor: pointer;
    text-align: left;
}

.menu-item:hover {
    background: var(--surface-2);
}

.menu-item.danger {
    color: var(--ng);
}

/* ===== レイアウト ===== */
.page {
    flex: 1;
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
    padding: 8px 16px 24px;
}

.page-wide {
    max-width: 1240px;
}

.page-title {
    margin: 4px 0 16px;
    font-size: 22px;
    font-weight: 800;
}

.footer {
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    text-align: center;
    font-size: 12px;
    color: var(--ink-3);
}

.has-dock .footer {
    padding-bottom: calc(var(--dock-h) + 16px + env(safe-area-inset-bottom));
}

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

.card-title {
    margin: 0 0 12px;
    font-size: 13px;
    font-weight: 700;
    color: var(--ink-3);
    letter-spacing: .04em;
}

/* ===== 入力 ===== */
.field {
    margin-bottom: 16px;
}

.field:last-child {
    margin-bottom: 0;
}

.label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 700;
    color: var(--ink-2);
}

.label small {
    font-weight: 500;
    color: var(--ink-3);
}

.input,
.select,
.textarea {
    width: 100%;
    min-height: 50px;
    padding: 12px 14px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 16px;
    /* iPhone の自動ズーム防止 */
    appearance: none;
    -webkit-appearance: none;
}

.select {
    padding-right: 40px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 6l4.5 4.5L12.5 6' fill='none' stroke='%238a93a0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
}

.textarea {
    min-height: 80px;
    resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--focus);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent);
}

.input.is-invalid,
.select.is-invalid {
    border-color: var(--ng);
}

.hint {
    margin-top: 6px;
    font-size: 13px;
    color: var(--ink-3);
}

.hint.warn {
    color: var(--warn);
    font-weight: 600;
}

.row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* 2〜4択のボタン型ラジオ */
.seg {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 8px;
}

.seg.wrap {
    grid-auto-flow: row;
    grid-template-columns: repeat(4, 1fr);
}

.seg input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.seg label {
    --tone: var(--primary);
    --tone-ink: var(--primary-ink);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 52px;
    padding: 6px 8px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    transition: background .15s, border-color .15s, color .15s;
}

.seg input:checked+label {
    background: var(--tone);
    border-color: var(--tone);
    color: var(--tone-ink);
}

.seg input:focus-visible+label {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.seg label.tone-ok {
    --tone: var(--ok);
    --tone-ink: #fff;
}

.seg label.tone-ng {
    --tone: var(--ng);
    --tone-ink: #fff;
}

.seg label.tone-warn {
    --tone: var(--warn);
    --tone-ink: #fff;
}

.seg label.tone-muted {
    --tone: var(--muted);
    --tone-ink: #fff;
}

:root[data-theme="dark"] .seg label[class*="tone-"] {
    --tone-ink: #0b1220;
}

/* ===== ボタン ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 10px 18px;
    border: 1.5px solid transparent;
    border-radius: 14px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    transition: transform .1s, background .15s, opacity .15s;
}

.btn:active {
    transform: scale(.98);
}

.btn:disabled {
    opacity: .55;
    cursor: default;
}

.btn-primary {
    background: var(--primary);
    color: var(--primary-ink);
}

.btn-secondary {
    background: var(--surface);
    border-color: var(--line);
    color: var(--ink);
}

.btn-danger {
    background: var(--ng);
    color: #fff;
}

.btn-lg {
    min-height: 60px;
    font-size: 18px;
    border-radius: 18px;
}

.btn-block {
    width: 100%;
}

.btn-sm {
    min-height: 38px;
    padding: 6px 12px;
    font-size: 14px;
    border-radius: 10px;
}

/* 画面下に固定する主操作ボタン（片手操作用） */
.dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
}

.dock-inner {
    max-width: 560px;
    margin: 0 auto;
    display: flex;
    gap: 10px;
}

.dock-inner>.btn {
    flex: 1;
}

/* ===== バッジ ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    background: var(--muted-bg);
    color: var(--muted);
}

.badge.ok {
    background: var(--ok-bg);
    color: var(--ok);
}

.badge.ng {
    background: var(--ng-bg);
    color: var(--ng);
}

.badge.warn {
    background: var(--warn-bg);
    color: var(--warn);
}

/* ===== お知らせ ===== */
.notice {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--muted-bg);
    color: var(--ink-2);
    font-size: 14px;
    margin-bottom: 14px;
}

.notice i {
    font-size: 18px;
    line-height: 1.3;
}

.notice.ng {
    background: var(--ng-bg);
    color: var(--ng);
}

.notice.warn {
    background: var(--warn-bg);
    color: var(--warn);
}

.toast-area {
    position: fixed;
    left: 50%;
    top: calc(64px + env(safe-area-inset-top));
    transform: translateX(-50%);
    z-index: 80;
    width: min(92vw, 480px);
    display: grid;
    gap: 8px;
}

.toast {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: var(--ink);
    color: var(--bg);
    box-shadow: var(--shadow);
    font-weight: 600;
    animation: toast-in .2s ease-out;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
}

/* ===== 下から出るシート（確認画面など） ===== */
.sheet {
    width: 100%;
    max-width: 560px;
    max-height: 92vh;
    margin: auto auto 0;
    padding: 0;
    border: 0;
    border-radius: 24px 24px 0 0;
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 -8px 40px rgba(0, 0, 0, .25);
}

.sheet::backdrop {
    background: rgba(10, 12, 16, .55);
}

.sheet[open] {
    animation: sheet-in .22s ease-out;
}

@keyframes sheet-in {
    from {
        transform: translateY(40px);
        opacity: .4;
    }
}

.sheet-body {
    padding: 20px 18px 8px;
}

.sheet-title {
    margin: 0 0 14px;
    font-size: 19px;
    font-weight: 800;
}

.sheet-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    gap: 10px;
    padding: 12px 18px calc(14px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--line);
}

.sheet-actions .btn {
    flex: 1;
}

@media (min-width: 640px) {
    .sheet {
        margin: auto;
        border-radius: 24px;
    }

    .sheet-actions {
        border-radius: 0 0 24px 24px;
        padding-bottom: 14px;
    }
}

/* 項目一覧（確認・詳細表示） */
.kv {
    margin: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    border-top: 1px solid var(--line);
}

.kv dt,
.kv dd {
    margin: 0;
    padding: 10px 2px;
    border-bottom: 1px solid var(--line);
}

.kv dt {
    padding-right: 16px;
    color: var(--ink-3);
    font-size: 14px;
    white-space: nowrap;
}

.kv dd {
    font-weight: 600;
    text-align: right;
    word-break: break-word;
}

.kv dd.is-ng {
    color: var(--ng);
}

.kv dd.is-warn {
    color: var(--warn);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}
