:root {
  --bg: #11161c; --panel: #1a222b; --panel2: #222c37; --line: #2f3b48;
  --text: #e8edf2; --muted: #8a97a6; --accent: #f2b33d; --good: #3fbf7f; --bad: #e5534b;
  --court: #c98b4a; --court2: #b57a3d;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif; }
button { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #1a1205; border-color: var(--accent); font-weight: 700; }
button.danger { border-color: var(--bad); color: #ffb3ae; }
button:disabled { opacity: .4; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.hidden { display: none !important; }
.small { font-size: 12px; color: var(--muted); }
.screen { min-height: 100%; }

/* lobby */
#lobby, #waitroom { display: flex; align-items: center; justify-content: center; padding: 16px; }
.lobby-box { width: 100%; max-width: 460px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.lobby-box h1 { margin: 0; font-size: 30px; letter-spacing: 2px; font-weight: 900; }
.lobby-box h1 span { color: var(--accent); margin: 0 6px; }
.lobby-box label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.lobby-box input, .lobby-box select { width: 100%; }
.sub { margin: 0; color: var(--muted); }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; min-width: 0; }
.join input { text-transform: uppercase; letter-spacing: 3px; text-align: center; }
.bigcode { font-size: 48px; font-weight: 900; letter-spacing: 8px; color: var(--accent); text-align: center; user-select: all; }

/* builder */
#builder { display: flex; flex-direction: column; height: 100vh; }
.bhead { display: flex; gap: 6px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.bhead #bName { width: 180px; }
.bcount b.ok { color: var(--good); } .bcount b.bad { color: var(--bad); }
.bbody { display: grid; grid-template-columns: 1fr 340px; flex: 1; min-height: 0; }
.bpool { display: flex; flex-direction: column; min-height: 0; }
.bfilters { display: flex; gap: 6px; padding: 8px 12px; flex-wrap: wrap; }
.bfilters #fText { flex: 1 1 220px; }
.pool { flex: 1; overflow-y: auto; display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 12px; align-content: flex-start; }
.pool .card { cursor: pointer; }
.pool .card:hover { box-shadow: 0 0 0 2px var(--accent); }
.bdeck { border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 8px; }
.drow { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-left: 4px solid var(--sc); background: var(--panel2); margin-bottom: 4px; border-radius: 4px; }
.drow .dn { font-weight: 800; width: 20px; text-align: right; }
.drow .dname { flex: 1; cursor: pointer; font-size: 13px; }
.drow .dname small { color: var(--muted); display: block; font-size: 10px; }
.drow button { padding: 0 8px; }
textarea.io { width: 100%; min-height: 260px; font-family: monospace; }
.info { background: #fff; color: #333; border-radius: 50%; width: 16px; height: 16px; display: inline-block; text-align: center; line-height: 16px; font-size: 11px; }

/* game layout */
#game { display: grid; grid-template-columns: 1fr 300px; grid-template-rows: auto 1fr; height: 100vh; }
#topbar { grid-column: 1 / -1; display: flex; gap: 16px; align-items: center; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#topbar .score { font-weight: 800; font-size: 16px; }
#topbar .score b { color: var(--accent); }
#topbar .phase { color: var(--muted); }
#board { overflow-y: auto; padding: 10px 16px; display: flex; flex-direction: column; gap: 8px; }
#logPanel { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
#logPanel h3 { margin: 0; padding: 10px 12px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); }
#log { overflow-y: auto; padding: 8px 12px; font-size: 12px; color: #c4ceda; flex: 1; }
#log div { padding: 2px 0; border-bottom: 1px dashed #26303b; }
#log div.set { color: var(--accent); font-weight: 700; }
#log div.lost { color: #ff9b94; }

.side { background: linear-gradient(var(--court), var(--court2)); border-radius: 12px; padding: 8px; display: grid; grid-template-columns: 160px 1fr; gap: 8px; }
.pinfo { background: rgba(0,0,0,.35); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.pinfo .pname { font-weight: 800; font-size: 14px; }
.pinfo .turnflag { color: var(--accent); font-weight: 700; }
.pinfo .piles { display: flex; gap: 6px; flex-wrap: wrap; }
.pile { background: rgba(0,0,0,.35); border-radius: 6px; padding: 2px 6px; }
.pile.click { cursor: pointer; text-decoration: underline dotted; }
.notes div { background: #fff6d6; color: #333; border-radius: 4px; padding: 2px 4px; margin-top: 2px; }
.notes a { cursor: pointer; color: #a00; font-weight: 700; }
.setcards { display: inline-flex; gap: 3px; vertical-align: middle; }
.setcards i { width: 12px; height: 18px; border-radius: 3px; background: repeating-linear-gradient(45deg, #2a3646, #2a3646 3px, #3a4a5e 3px, #3a4a5e 6px); border: 1px solid #556; display: inline-block; }
.court { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.slot { background: rgba(255,255,255,.12); border: 1px dashed rgba(255,255,255,.4); border-radius: 10px; padding: 4px; min-height: 112px; display: flex; flex-direction: column; gap: 3px; }
.slot .slab { font-size: 10px; font-weight: 800; letter-spacing: 1px; color: rgba(0,0,0,.65); }
.slot.active { border: 2px solid var(--accent); background: rgba(242,179,61,.18); }
.slot .sides { display: flex; gap: 3px; }
.guts { font-size: 11px; color: rgba(0,0,0,.75); cursor: pointer; text-decoration: underline dotted; }

#midline { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 6px; background: #fff; color: #222; border-radius: 6px; font-weight: 700; min-height: 36px; flex-wrap: wrap; }
#midline .big { font-size: 20px; }
#midline .tag { background: #e5e5e5; color: #222; }
#midline .tag.dark { background: #222; color: #fff; }
#midline .tag.warn { background: var(--bad); color: #fff; }
#midline .proj { font-weight: 600; color: #444; }
#midline .proj.ok { color: #1c8a52; } #midline .proj.ko { color: #c0362e; }

#actions { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-height: 56px; }
#actions .msg { flex: 1 1 260px; }
#actions .msg small { color: var(--muted); display: block; }
#hand { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 12px; min-height: 200px; }
#tools { display: flex; flex-wrap: wrap; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
#tools:empty { display: none; }
.tgroup { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; padding-right: 8px; border-right: 1px solid var(--line); }
.tgroup span { font-size: 11px; color: var(--muted); }
.tgroup button { padding: 4px 8px; font-size: 12px; }
#peek { background: #2b2341; border: 1px solid #6a4bb5; border-radius: 12px; padding: 8px; }
.peekhead { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.peekcards { display: flex; gap: 8px; overflow-x: auto; }

/* cards (original v2 design) */
.card .art { position: relative; margin: 0 6px 4px; height: 58px; border-radius: 8px; color: var(--sct); overflow: hidden;
  background: radial-gradient(circle at 30% 20%, color-mix(in srgb, var(--sc) 55%, #fff) 0%, var(--sc) 55%, color-mix(in srgb, var(--sc) 65%, #000) 100%);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.card .art svg { width: 100%; height: 100%; display: block; }
.card.big .art { height: 130px; margin: 2px 10px 8px; }
.card.event .art { background: radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--sc) 40%, #fff) 0%, var(--sc) 45%, #3b2a6b 100%); }
.card { --sc: #556; --sct: #fff; position: relative; width: 150px; min-width: 150px; height: 250px; border-radius: 12px; overflow: hidden; cursor: pointer; user-select: none;
  display: flex; flex-direction: column; color: #16181d; transition: transform .12s, box-shadow .12s;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--sc) 22%, #fbf8f2) 0%, #fbf8f2 46%),
    #fbf8f2;
  border: 2px solid color-mix(in srgb, var(--sc) 70%, #000);
  box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.card::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .09;
  background: repeating-linear-gradient(115deg, var(--sc) 0 2px, transparent 2px 14px); }
.card .band { position: relative; display: flex; justify-content: space-between; gap: 6px; padding: 3px 7px; font-size: 9px; font-weight: 800; letter-spacing: .3px;
  background: linear-gradient(100deg, var(--sc) 70%, color-mix(in srgb, var(--sc) 60%, #000) 70%); color: var(--sct); white-space: nowrap; }
.card .band .aff { overflow: hidden; text-overflow: ellipsis; }
.card .band .no { opacity: .85; font-weight: 600; }
.card .hero { position: relative; display: flex; align-items: center; gap: 7px; padding: 6px 7px 4px; }
.card .emblem { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--sc) 55%, #fff), var(--sc)); color: var(--sct);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.55), 0 1px 3px rgba(0,0,0,.3); }
.card .emblem svg { width: 20px; height: 20px; }
.card .who { min-width: 0; }
.card .cn { font-weight: 900; font-size: 14px; line-height: 1.1; letter-spacing: -.2px; }
.card .pos { font-size: 10px; font-weight: 800; color: color-mix(in srgb, var(--sc) 75%, #000); text-transform: uppercase; letter-spacing: .6px; }
.card .jp { font-size: 11px; color: #666; }
.card .stats { position: relative; display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; margin: 2px 6px 4px; }
.card .stats div { display: flex; flex-direction: column; align-items: center; border-radius: 6px; padding: 1px 0 2px; background: #fff; border: 1px solid color-mix(in srgb, var(--sc) 35%, #ddd); }
.card .stats i { font-style: normal; font-size: 8px; font-weight: 800; color: #777; letter-spacing: .4px; }
.card .stats b { font-size: 16px; font-weight: 900; line-height: 1; }
.card .stats div.no { background: transparent; border-style: dashed; }
.card .stats div.no b { color: #c4c4c4; }
.card .stats div.up b { color: #0a8a4a; } .card .stats div.down b { color: #c0362e; }
.card .stats div.hi { background: var(--sc); border-color: var(--sc); }
.card .stats div.hi i, .card .stats div.hi b { color: var(--sct); }
.card .timing { position: relative; padding: 2px 7px 4px; display: flex; gap: 3px; flex-wrap: wrap; }
.card .txt { position: relative; font-size: 9.5px; padding: 3px 7px 6px; color: #2a2a2a; overflow: hidden; flex: 1; line-height: 1.3;
  border-top: 1px solid color-mix(in srgb, var(--sc) 30%, transparent); }
.card .note { margin-top: 6px; padding-top: 4px; border-top: 1px dashed #bbb; color: #555; }
.tag { display: inline-block; background: var(--sc, #444); color: var(--sct, #fff); border-radius: 3px; padding: 0 4px; font-size: .9em; font-weight: 800; margin: 0 1px; }
.card.event { background:
    radial-gradient(circle at 85% 20%, color-mix(in srgb, var(--sc) 30%, transparent), transparent 55%),
    linear-gradient(180deg, #f3eefc, #fbf8f2); }
.card.event .emblem { border-radius: 9px; transform: rotate(-6deg); }
.card.event .txt { font-size: 10px; }
.card.mini { width: 100%; min-width: 0; height: auto; min-height: 0; border-radius: 9px; border-width: 1.5px; }
.card.mini .band { display: none; }
.card.mini .hero { padding: 4px 4px 2px; gap: 4px; }
.card.mini .emblem { width: 20px; height: 20px; }
.card.mini .emblem svg { width: 12px; height: 12px; }
.card.mini .cn { font-size: 10.5px; }
.card.mini .pos { font-size: 8px; }
.card.mini .stats { margin: 1px 3px 4px; gap: 2px; }
.card.mini .stats b { font-size: 12px; }
.card.mini .stats i { font-size: 7px; }
.card.big { width: 320px; min-width: 320px; height: auto; min-height: 440px; cursor: default; }
.card.big .band { font-size: 12px; padding: 5px 10px; }
.card.big .emblem { width: 58px; height: 58px; } .card.big .emblem svg { width: 34px; height: 34px; }
.card.big .cn { font-size: 22px; } .card.big .pos { font-size: 13px; }
.card.big .stats { margin: 4px 10px 8px; gap: 5px; } .card.big .stats b { font-size: 26px; } .card.big .stats i { font-size: 11px; }
.card.big .txt { font-size: 13.5px; padding: 8px 12px 12px; }
.card.elig { box-shadow: 0 0 0 3px var(--accent), 0 2px 6px rgba(0,0,0,.35); }
.card.elig:hover { transform: translateY(-4px); }
.card.sel { transform: translateY(-10px); box-shadow: 0 0 0 4px var(--good), 0 6px 12px rgba(0,0,0,.4); }
.card.danger { box-shadow: 0 0 0 3px var(--bad); }
.card .badge { position: absolute; top: 4px; right: 4px; background: var(--good); color: #fff; font-weight: 800; font-size: 11px; border-radius: 4px; padding: 1px 5px; z-index: 2; }
.pool .card .badge { background: transparent; top: auto; bottom: 4px; right: 4px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; max-width: 980px; width: auto; max-height: 90vh; overflow: auto; position: relative; }
.modal-box .close { position: sticky; float: right; top: 0; z-index: 20; margin: -6px -6px 4px 8px; padding: 4px 14px; font-size: 18px; background: var(--panel2); }
.modal-box .grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.cardmenu { display: flex; gap: 16px; flex-wrap: wrap; }
.cardmenu .menu { display: flex; flex-direction: column; gap: 10px; min-width: 260px; max-width: 360px; }
.mgroup { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.mgroup > span { width: 100%; font-size: 11px; color: var(--muted); }
.modrow { display: flex; gap: 4px; align-items: center; width: 100%; font-size: 12px; }
.modrow button { padding: 2px 8px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #2c3a48; border: 1px solid var(--accent); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; }
.over { font-size: 22px; font-weight: 900; }
.over.win { color: var(--good); } .over.loss { color: var(--bad); }

@media (max-width: 900px) {
  #game { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; height: auto; min-height: 100vh; }
  #logPanel { border-left: 0; border-top: 1px solid var(--line); max-height: 220px; }
  .side { grid-template-columns: 1fr; }
  .court { grid-template-columns: repeat(5, minmax(64px, 1fr)); overflow-x: auto; }
  .card { width: 132px; min-width: 132px; height: 228px; }
  .card .art { height: 50px; }
  .card.mini .emblem { display: none; }
  .card.mini .pos { display: none; }
  .card.mini .stats { grid-template-columns: 1fr; margin: 1px 3px 4px; }
  .card.mini .stats div:not(.hi) { display: none; }
  .card.mini .stats div.hi { flex-direction: row; justify-content: center; gap: 4px; padding: 2px 0; }
  .card.mini .stats b { font-size: 15px; }
  .card.mini .stats i { font-size: 8px; }
  .card.mini .cn { font-size: 9.5px; }
  .card.big { width: 100%; min-width: 0; }
  .bbody { grid-template-columns: 1fr; }
  .bdeck { border-left: 0; border-top: 1px solid var(--line); max-height: 40vh; }
}

.tophead { align-items: center; }
.tophead h1 { flex: 1; }
.langslot { flex: 0 0 auto !important; }
button.lang { padding: 3px 10px; font-weight: 700; font-size: 12px; }

/* card details */
.card { -webkit-touch-callout: none; -webkit-user-select: none; touch-action: manipulation; }
.details .menu { max-width: 420px; }
.dtitle { font-size: 20px; font-weight: 900; }
.dtable { border-collapse: collapse; width: 100%; font-size: 13px; }
.dtable th { text-align: left; color: var(--muted); font-weight: 600; padding: 3px 10px 3px 0; white-space: nowrap; vertical-align: top; }
.dtable td { padding: 3px 6px 3px 0; vertical-align: top; }
.stats-t td b { font-size: 16px; }
.stats-t .help { color: var(--muted); font-size: 12px; }
.dash { color: var(--muted); }
.dsec { margin-top: 8px; font-size: 11px; font-weight: 800; letter-spacing: 1px; color: var(--accent); text-transform: uppercase; }
.dskill { background: var(--panel2); border-radius: 8px; padding: 8px 10px; line-height: 1.45; font-size: 13px; }
details summary { cursor: pointer; margin-top: 8px; }
