:root {
  color-scheme: dark;
  --bg: #050505;
  --panel: #0a0a0a;
  --card: #171717;
  --card2: #1c1c1c;
  --line: #343434;
  --text: #f8f8f8;
  --muted: #a8a8a8;
  --orange: #ff9800;
  --green: #62cf22;
  --pink: #e23a91;
  --blue: #2f79ff;
  --red: #ff485c;
  --yellow: #ffd91e;
  font-family: "BIZ UDPGothic", "BIZ UDPゴシック", "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--bg); color: var(--text); }
button, input { font: inherit; }
button { border: 0; color: inherit; cursor: pointer; touch-action: manipulation; user-select: none; }

.app {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% -10%, rgba(255,152,0,.12), transparent 24%),
    linear-gradient(180deg, #020202 0%, #090909 46%, #020202 100%);
}

.app-header {
  height: 60px;
  padding: 7px 12px 6px;
  display: grid;
  grid-template-columns: 1fr 44px;
  align-items: center;
  background: #030303;
  border-bottom: 1px solid #191919;
}
.title { text-align: center; line-height: 1.05; padding-left: 44px; }
.title strong { display: block; color: var(--orange); font-size: 17px; letter-spacing: 0; font-weight: 900; }
.title span { display: block; margin-top: 3px; font-size: 15px; font-weight: 900; }
.menu-button { width: 38px; height: 46px; display: grid; justify-items: center; align-content: center; gap: 3px; background: transparent; }
.menu-button span { width: 24px; height: 3px; border-radius: 2px; background: #fff; }
.menu-button small { color: #fff; font-size: 9px; font-weight: 800; }
.menu-panel {
  position: absolute;
  z-index: 5;
  top: 58px;
  right: 8px;
  width: 220px;
  padding: 8px;
  background: #111;
  border: 1px solid #555;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,.55);
}
.menu-panel button { width: 100%; min-height: 42px; margin-bottom: 7px; border-radius: 6px; background: #252525; font-weight: 900; }
.menu-panel button:last-child { margin-bottom: 0; }
.menu-panel .danger { background: #b71922; }

.view {
  display: none;
  height: calc(100dvh - 60px - 64px - env(safe-area-inset-bottom));
  padding: 7px 7px 0;
}
.view.active { display: block; }
.view-main.active {
  display: grid;
  grid-template-rows: 92px 178px 68px 1fr;
  gap: 6px;
  overflow: hidden;
}
.scroll-view { overflow-y: auto; padding-bottom: 12px; }
.card {
  position: relative;
  background: linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.008)), var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.02);
}
.card-head {
  min-height: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  color: var(--orange);
  font-size: 13px;
  font-weight: 900;
}
.card-head small { color: var(--muted); font-size: 10px; font-weight: 700; }
.accent-orange { border-color: rgba(255,152,0,.62); box-shadow: inset 0 0 14px rgba(255,152,0,.08); }
.green-card { border-color: rgba(98,207,34,.42); }
.green-card .card-head { color: var(--green); }
.pink-card { border-color: rgba(226,58,145,.48); }
.pink-card .card-head { color: #ff4bad; }

.games-card { padding: 7px 8px; }
.game-row {
  height: 56px;
  display: grid;
  grid-template-columns: 44px 1fr 26px 52px;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
  padding: 5px 7px;
  background: #101010;
  border: 1px solid #3a2c16;
  border-radius: 8px;
}
.game-input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #fff;
  text-align: right;
  font-size: 38px;
  line-height: 1;
  font-weight: 900;
}
.game-unit { color: #fff; font-size: 22px; font-weight: 900; }

.minus, .plus {
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: #141414;
  border: 1px solid #5e5e5e;
  font-weight: 900;
}
.minus { width: 34px; height: 34px; color: #ffd987; border-color: #474747; font-size: 23px; }
.plus { width: 43px; height: 43px; color: #ffb038; border-color: #ff9800; font-size: 28px; }
.big-plus { width: 52px; height: 48px; font-size: 31px; }
button:active, .tap-flash { transform: scale(.96); filter: brightness(1.25); transition: transform .1s ease, filter .1s ease; }

.estimate-card { padding: 8px; }
.estimate-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(96px, 118px); gap: 8px; height: calc(100% - 22px); }
.setting-bars, .summary-probs { min-width: 0; }
.setting-bars { display: grid; grid-template-rows: repeat(6, 1fr); gap: 4px; }
.setting-row { min-width: 0; display: grid; grid-template-columns: 44px minmax(0, 1fr) 38px; align-items: center; gap: 5px; font-weight: 900; }
.setting-row .name { font-size: 14px; }
.bar-track { height: 18px; background: #202020; border: 1px solid #303030; border-radius: 2px; overflow: hidden; }
.bar-fill { height: 100%; min-width: 2px; transition: width .14s ease; }
.setting-row .pct { text-align: right; font-size: 17px; }
.summary-probs { display: grid; grid-template-rows: repeat(3, 1fr); gap: 6px; }
.summary-probs div {
  min-width: 0;
  display: grid;
  place-items: center;
  align-content: center;
  padding: 4px;
  background: #111;
  border: 1px solid var(--orange);
  border-radius: 7px;
}
.summary-probs span { color: #ffbd2e; font-size: 10px; font-weight: 900; }
.summary-probs b { color: #ffbd00; font-size: 24px; line-height: 1; }

.verdict-card {
  display: grid;
  grid-template-columns: 84px 1fr;
  align-items: center;
  padding: 8px 12px;
  border-color: #3b3b3b;
}
.verdict-card span { color: #dcdcdc; font-size: 13px; font-weight: 900; }
.verdict-card strong { color: #ff485c; font-size: 25px; font-weight: 900; text-align: center; }
.verdict-card.watch strong { color: var(--yellow); }
.verdict-card.low strong { color: var(--blue); }
.verdict-card.high strong { color: #45de57; }
.verdict-card.s4 strong, .verdict-card.s5 strong, .verdict-card.s6 strong { color: #ff4058; }

.counter-stack { min-height: 0; display: grid; grid-template-rows: repeat(4, 1fr); gap: 6px; }
.counter-card {
  min-height: 0;
  padding: 5px 6px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) minmax(66px, 86px) 52px;
  grid-template-rows: 19px 1fr;
  column-gap: 5px;
  align-items: center;
}
.help-chip {
  position: absolute;
  top: 7px;
  right: 9px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid #777;
  background: #191919;
  color: #ddd;
  font-size: 14px;
  font-weight: 900;
}
.counter-title { grid-column: 1 / 5; color: var(--orange); font-size: 14px; font-weight: 900; }
.counter-title small { color: #ffca57; font-size: 10px; }
.counter-value { min-width: 0; justify-self: center; display: flex; align-items: baseline; gap: 4px; }
.counter-value b { font-size: 28px; line-height: 1; font-weight: 900; }
.counter-value span { font-size: 14px; font-weight: 900; }
.counter-rate { min-width: 0; justify-self: end; font-size: 20px; font-weight: 900; white-space: nowrap; }
.counter-card .minus { grid-column: 1; grid-row: 2; }
.counter-card .counter-value { grid-column: 2; grid-row: 2; }
.counter-card .counter-rate { grid-column: 3; grid-row: 2; }
.counter-card .plus { grid-column: 4; grid-row: 2; }

.detail-card, .hint-card { padding: 9px; margin-bottom: 7px; }
.detail-card .card-head {
  min-height: 34px;
  padding-right: 0;
}
.detail-card .card-head > span {
  min-width: 0;
  flex: 1;
}
.detail-card .help-chip { display: none; }
.collapse-toggle {
  flex: 0 0 36px;
  width: 36px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: #101010;
  border: 1px solid currentColor;
  color: inherit;
}
.collapse-toggle::before {
  content: "";
  width: 10px;
  height: 10px;
  border-right: 3px solid currentColor;
  border-bottom: 3px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
}
.card:not(.collapsed) > .card-head .collapse-toggle::before {
  transform: rotate(225deg) translate(-2px, -2px);
}
.collapse-content {
  display: grid;
  gap: 0;
  padding-top: 6px;
}
.collapsed > .collapse-content { display: none; }
.triple-stat { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.triple-stat button, .triple-stat div, .ep-row, .tile, .point-row > span, .point-row button, .hint-tile {
  min-height: 56px;
  border-radius: 7px;
  background: #111;
  border: 1px solid #363636;
  display: grid;
  place-items: center;
  align-content: center;
}
.triple-stat span { color: #ddd; font-size: 11px; }
.triple-stat b { font-size: 22px; font-weight: 900; }
.triple-stat small { color: #ddd; font-size: 10px; }
.green-card button { border-color: rgba(98,207,34,.45); }
.compact b { font-size: 24px; }
.point-rows { display: grid; gap: 5px; }
.point-row { display: grid; grid-template-columns: 1.3fr .85fr .85fr; gap: 5px; align-items: center; }
.point-row > span { justify-items: start; padding-left: 10px; font-size: 14px; font-weight: 900; }
.point-row small { display: block; color: var(--muted); font-size: 10px; }
.point-row button { min-height: 44px; font-size: 18px; font-weight: 900; }
.point-row .win { color: #328cff; border-color: #1b75ff; }
.point-row .lose { color: #ff544a; border-color: #b94b45; }
.ep-row { grid-template-columns: 42px 1fr 48px 1.2fr; min-height: 60px; gap: 8px; padding: 7px; }
.ep-row b { text-align: center; font-size: 26px; }
.ep-row strong { text-align: center; font-size: 22px; }
.tile-grid { display: grid; gap: 6px; }
.tile-grid.two { grid-template-columns: 1fr 1fr; }
.tile-grid.four { grid-template-columns: repeat(4, 1fr); }
.tile { min-height: 49px; font-size: 12px; font-weight: 900; }
.tile b { font-size: 20px; }
.replay .tile { border-color: #ff9800; }
.replay .tile:first-child { border-color: var(--green); color: var(--green); }

.hint-grid { display: grid; gap: 6px; }
.hint-grid.four { grid-template-columns: repeat(4, 1fr); }
.hint-grid.three { grid-template-columns: repeat(3, 1fr); }
.hint-grid.six { grid-template-columns: repeat(6, 1fr); }
.hint-tile { min-height: 66px; padding: 4px 3px; border-color: rgba(226,58,145,.42); }
.hint-tile .pic {
  width: 100%;
  height: 28px;
  margin-bottom: 3px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: linear-gradient(135deg, rgba(226,58,145,.28), rgba(255,152,0,.18));
  border: 1px solid rgba(255,255,255,.08);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}
.hint-tile strong { font-size: 11px; line-height: 1.05; text-align: center; }
.hint-tile span { color: #f5b7df; font-size: 10px; line-height: 1.05; text-align: center; }
.hint-tile b { color: #fff; font-size: 14px; }
.hint-tile.hot { border-color: #ff9800; box-shadow: inset 0 0 12px rgba(255,152,0,.2); }
.hint-grid.small .hint-tile { min-height: 52px; }
.hint-grid.six .hint-tile { min-width: 0; }
.hint-grid.six .hint-tile strong { font-size: 12px; }
.hint-grid.six .hint-tile span { display: none; }

.tabs {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  height: calc(64px + env(safe-area-inset-bottom));
  padding: 7px 7px calc(7px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  background: linear-gradient(180deg, #202020, #101010);
  border-top: 1px solid #333;
}
.tab {
  border-radius: 8px;
  background: #151515;
  border: 1px solid #333;
  color: #fff;
  font-weight: 900;
  font-size: 15px;
}
.tab.active.main-tab { background: var(--orange); color: #111; }
.tab.active.detail-tab { background: var(--green); color: #111; }
.tab.active.hint-tab { background: var(--pink); color: #fff; }

@media (max-width: 360px), (max-height: 760px) {
  .app-header { height: 54px; padding-top: 5px; }
  .title strong { font-size: 16px; }
  .title span { font-size: 14px; }
  .view { height: calc(100dvh - 54px - 58px - env(safe-area-inset-bottom)); padding: 5px 5px 0; }
  .view-main.active { grid-template-rows: 84px 158px 58px 1fr; gap: 5px; }
  .tabs { height: calc(58px + env(safe-area-inset-bottom)); padding: 5px 5px calc(5px + env(safe-area-inset-bottom)); }
  .games-card, .estimate-card, .counter-card { padding: 5px 6px; }
  .game-row { height: 50px; grid-template-columns: 34px 1fr 22px 46px; gap: 5px; }
  .game-input { font-size: 32px; }
  .setting-row { grid-template-columns: 38px minmax(0, 1fr) 32px; gap: 4px; }
  .setting-row .name { font-size: 12px; }
  .bar-track { height: 15px; }
  .setting-row .pct { font-size: 14px; }
  .estimate-body { grid-template-columns: minmax(0, 1fr) minmax(90px, 104px); gap: 6px; }
  .summary-probs b { font-size: 20px; }
  .summary-probs span { font-size: 9px; }
  .verdict-card strong { font-size: 21px; }
  .counter-stack { gap: 5px; }
  .counter-card { grid-template-columns: 30px minmax(0, 1fr) minmax(66px, 78px) 46px; column-gap: 4px; grid-template-rows: 17px 1fr; }
  .counter-value { min-width: 0; }
  .counter-rate { min-width: 0; white-space: nowrap; }
  .counter-title { font-size: 12px; }
  .counter-value b { font-size: 24px; }
  .counter-rate { font-size: 17px; }
  .plus { width: 40px; height: 38px; }
  .big-plus { width: 46px; height: 42px; }
}

@media (orientation: landscape) and (min-width: 600px) {
  .app,
  .tabs {
    max-width: none;
  }

  .view {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .tabs {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .app-header {
    grid-template-columns: 1fr 60px;
  }

  .title {
    padding-left: 60px;
    white-space: nowrap;
  }

  .title strong,
  .title span {
    display: inline;
    margin-top: 0;
  }

  .title span {
    margin-left: 10px;
  }

  .menu-button {
    width: 54px;
  }

  .menu-button small {
    white-space: nowrap;
  }

  .view-main.active {
    grid-template-columns: minmax(240px, .96fr) minmax(320px, 1.04fr);
    grid-template-rows: 62px minmax(0, 1fr) 58px;
    grid-template-areas:
      "estimate games"
      "estimate counters"
      "verdict counters";
    gap: 6px;
  }

  .games-card { grid-area: games; }
  .estimate-card { grid-area: estimate; }
  .verdict-card { grid-area: verdict; }
  .counter-stack { grid-area: counters; }

  .games-card {
    padding: 5px 8px;
  }

  .games-card .card-head {
    position: absolute;
    z-index: 1;
    top: 5px;
    left: 10px;
  }

  .games-card .card-head b {
    display: none;
  }

  .game-row {
    height: 100%;
    margin-top: 0;
    padding: 3px 7px;
  }

  .game-input {
    font-size: 32px;
  }

  .estimate-body {
    grid-template-columns: minmax(0, 1fr) minmax(104px, 30%);
  }

  .counter-stack {
    grid-template-rows: repeat(4, minmax(0, 1fr));
  }

  .counter-card {
    padding-top: 3px;
    padding-bottom: 3px;
    grid-template-columns: 34px minmax(0, 1fr) minmax(62px, 78px) 46px;
    grid-template-rows: 16px minmax(0, 1fr);
    column-gap: 5px;
  }

  .counter-title {
    grid-column: 1 / 4;
    font-size: 12px;
  }

  .counter-title small {
    font-size: 9px;
  }

  .counter-value b {
    font-size: 23px;
  }

  .counter-rate {
    font-size: 17px;
  }

  .counter-card .minus {
    height: min(30px, 100%);
    font-size: 0;
    line-height: 1;
  }

  .counter-card .minus::before {
    content: "−";
    display: block;
    font-size: 23px;
    line-height: 1;
    transform: translateY(-1px);
  }

  .counter-card .plus {
    grid-row: 1 / 3;
    align-self: center;
    width: 46px;
    height: min(38px, calc(100% - 2px));
    line-height: 1;
  }

  #detailView .detail-card {
    padding: 4px 8px;
    margin-bottom: 4px;
  }

  #detailView .detail-card .card-head {
    min-height: 27px;
  }

  #detailView .collapse-toggle {
    height: 25px;
  }
}
