:root {
  --bg: #f4f1e8; --panel: #fffdf7; --panel2: #f8f4e8; --line: #ddd5c0; --text: #2b2a25; --muted: #7a7466;
  --accent: #2f6b3a; --accent2: #3f8a4c; --accent-soft: #e2efdf;
  --gold: #b88a1b; --gold-soft: #f6ecd0; --red: #b2402f; --red-soft: #f6e0db; --blue: #2c5f8a; --blue-soft: #dfeaf4;
  --shadow: 0 1px 3px rgba(60, 50, 20, .08);
  --tap: 44px;                 /* スマホのタップ領域の最小高さ */
  --bottombar: 0px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1d1a; --panel: #242722; --panel2: #2b2f29; --line: #3b4038; --text: #e8e6de; --muted: #a09c8e;
    --accent: #6fbf7c; --accent2: #5aa868; --accent-soft: #2c3d2d;
    --gold: #e0b44a; --gold-soft: #3d3522; --red: #e57a68; --red-soft: #432a25; --blue: #7fb0dc; --blue-soft: #243444;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.55 "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  padding-bottom: var(--bottombar); overflow-wrap: anywhere; }
button { font: inherit; color: inherit; touch-action: manipulation; }
select { font: inherit; padding: 2px 4px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text); max-width: 100%; }
a { color: var(--blue); }
.hidden { display: none !important; }
.mobile-only { display: none !important; }

/* ---------------- ヘッダー ---------------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--accent); color: #fff; box-shadow: var(--shadow); }
.brand { font-weight: 800; font-size: 16px; white-space: nowrap; }
.brand small { margin-left: 6px; font-weight: 400; opacity: .7; font-size: 11px; }
.status { display: flex; gap: 18px; flex: 1; flex-wrap: wrap; min-width: 0; }
.stat label { display: block; font-size: 10px; opacity: .75; }
.stat b { font-size: 15px; white-space: nowrap; }
.stat b.neg { color: #ffb4a8; }
.actions { display: flex; gap: 6px; }

.btn { border: 1px solid var(--line); background: var(--panel); padding: 5px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #fff; font-weight: 700; }
.btn.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
.btn.sm { padding: 2px 8px; font-size: 12px; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--red); }
.btn.wide { width: 100%; }
.topbar .btn:not(.primary):not(.ghost) { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.35); }

/* ---------------- 重要通知・カレンダー・確認事項 ---------------- */
.alerts:empty { display: none; }
.alerts { margin: 8px 16px 0; display: grid; gap: 6px; }
.alert { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border-radius: 8px;
  background: var(--gold-soft); border: 2px solid var(--gold); font-weight: 700; }
.alert .grow { flex: 1; min-width: 160px; }

.calendar { display: grid; grid-template-columns: repeat(12, 1fr); gap: 2px; padding: 8px 16px 0; }
.cal { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 3px 4px; font-size: 11px; min-height: 44px; }
.cal .m { font-weight: 700; }
.cal.now { outline: 2px solid var(--gold); background: var(--gold-soft); }
.cal.breed .m::after { content: " 種付"; color: var(--accent); font-size: 10px; font-weight: 400; }
.cal .ev { display: block; color: var(--blue); font-size: 10px; line-height: 1.25; }

.todo { margin: 8px 16px 0; padding: 8px 12px; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--gold); border-radius: 6px; }
.todo:empty { display: none; }
.todo summary { cursor: pointer; font-weight: 700; }
.todo ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------------- レイアウト ---------------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 12px; padding: 12px 16px 40px; }
.main { min-width: 0; }
.side { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; align-self: start; position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; }
.logbox summary { cursor: pointer; list-style: none; }
.logbox summary::-webkit-details-marker { display: none; }
.logbox #logLatest { display: none; }
.log div { padding: 3px 0; border-bottom: 1px dashed var(--line); font-size: 12px; }
.log .d { color: var(--muted); margin-right: 4px; font-size: 11px; }
.log .good { color: var(--accent); } .log .bad { color: var(--red); } .log .birth { color: var(--gold); font-weight: 700; }
.log .great { color: var(--gold); font-weight: 800; } .log .sale { color: var(--blue); }

.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--accent); flex-wrap: wrap; }
.tabs button { border: 0; background: var(--panel2); padding: 7px 14px; border-radius: 6px 6px 0 0; cursor: pointer; }
.tabs button.active { background: var(--accent); color: #fff; font-weight: 700; }
#view { padding-top: 10px; }
h2 { font-size: 15px; margin: 14px 0 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
h2 small { font-weight: 400; color: var(--muted); font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; }

/* ---------------- カード ---------------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr)); gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; box-shadow: var(--shadow); min-width: 0; }
.card.highlight { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold-soft); }
.card .title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.card .title b { font-size: 15px; }
.card .sub { color: var(--muted); font-size: 12px; }
.kv { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 1px 8px; font-size: 12.5px; margin: 6px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; }
/* 概要の項目（スマホでは2列） */
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 2px 10px; font-size: 12.5px; margin: 6px 0; }
.facts > div { display: flex; gap: 6px; align-items: baseline; min-width: 0; }
.facts .k { color: var(--muted); flex: none; min-width: 3.2em; }
.facts .full { grid-column: 1 / -1; }
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.tag { display: inline-block; padding: 0 6px; border-radius: 10px; font-size: 11px; background: var(--panel2); border: 1px solid var(--line); }
.tag.g { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.tag.r { background: var(--red-soft); border-color: transparent; color: var(--red); }
.tag.y { background: var(--gold-soft); border-color: transparent; color: var(--gold); }
.tag.b { background: var(--blue-soft); border-color: transparent; color: var(--blue); }
.grade { display: inline-block; min-width: 20px; text-align: center; font-weight: 800; border-radius: 4px; padding: 0 4px; background: var(--panel2); }
.grade.S { background: var(--gold); color: #fff; } .grade.A { background: var(--accent); color: #fff; }
.grade.B { background: var(--accent-soft); color: var(--accent); } .grade.D, .grade.E { color: var(--muted); }

.bar { height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.bar i { display: block; height: 100%; background: var(--accent2); }
.bar.full i { background: var(--gold); }

/* 予約ストリップ */
.reserve { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 6px 0; padding: 6px 8px; border-radius: 6px; background: var(--panel2); border: 1px dashed var(--line); font-size: 12.5px; }
.reserve.on { background: var(--blue-soft); border: 1px solid var(--blue); }
.reserve .label { font-weight: 700; }
.reserve.on .label { color: var(--blue); }
.reserve select { flex: 1; min-width: 150px; }
.ctrl { display: flex; align-items: center; gap: 6px; margin: 4px 0; font-size: 12.5px; }
.ctrl .k { color: var(--muted); flex: none; min-width: 3.2em; }
.ctrl select { flex: 1; min-width: 0; }
.outlook { font-size: 12px; margin: 4px 0; }

/* 折りたたみ詳細 */
details.more { margin-top: 6px; border-top: 1px dashed var(--line); padding-top: 4px; }
details.more > summary { cursor: pointer; color: var(--blue); font-size: 12.5px; padding: 4px 0; }
.outlist { display: grid; gap: 2px; font-size: 12px; margin: 4px 0; }
.outlist > div { display: grid; grid-template-columns: 82px minmax(0, 1fr) auto; gap: 6px; padding: 2px 0; border-bottom: 1px dotted var(--line); }
.outlist .p { text-align: right; white-space: nowrap; }

.scout { margin: 6px 0; padding: 10px 12px; border-radius: 8px; background: var(--gold-soft); border: 2px solid var(--gold); }
.scout p { margin: 4px 0; }
.scout .msg { font-size: 15px; }
.scout .price { font-size: 18px; font-weight: 800; }

/* 表（PC）とカード（スマホ）を切り替える */
table.t { width: 100%; border-collapse: collapse; background: var(--panel); font-size: 12.5px; }
table.t th, table.t td { border-bottom: 1px solid var(--line); padding: 5px 6px; text-align: left; vertical-align: top; }
table.t th { background: var(--panel2); font-weight: 700; position: sticky; top: 0; }
table.t td.num, table.t th.num { text-align: right; white-space: nowrap; }
.pos { color: var(--accent); } .neg { color: var(--red); }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; max-width: 100%; }
.mcards { display: none; }
.mcard { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; min-width: 0; }
.mcard .title { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.mcard .title b { font-size: 14px; }
.mcard.show { margin: 6px 0; }
.answer { margin: 10px 0; padding: 8px 10px; border: 2px solid var(--accent); border-radius: 8px; background: var(--accent-soft); }
.answer h2 { margin-top: 0; }
.answer .big { font-size: 18px; }
.answer .facts { margin: 2px 0 6px; }

/* ---------------- モーダル・確認 ---------------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { position: relative; background: var(--panel); border-radius: 10px; max-width: 980px; width: 100%; max-height: 90vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { position: absolute; right: 4px; top: 2px; z-index: 2; }
.modal-close { border: 0; background: var(--panel); border-radius: 50%; width: 40px; height: 40px; font-size: 24px; line-height: 1; cursor: pointer; }
.modal-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 18px 20px 8px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.modal-body h3:first-child { margin-top: 0; padding-right: 36px; }
.modal-foot { padding: 8px 20px 12px; border-top: 1px solid var(--line); }
.result-big { font-size: 28px; font-weight: 800; margin: 6px 0; }
.ledger td { padding: 1px 6px; font-size: 12px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

.ask { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.ask-box { background: var(--panel); border-radius: 12px; width: 100%; max-width: 440px; padding: 16px 18px; max-height: 90vh; overflow: auto; }
.ask-box h3 { margin: 0 0 8px; font-size: 16px; }
.ask-body { font-size: 13.5px; }
.ask-body p { margin: 4px 0; }
.ask-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.ask-btns .btn { min-height: var(--tap); font-size: 15px; }
.ask-btns .btn.danger-ok { background: var(--red); border-color: var(--red); color: #fff; }

.menu { position: fixed; right: 16px; top: 56px; z-index: 30; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow); min-width: 180px; }
.menu .btn { min-height: 40px; }
.debug { color: #a0f; font-size: 11px; }
.empty { padding: 20px; text-align: center; color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: 8px; }

.bottombar { display: none; }

/* ======================= スマホ（〜767px） ======================= */
@media (max-width: 767px) {
  :root { --bottombar: calc(68px + env(safe-area-inset-bottom)); }
  .pc-only { display: none !important; }
  .mobile-only { display: revert !important; }
  body { font-size: 14px; }

  /* ヘッダーは1行に圧縮 */
  .topbar { gap: 6px; padding: 6px 8px; padding-top: calc(6px + env(safe-area-inset-top)); flex-wrap: nowrap; }
  .brand { display: none; }
  .status { gap: 4px 10px; flex-wrap: nowrap; justify-content: space-between; }
  .stat label { font-size: 9px; line-height: 1.1; }
  .stat b { font-size: 13.5px; }
  .actions .btn.ghost { width: 40px; height: 40px; padding: 0; font-size: 20px; }

  /* 画面下の操作バー */
  .bottombar { display: grid; grid-template-columns: 1fr 1.25fr; gap: 8px; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line);
    box-shadow: 0 -2px 8px rgba(0,0,0,.08); }
  .bottombar .btn { min-height: 50px; font-size: 15px; border-radius: 10px; }
  .bottombar .btn.primary { font-size: 17px; }

  .alerts, .todo { margin: 8px 8px 0; }
  .alert .btn { min-height: var(--tap); }

  /* カレンダーは横スクロールの帯（ページは横にはみ出さない） */
  .calendar { display: flex; overflow-x: auto; gap: 3px; padding: 6px 8px 2px; scrollbar-width: none; overscroll-behavior-x: contain; }
  .calendar::-webkit-scrollbar { display: none; }
  .cal { flex: 0 0 76px; min-height: 40px; }

  .todo { padding: 6px 10px; font-size: 13px; }

  .layout { grid-template-columns: minmax(0, 1fr); padding: 8px 8px 16px; gap: 8px; }
  .side { position: static; max-height: none; padding: 0; }
  .logbox summary { padding: 10px 12px; min-height: var(--tap); }
  .logbox #logLatest { display: inline; }
  .logbox[open] #logLatest { display: none; }
  .log { padding: 0 12px 8px; max-height: 60vh; overflow: auto; }

  /* タブは3列×2段（隠れるタブを作らない） */
  .tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; border-bottom-width: 2px; }
  .tabs button { min-height: 40px; padding: 6px 4px; border-radius: 6px 6px 0 0; font-size: 13.5px; }

  h2 { margin: 12px 0 6px; }
  .cards { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .card { padding: 10px; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* ボタンはタップしやすく */
  .btn.sm { min-height: 38px; padding: 6px 12px; font-size: 13.5px; }
  .card .row .btn { flex: 1 1 auto; }
  .ctrl select, .reserve select { min-height: 38px; font-size: 14px; }
  details.more > summary { min-height: 36px; display: flex; align-items: center; }

  /* 表はカードに */
  .tablewrap.pc-table { display: none; }
  .mcards { display: grid; gap: 6px; }

  /* モーダルは画面いっぱいのシート */
  .modal { padding: 0; align-items: flex-end; }
  .modal-box { max-width: none; width: 100%; max-height: calc(100dvh - 16px - env(safe-area-inset-top)); border-radius: 14px 14px 0 0; }
  .modal-body { padding: 14px 12px 8px; }
  .modal-foot { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { min-height: var(--tap); font-size: 15px; }
  .modal-close { width: 44px; height: 44px; }
  .result-big { font-size: 24px; }
  .modal-body .cards { grid-template-columns: minmax(0, 1fr); }
  .modal-body .btn { min-height: var(--tap); }

  .ask { align-items: flex-end; padding: 0; }
  .ask-box { max-width: none; border-radius: 14px 14px 0 0; padding: 16px 14px calc(14px + env(safe-area-inset-bottom)); }
  .ask-btns .btn { min-height: 50px; }

  .menu { right: 8px; top: 52px; }
}
@media (max-width: 359px) {
  .stat b { font-size: 12.5px; }
  .status { gap: 2px 6px; }
}
/* スカウトの受ける/断るは離して大きく（誤操作防止。どちらも確認シートが出る） */
.scout .row { gap: 16px; }
.scout .row .btn { flex: 1; min-height: var(--tap); font-size: 15px; }
/* 入札の経過 */
details.auction { margin: 6px 0; border: 1px dashed var(--line); border-radius: 6px; padding: 4px 8px; }
details.auction > summary { cursor: pointer; color: var(--blue); font-size: 12.5px; padding: 4px 0; }
ol.bids { margin: 4px 0; padding-left: 22px; font-size: 12.5px; max-height: 50vh; overflow: auto; }
ol.bids li.drop { color: var(--muted); }
ol.bids li.heat { color: var(--red); font-weight: 700; }
ol.bids li.hammer { color: var(--accent); font-weight: 800; }
ol.bids li.join { color: var(--blue); }
ol.bids li.open, ol.bids li.down, ol.bids li.unsold { color: var(--muted); font-style: italic; }
/* 配合理論・血統表 */
.theory { margin: 4px 0 6px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.theory details.more { width: 100%; margin-top: 2px; }
.theory ul { margin: 2px 0; padding-left: 18px; }
tr.theory-row td { background: var(--panel2); padding-top: 2px; }
table.pedigree { font-size: 12px; table-layout: fixed; }
table.pedigree td { vertical-align: middle; border: 1px solid var(--line); padding: 3px 5px; overflow-wrap: anywhere; }
table.pedigree td.g1 { font-weight: 700; width: 30%; }
table.pedigree td.g2 { width: 33%; }
