:root {
  --bg: #f1efe8;
  --card: #ffffff;
  --ink: #1d1d1b;
  --muted: #6b6a64;
  --line: #e2ddd0;
  --felt: #1f5f4a;
  --felt-soft: #e3efe9;
  --accent: #1f5f4a;
  --accent-ink: #ffffff;
  --warn-bg: #fff3e0;
  --warn-ink: #8a4b00;
  --bad-bg: #fdecec;
  --bad-ink: #a61b1b;
  --good-bg: #e6f4ea;
  --good-ink: #17643a;
  --chip: #f5f3ec;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121513;
    --card: #1c201e;
    --ink: #ecebe6;
    --muted: #a3a29b;
    --line: #2f3532;
    --felt: #2c7a60;
    --felt-soft: #1e3029;
    --accent: #3a9a7a;
    --accent-ink: #0d1411;
    --warn-bg: #3a2a12;
    --warn-ink: #ffcf8a;
    --bad-bg: #3a1a1a;
    --bad-ink: #ffb0b0;
    --good-bg: #173022;
    --good-ink: #9fe0b8;
    --chip: #262b28;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121513; --card: #1c201e; --ink: #ecebe6; --muted: #a3a29b; --line: #2f3532;
  --felt: #2c7a60; --felt-soft: #1e3029; --accent: #3a9a7a; --accent-ink: #0d1411;
  --warn-bg: #3a2a12; --warn-ink: #ffcf8a; --bad-bg: #3a1a1a; --bad-ink: #ffb0b0;
  --good-bg: #173022; --good-ink: #9fe0b8; --chip: #262b28; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }

.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--felt); color: #fff;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 0;
}
.top h1 { margin: 0 0 6px; font-size: 17px; font-weight: 700; letter-spacing: .04em; }
.tabs { display: flex; gap: 4px; }
.tabs button {
  flex: 1; border: 0; background: transparent; color: rgba(255,255,255,.75);
  padding: 8px 0 10px; font-weight: 600; border-bottom: 3px solid transparent;
}
.tabs button.on { color: #fff; border-bottom-color: #f2c94c; }

main { max-width: 560px; margin: 0 auto; padding: 12px 16px 24px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px; margin-bottom: 12px;
}
h2 { font-size: 15px; margin: 0 0 8px; }
h3 { font-size: 14px; margin: 14px 0 6px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.small-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.row-head { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; font-size: 14px; }

/* 牌 */
.tile-svg { display: block; width: 100%; height: auto; }
.tiles { display: flex; flex-wrap: wrap; gap: 2px; min-height: 44px; align-items: flex-end; }
.tiles .t { width: calc((100% - 26px) / 14); max-width: 40px; border: 0; padding: 0; background: none; }
.tiles.hand { padding: 6px; background: var(--felt-soft); border-radius: 10px; min-height: 58px; }
.tiles.hand .t.new { outline: 2px solid #f2c94c; outline-offset: 1px; border-radius: 4px; }
.tiles.win { min-height: 50px; width: 44px; padding: 4px; background: var(--felt-soft); border-radius: 10px; justify-content: center; align-items: center; }
.tiles.win .t { width: 34px; }
.tiles.mini { min-height: 34px; }
.tiles.mini .t { width: 26px; }
.tiles .empty { color: var(--muted); font-size: 12px; align-self: center; padding: 0 6px; }
.slot-wrap { min-width: 0; }
.slot-wrap.grow { flex: 1; }
.sub-row { display: flex; gap: 10px; margin-top: 8px; }
.melds { display: flex; flex-wrap: wrap; gap: 6px; min-height: 50px; padding: 4px 6px; background: var(--felt-soft); border-radius: 10px; align-items: center; }
.meld { display: flex; gap: 1px; border: 0; padding: 2px; background: none; border-radius: 6px; }
.meld .t { width: 22px; }
.meld .t.side { transform: rotate(-90deg) translateX(-3px); margin: 0 4px; }
.meld .t.back svg rect:nth-child(2) { fill: #2f6f9f; }
.meld-tag { font-size: 10px; color: var(--muted); display: block; text-align: center; }
.target-on { box-shadow: 0 0 0 2px var(--accent); }

/* パレット */
.palette-card { position: sticky; bottom: 0; z-index: 5; box-shadow: 0 -4px 14px rgba(0,0,0,.08); }
.targets { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.targets button, .meld-types button, .chip {
  border: 1px solid var(--line); background: var(--chip); border-radius: 999px;
  padding: 5px 12px; font-size: 13px; font-weight: 600;
}
.targets button.on, .meld-types button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.meld-types { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.meld-types .hint { margin: 0; flex-basis: 100%; }
.palette { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; }
.palette .t { border: 0; padding: 0; background: none; }
.palette .t:disabled { opacity: .25; }
.palette .t:active:not(:disabled) { transform: translateY(1px) scale(.96); }
.palette .gap { visibility: hidden; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.ghost { border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 6px 12px; font-size: 13px; }
.ghost.danger { color: var(--bad-ink); }

/* 条件 */
.cond { display: flex; flex-direction: column; gap: 8px; }
.cond-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cond-row .lbl { width: 96px; font-size: 13px; color: var(--muted); flex-shrink: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: 0; background: var(--chip); padding: 6px 11px; font-size: 13px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.seg button:disabled { opacity: .4; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.stepper button { border: 0; background: var(--chip); width: 36px; height: 32px; font-size: 16px; }
.stepper output { min-width: 32px; text-align: center; font-weight: 700; }
.dora-wrap { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cond-row .full { flex-basis: 100%; margin: 0; }
.dora-list { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.dora-list .empty { color: var(--muted); font-size: 12px; }
.dora-pair { display: flex; align-items: center; gap: 3px; border: 1px solid var(--line); background: var(--chip); border-radius: 8px; padding: 3px 6px; }
.dora-pair .t { width: 24px; display: block; }
.dora-pair .arrow { font-size: 12px; color: var(--muted); }
.dora-pair .cap { font-size: 10px; color: var(--muted); display: block; text-align: center; line-height: 1.2; }
.dora-sum { font-size: 13.5px; font-weight: 700; }
.dora-sum:empty { display: none; }
.tiles .t.is-dora { position: relative; }
.tiles .t.is-dora::after {
  content: 'ドラ'; position: absolute; left: 50%; top: -9px; transform: translateX(-50%);
  background: #f2c94c; color: #3a2d00; font-size: 8.5px; font-weight: 800; line-height: 1; padding: 2px 3px; border-radius: 4px; white-space: nowrap;
}
.tiles.hand { padding-top: 12px; }
.palette-guide { margin: 0 0 8px; font-size: 13px; font-weight: 600; }
.palette-guide.dora { background: #fff1c2; color: #5a4100; padding: 8px 10px; border-radius: 8px; }
.more { margin-top: 10px; }
.more summary { font-size: 13px; color: var(--muted); padding: 4px 0; }
.more .cond { margin-top: 8px; }

/* 結果 */
.result:empty { display: none; }
.big { font-size: 30px; font-weight: 800; letter-spacing: .01em; line-height: 1.2; }
.limit { display: inline-block; background: #f2c94c; color: #3a2d00; border-radius: 6px; padding: 1px 8px; font-size: 13px; font-weight: 700; margin-right: 6px; vertical-align: middle; }
.pay { margin: 4px 0 10px; font-size: 14px; }
.hanfu { color: var(--muted); font-size: 13px; }
.yaku-list { list-style: none; padding: 0; margin: 8px 0; border-top: 1px solid var(--line); }
.yaku-list li { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.yaku-list .nm { font-weight: 600; }
.yaku-list .ds { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.yaku-list .hn { white-space: nowrap; font-weight: 700; }
.msg { border-radius: 10px; padding: 10px 12px; margin: 8px 0; font-size: 14px; }
.msg.bad { background: var(--bad-bg); color: var(--bad-ink); }
.msg.warn { background: var(--warn-bg); color: var(--warn-ink); }
.msg.good { background: var(--good-bg); color: var(--good-ink); }
.msg.info { background: var(--felt-soft); }
.msg b { font-weight: 800; }
details.fu summary { font-size: 13px; color: var(--muted); }
table.fu-table, table.pts { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
table.fu-table td, table.pts td, table.pts th { border-bottom: 1px solid var(--line); padding: 5px 4px; }
table.fu-table td:last-child { text-align: right; white-space: nowrap; }
table.pts th { text-align: right; font-weight: 600; color: var(--muted); }
table.pts td { text-align: right; font-variant-numeric: tabular-nums; }
table.pts td:first-child, table.pts th:first-child { text-align: left; }
.pts-wrap { overflow-x: auto; }

.inline-tiles { display: inline-flex; gap: 1px; vertical-align: middle; }
.inline-tiles .t { width: 22px; display: inline-block; }
.cand { border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; margin: 8px 0; }
.cand-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.cand-name { font-weight: 700; }
.badge { font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.badge.done { background: var(--good-bg); color: var(--good-ink); }
.badge.near { background: #fff1c2; color: #6b4e00; }
.badge.far { background: var(--chip); color: var(--muted); }
.cand-note { font-size: 13px; margin-top: 2px; }
.cand-tiles { font-size: 12.5px; color: var(--muted); margin-top: 4px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.wait-row, .disc-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.wait-row .t, .disc-row .t { width: 28px; flex-shrink: 0; }
.wait-info, .disc-info { font-size: 13px; }
.wait-info b, .disc-info b { font-size: 14px; }

/* 役一覧 */
.ylist { list-style: none; padding: 0; margin: 0; }
.ylist li { padding: 9px 0; border-bottom: 1px solid var(--line); }
.ylist .top-line { display: flex; justify-content: space-between; gap: 8px; }
.ylist .nm { font-weight: 700; }
.ylist .hn { font-size: 13px; color: var(--muted); white-space: nowrap; }
.ylist .ds { font-size: 13px; margin: 2px 0 4px; }
.ylist .ex { display: flex; gap: 1px; flex-wrap: wrap; }
.ylist .ex .t { width: 19px; }
.ylist .ex .sp { width: 6px; }
.ylist .ycard { padding: 11px 0; }
.ylist .ycard:last-child { border-bottom: 0; }
.ylist .yomi { display: block; font-size: 11.5px; color: var(--muted); }
.ylist .beg { display: inline-block; margin-left: 6px; font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: var(--good-bg); color: var(--good-ink); vertical-align: 2px; }
.ylist .hn { text-align: right; }
.ylist .hn b { display: block; font-size: 15px; color: var(--ink); }
.ylist .hn small { display: block; font-size: 11px; }
.ylist .hn small.ng { color: var(--bad-ink); }
.ylist .ex-none { font-size: 12px; color: var(--muted); }
.ylist .ex-none:empty { display: none; }
.ylist .tip { margin-top: 6px; font-size: 12.5px; background: var(--felt-soft); border-radius: 8px; padding: 6px 8px; }
.ylist .freq { display: block; font-size: 11px; color: #b8860b; letter-spacing: .02em; }
.filters { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; margin: 0 -2px; -webkit-overflow-scrolling: touch; }
.filters button { flex-shrink: 0; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; }
.filters button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tabs button { font-size: 14px; }

.foot { text-align: center; font-size: 11.5px; color: var(--muted); padding: 0 16px 24px; }
[hidden] { display: none !important; }

@media (min-width: 520px) {
  .palette { gap: 5px; }
}

/* ドラッグ */
#palette .t, #hand .t, #win .t { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.drag-ghost { position: fixed; left: 0; top: 0; width: 40px; z-index: 100; pointer-events: none; filter: drop-shadow(0 6px 10px rgba(0,0,0,.35)); }
.drag-src { opacity: .35; }
body.dragging { -webkit-user-select: none; user-select: none; }
body.drag-in [data-drop="hand"], body.drag-in [data-drop="win"], body.drag-in [data-drop="meld"],
body.drag-out [data-drop="hand"], body.drag-out [data-drop="win"] { outline: 2px dashed var(--accent); outline-offset: 2px; }
body.drag-in .cond-row[data-drop] { outline: 2px dashed var(--accent); outline-offset: 3px; border-radius: 8px; }
body.drag-out [data-drop="trash"] { outline: 2px dashed var(--bad-ink); outline-offset: 2px; }
[data-drop].drop-hover { background-color: color-mix(in srgb, var(--accent) 22%, transparent) !important; }
