/* ==========================================================
 * マグネットタッチ（apps/magnet） style.css
 * 左に操作パネル（いちばん上の行は 🏠 もどる の場所）・右に写真
 * ========================================================== */
:root {
    --main: #0284c7;
    --main-dark: #075985;
    --bg: #e0f2fe;
    --panel: #ffffff;
    --text: #1e293b;
    --sub: #64748b;
    --on: #dc2626;
    --off: #2563eb;
    --teacher: #f59e0b;
    --danger: #e11d48;
    --font: 'M PLUS Rounded 1c', 'Gowun Dodum', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'BIZ UDPGothic', 'Meiryo', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

button { font-family: var(--font); }

/* UI要塞化 */
.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    z-index: -1 !important;
    position: absolute !important;
}

#app {
    position: relative;
    height: 100dvh;
    display: grid;
    grid-template-columns: clamp(260px, 27vw, 330px) 1fr;
    overflow: hidden;
}

/* ---------- 左のパネル ---------- */
#panel {
    position: relative;
    background: var(--panel);
    border-right: 4px solid var(--main);
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 14px 12px;
    padding-left: calc(14px + env(safe-area-inset-left, 0px));
    overflow-y: auto;
    z-index: 10;
}
.panel-top-space { flex: 0 0 52px; }

.app-title {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--main-dark);
    line-height: 1.3;
}

.panel-body {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.guide {
    margin: 0;
    font-size: 0.98rem;
    font-weight: 700;
    line-height: 1.55;
    background: #f0f9ff;
    border: 2px solid #bae6fd;
    border-radius: 12px;
    padding: 8px 10px;
}
.guide.small { font-size: 0.9rem; }

.count-box {
    background: #fff7ed;
    border: 3px solid #fdba74;
    border-radius: 14px;
    padding: 8px 10px;
}
.count-main {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-weight: 800;
    font-size: 1.05rem;
}
.count-main b { font-size: 2rem; color: var(--on); }
.count-sub {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    font-weight: 700;
    font-size: 0.95rem;
    margin-top: 2px;
}
.count-sub b { font-size: 1.2rem; }
.mark-on b { color: var(--on); }
.mark-off b { color: var(--off); }

.btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 6px 10px;
    border: none;
    border-radius: 14px;
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.3;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.18);
}
.btn:active { transform: translateY(3px); box-shadow: none; }
.btn-main { background: var(--main); color: #fff; min-height: 56px; font-size: 1.1rem; }
.btn-sub { background: #e2e8f0; color: var(--text); }
.btn-finish { background: #16a34a; color: #fff; min-height: 60px; font-size: 1.1rem; }
.btn-reveal { background: #fef3c7; color: #92400e; border: 2px solid #f59e0b; margin: 8px auto 0; min-width: 220px; }
.sum-rest { margin-top: 10px; background: #f8fafc; border: 3px dashed #cbd5e1; border-radius: 14px; padding: 8px; }
.sum-rest h3 { margin: 0 0 6px; font-size: 1.05rem; color: #475569; }
.sum-rest .sum-item canvas { opacity: 0.45; filter: grayscale(40%); }
.sum-rest .sum-item .q { font-weight: 900; color: #64748b; }
.sum-rest-msg { margin: 8px 0 0; font-weight: 800; color: #b45309; }
.sum-all { margin: 10px 0 0; font-weight: 900; font-size: 1.2rem; color: #4f46e5; }
.sum-item.revealed { border: 2px dashed #94a3b8; }
.btn-teacher { background: #fef3c7; color: #92400e; border: 2px solid var(--teacher); margin-top: 6px; }
.btn-danger { background: #ffe4e6; color: var(--danger); }
.btn-danger.armed { background: var(--danger); color: #fff; }
.file-btn { cursor: pointer; }

.row2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
.row2 .btn { font-size: 0.9rem; }

.type-pick {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
.type-btn {
    min-height: 52px;
    border-radius: 12px;
    border: 3px solid #cbd5e1;
    background: #f8fafc;
    font-size: 0.95rem;
    font-weight: 800;
    cursor: pointer;
    color: var(--text);
}
.type-btn[data-type="iron"].active { border-color: var(--on); background: #fee2e2; color: var(--on); }
.type-btn[data-type="other"].active { border-color: var(--off); background: #dbeafe; color: var(--off); }

.small-note {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--sub);
    line-height: 1.5;
}

.lang-slot {
    margin-top: auto;
    padding-top: 8px;
    display: flex;
    justify-content: center;
}

/* ---------- 右の写真 ---------- */
#stage-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    padding-right: calc(12px + env(safe-area-inset-right, 0px));
    overflow: hidden;
}
#stage {
    position: relative;
    border-radius: 14px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 6px 20px rgba(2, 132, 199, 0.25);
    touch-action: none;
    cursor: none;
}
#stage.edit { cursor: crosshair; }
#photo-canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}
#mark-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.mark {
    position: absolute;
    transform: translate(-50%, -50%) scale(0);
    font-size: clamp(42px, 7vw, 84px);
    font-weight: 900;
    line-height: 1;
    animation: pop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    text-shadow: 0 2px 0 #fff, 0 0 8px #fff;
}
@keyframes pop {
    0% { transform: translate(-50%, -50%) scale(0); }
    60% { transform: translate(-50%, -50%) scale(1.2); }
    100% { transform: translate(-50%, -50%) scale(1); }
}
.magnet {
    position: absolute;
    left: 0;
    top: 0;
    width: clamp(64px, 9vw, 96px);
    height: clamp(64px, 9vw, 96px);
    transform: translate(-50%, -100%);
    pointer-events: none;
    filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.3));
    z-index: 5;
}
.magnet.clink { animation: clink 0.3s ease; }
@keyframes clink {
    0% { transform: translate(-50%, -100%) rotate(0deg); }
    30% { transform: translate(-50%, -96%) rotate(-8deg); }
    60% { transform: translate(-50%, -98%) rotate(6deg); }
    100% { transform: translate(-50%, -100%) rotate(0deg); }
}

/* ---------- まとめ（小窓） ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 8000;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-box {
    position: relative;
    width: min(860px, 96vw);
    max-height: 92dvh;
    overflow-y: auto;
    background: #fff;
    border: 5px solid #facc15;
    border-radius: 22px;
    padding: 14px 18px 16px;
    text-align: center;
}
.clear-head h2 { margin: 0; font-size: 2rem; color: #4f46e5; }
.clear-head p { margin: 2px 0 6px; font-weight: 800; color: var(--sub); }
.clear-emoji { font-size: 3rem; line-height: 1; }
.summary-title { margin: 4px 0 8px; font-size: 1.3rem; color: var(--main-dark); }
.summary-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.sum-col {
    border-radius: 14px;
    padding: 8px;
    min-height: 120px;
}
.sum-col h3 { margin: 0 0 6px; font-size: 1.05rem; }
.sum-on { background: #fef2f2; border: 3px solid #fca5a5; }
.sum-on h3 { color: var(--on); }
.sum-off { background: #eff6ff; border: 3px solid #93c5fd; }
.sum-off h3 { color: var(--off); }
.sum-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    gap: 6px;
}
.sum-item {
    background: #fff;
    border-radius: 10px;
    padding: 4px;
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1.3;
}
.sum-item canvas {
    display: block;
    width: 100%;
    height: 64px;
    object-fit: contain;
}
.sum-item.untouched { opacity: 0.45; }
.sum-empty { font-size: 0.9rem; color: var(--sub); font-weight: 700; grid-column: 1 / -1; padding: 12px 0; }
.sum-ask { margin: 10px 0 6px; font-weight: 800; }
.modal-btns {
    display: flex;
    gap: 10px;
    justify-content: center;
}
.modal-btns .btn { min-width: 180px; }

/* ---------- 小さな お知らせ ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 8500;
    background: rgba(15, 23, 42, 0.88);
    color: #fff;
    padding: 10px 20px;
    border-radius: 30px;
    font-weight: 800;
    max-width: 90vw;
    text-align: center;
}

/* ---------- せまい画面（たて） ---------- */
@media (max-width: 800px) {
    #app {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }
    #panel {
        border-right: none;
        border-bottom: 4px solid var(--main);
        max-height: 46dvh;
    }
    .summary-cols { grid-template-columns: 1fr; }
}
@media (max-height: 700px) {
    .guide { font-size: 0.88rem; padding: 6px 8px; }
    .count-main b { font-size: 1.6rem; }
    .btn { min-height: 44px; font-size: 0.92rem; }
    .btn-main { min-height: 48px; }
    .app-title { font-size: 1.15rem; }
}

/* P1：小さい スマホの よこ（667×375）。はばの @media（800 以下）で 上下ならびに なり、写真が 238px・いちばん 小さい ものが 13px だった
   → よこの 低い 画面は 左右ならびに もどす（はばの @media より あとに 書く） */
@media (max-height: 560px) and (orientation: landscape) {
    #app { grid-template-columns: clamp(220px, 32vw, 300px) 1fr; grid-template-rows: none; }
    #panel { border-bottom: none; border-right: 4px solid var(--main); max-height: none; overflow-y: auto; }
}
