/* 百人一首かるた: Bootstrap で賄えない部分だけ（全画面の段組み・札の格子・読み札の重ね表示）。
   段組みは responsive.css と同じ考え方: body を 100dvh の縦の列にし、
   場（札の格子）が残りを埋める。札の大きさは karuta.js が場の広さから決める。 */

.karuta-body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: #1f3b2c;
}
.karuta-nav { flex: 0 0 auto; padding-top: .25rem; padding-bottom: .25rem; }
.karuta-main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.karuta-scroll { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; }
.karuta-narrow { max-width: 820px; }

/* ---------- 対戦画面: 場（左）＋読み手と点数（右） ---------- */
.karuta-game {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    gap: 6px;
    padding: 6px;
    padding-left: max(6px, env(safe-area-inset-left));
    padding-right: max(6px, env(safe-area-inset-right));
}
.karuta-stage { position: relative; flex: 1 1 auto; min-width: 0; min-height: 0; }
.karuta-field-wrap {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    overflow-x: hidden;
    border-radius: .5rem;
    background: radial-gradient(ellipse at center, #d9c9a0 0%, #c8b27f 100%);   /* 畳の色 */
    padding: 6px;
}
.karuta-field {
    display: grid;
    gap: var(--gap, 6px);
    grid-template-columns: repeat(var(--cols, 5), var(--card-w, 90px));
    justify-content: center;
    align-content: center;
    min-height: 100%;
}
.karuta-side {
    flex: 0 0 clamp(190px, 26vw, 340px);
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    color: #f8f9fa;
}

/* ---------- 取り札 ---------- */
.tori {
    width: var(--card-w, 90px);
    aspect-ratio: 200 / 280;
    padding: 0;
    border: 0;
    border-radius: 6%;
    background: transparent;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .35);
    touch-action: manipulation;
    transition: transform .12s ease-out, opacity .35s ease-in;
    cursor: pointer;
}
.tori img { width: 100%; height: 100%; display: block; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.tori:hover { transform: translateY(-2px); }
.tori:focus-visible { outline: 3px solid #ffc107; outline-offset: 2px; }
.tori-empty { width: var(--card-w, 90px); aspect-ratio: 200 / 280; }
.tori.is-taken { transform: scale(1.12); opacity: 0; pointer-events: none; box-shadow: 0 0 0 4px #198754; }
.tori.is-taken-other { box-shadow: 0 0 0 4px #0d6efd; }
.tori.is-flowed { opacity: 0; pointer-events: none; transition-duration: .8s; }
.tori.is-otetsuki { animation: karuta-shake .4s; box-shadow: 0 0 0 4px #dc3545; }
.tori-fallback {
    width: 100%; height: 100%; display: flex; flex-direction: column; flex-wrap: wrap-reverse;
    writing-mode: vertical-rl; font-weight: 800; font-size: calc(var(--card-w, 90px) / 5);
    background: #fbf6e6; border: 4px solid #2f6b45; border-radius: 6%; color: #1e1e1e; line-height: 1.1;
}
@keyframes karuta-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px) rotate(-2deg); }
    75% { transform: translateX(5px) rotate(2deg); }
}

/* ---------- 読み手 ---------- */
.karuta-reader .card-body { min-height: 5.2rem; }
.karuta-ticker {
    font-weight: 700;
    font-size: clamp(.95rem, 1.6vw, 1.35rem);
    letter-spacing: .05em;
    min-height: 1.6em;
    word-break: break-all;
}
.karuta-ticker-shimo { color: #6c757d; }
.karuta-ticker .kimariji { color: #dc3545; text-decoration: underline; }
.karuta-reader-art { float: right; height: 7.5rem; margin-left: .4rem; border-radius: .3rem; }
.karuta-scores .list-group-item { padding: .3rem .5rem; }
.karuta-scores .me { background: #fff3cd; }
.karuta-avatar { width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto; background: #fff; }

/* ---------- 取られた札の読み札（場の上に重ねる。タップは下へ通す） ---------- */
.karuta-yomi {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    display: flex;
    justify-content: center;
    padding: 4px;
}
.karuta-yomi.d-none { display: none; }
.karuta-yomi-card { max-width: 640px; width: 100%; background: rgba(255, 255, 255, .96); }
.karuta-yomi-art { height: min(38vh, 240px); aspect-ratio: 250 / 390; border-radius: .4rem; flex: 0 0 auto; }
.karuta-yomi-text { min-width: 0; }
.karuta-yomi-poem { font-size: 1.1rem; font-weight: 700; }
.karuta-yomi-poem .kimariji { color: #dc3545; }

.karuta-mini-row { display: flex; flex-wrap: wrap; gap: 4px; }
.karuta-mini-row img { width: 42px; aspect-ratio: 200 / 280; }

/* ---------- 縦向きのスマホ: 読み手を上、場を下に ---------- */
@media (orientation: portrait) and (max-width: 767.98px) {
    .karuta-game { flex-direction: column; }
    .karuta-side { flex: 0 0 auto; max-height: 38%; }
    .karuta-reader-art { height: 4.5rem; }
}

/* ---------- 横向きのスマホ（高さが低い） ---------- */
@media (max-height: 500px) {
    .karuta-nav .navbar-brand { font-size: 1rem; }
    .karuta-game { padding-top: 4px; padding-bottom: 4px; gap: 4px; }
    .karuta-field-wrap { padding: 4px; }
    .karuta-side { flex-basis: clamp(170px, 28vw, 260px); gap: 4px; }
    .karuta-ticker { font-size: .9rem; }
    .karuta-reader-art { height: 4.8rem; }
    .karuta-reader .card-body { min-height: 3.6rem; }
    .karuta-yomi-art { height: min(52vh, 200px); }
    .karuta-yomi-card .card-body { padding: .5rem; gap: .5rem !important; }
    .karuta-yomi-poem { font-size: .95rem; }
    .karuta-yomi-text .small { font-size: .75rem; }
}

/* ---------- 最初の画面: タイトル画面と同じパネル（css/title.css, js/panel-select.js） ---------- */
/* showView('setup') で body に karuta-at-title（と title-screen の背景）が付く。 */
.karuta-at-title .karuta-game-only { display: none !important; }
.karuta-body:not(.karuta-at-title) .karuta-title-only { display: none !important; }
