/* ===== TakkyuLife — POP THEME (iPhone-optimized) ===== */
:root {
  --bg-1: #fff7ed;
  --bg-2: #fce7f3;
  --bg-3: #dbeafe;
  --ink: #1e293b;
  --ink-dim: #64748b;
  --ink-faint: #94a3b8;
  --line: #1e293b;
  --paper: #ffffff;
  --paper-2: #fff9f0;
  --paper-3: #f1f5f9;

  --pink: #ec4899;
  --pink-deep: #db2777;
  --orange: #f97316;
  --orange-deep: #ea580c;
  --yellow: #facc15;
  --lime: #84cc16;
  --green: #22c55e;
  --green-deep: #16a34a;
  --cyan: #06b6d4;
  --cyan-deep: #0891b2;
  --blue: #3b82f6;
  --violet: #8b5cf6;
  --red: #ef4444;
  --red-bg: #fecaca;
  --dotted: #e2e8f0;

  --shadow-1: 0 4px 0 #1e293b;
  --shadow-2: 0 6px 0 #1e293b;
  --shadow-soft: 0 8px 24px rgba(30,41,59,0.12);

  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
  --safe-right: env(safe-area-inset-right);
  --tabbar-h: 64px;
  --header-h: 56px;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 24px;

  --t-fast: 0.12s cubic-bezier(0.2,0.8,0.2,1);
  --t-base: 0.22s cubic-bezier(0.2,0.8,0.2,1);
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f1f5f9;
    --ink-dim: #cbd5e1;
    --ink-faint: #94a3b8;
    --line: #0f172a;
    --paper: #1e293b;
    --paper-2: #293548;
    --paper-3: #334155;
    --dotted: #334155;
    --shadow-1: 0 4px 0 #0f172a;
    --shadow-2: 0 6px 0 #0f172a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }

/* Use dvh on iOS 15.4+ for truly full viewport height that doesn't change with URL bar */
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}

body {
  margin: 0;
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Sans", -apple-system, "Segoe UI", "Noto Sans JP", Roboto, system-ui, sans-serif;
  color: var(--ink);
  font-weight: 700;
  /* iOS supports background: fixed poorly — use a fixed ::before instead */
  background: linear-gradient(160deg, #fff7ed, #fef3c7 50%, #fce7f3 100%);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  /* Prevent iOS auto text-size adjust */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Smooth momentum is default in iOS 13+, but keep it enabled */
  -webkit-overflow-scrolling: touch;
}

@media (prefers-color-scheme: dark) {
  body {
    background: linear-gradient(160deg, #0f172a, #1e1b4b 50%, #3b0764 100%);
  }
}

/* Body lock when overlay open (prevents background scroll on iOS) */
body.lock-scroll {
  overflow: hidden;
  position: fixed;
  width: 100%;
  top: var(--lock-top, 0);
}

/* Fixed background layer (iOS safe way to pin decoration) */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(circle at 0% 0%, #fde68a 0%, transparent 40%),
    radial-gradient(circle at 100% 0%, #fbcfe8 0%, transparent 40%),
    radial-gradient(circle at 100% 100%, #bae6fd 0%, transparent 40%),
    radial-gradient(circle at 0% 100%, #bbf7d0 0%, transparent 40%);
  opacity: 0.9;
}
@media (prefers-color-scheme: dark) {
  body::before {
    background:
      radial-gradient(circle at 0% 0%, rgba(251,191,36,0.14) 0%, transparent 40%),
      radial-gradient(circle at 100% 0%, rgba(236,72,153,0.18) 0%, transparent 40%),
      radial-gradient(circle at 100% 100%, rgba(59,130,246,0.2) 0%, transparent 40%),
      radial-gradient(circle at 0% 100%, rgba(34,197,94,0.16) 0%, transparent 40%);
  }
}

/* Confetti dots */
body::after {
  content: ""; position: fixed; pointer-events: none; z-index: 0;
  top: 8%; left: -30px; width: 120px; height: 120px;
  background: radial-gradient(circle, rgba(251,191,36,0.7) 2px, transparent 3px) 0 0/14px 14px;
  opacity: 0.45;
}

button, input, select, textarea {
  font-family: inherit; color: inherit; font-weight: 800;
  /* Kill iOS default appearance */
  -webkit-appearance: none; appearance: none;
}
button {
  cursor: pointer; border: none; background: transparent;
  /* Remove 300ms click delay and reduce gestures */
  touch-action: manipulation;
}
input, select, textarea {
  -webkit-user-select: text; user-select: text;
  /* CRITICAL: 16px prevents iOS auto-zoom on focus */
  font-size: 16px;
}
select { touch-action: manipulation; }
.hidden { display: none !important; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ===== Splash ===== */
#splash {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: linear-gradient(135deg, #fde68a 0%, #fbcfe8 50%, #bae6fd 100%);
  animation: splash-out 1.6s ease 0.7s forwards;
}
@media (prefers-color-scheme: dark) {
  #splash { background: linear-gradient(135deg, #422006 0%, #500724 50%, #0c4a6e 100%); }
}
#splash h1 {
  margin: 12px 0 4px; font-size: 32px;
  color: var(--pink-deep); letter-spacing: 0.02em;
  text-shadow: 3px 3px 0 #fff, 4px 4px 0 var(--line);
}
#splash p { margin: 0; color: var(--line); font-weight: 800; font-size: 14px; }
.splash-ball {
  font-size: 80px; animation: splashBounce 0.6s ease infinite alternate;
  filter: drop-shadow(0 6px 0 rgba(30,41,59,0.3));
}
@keyframes splashBounce { from { transform: translateY(0) rotate(-10deg); } to { transform: translateY(-20px) rotate(20deg); } }
@keyframes splash-out { to { opacity: 0; visibility: hidden; pointer-events: none; } }

/* ===== Layout ===== */
#app { position: relative; z-index: 1; min-height: 100%; display: flex; flex-direction: column; }

@supports (min-height: 100dvh) {
  #app { min-height: 100dvh; }
}

#header {
  position: sticky; top: 0; z-index: 20;
  height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) max(12px, var(--safe-right)) 0 max(14px, var(--safe-left));
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(255, 255, 255, 0.85);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 2px solid var(--line);
  box-shadow: 0 4px 0 rgba(30,41,59,0.06);
}
@media (prefers-color-scheme: dark) {
  #header { background: rgba(30, 41, 59, 0.85); background: color-mix(in srgb, var(--paper) 82%, transparent); }
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  font-size: 28px; display: inline-block;
  animation: logoSway 2.4s ease-in-out infinite;
  transform-origin: bottom center;
}
@keyframes logoSway { 0%,100% { transform: rotate(-6deg); } 50% { transform: rotate(10deg); } }
.title-wrap { min-width: 0; }
.title-wrap .title {
  font-weight: 900; font-size: 17px; letter-spacing: 0.02em;
  color: var(--ink);
  text-shadow: 2px 2px 0 var(--yellow);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.title-wrap .subtitle {
  font-size: 10.5px; color: var(--pink-deep); font-weight: 800;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  min-width: 44px; min-height: 44px;
  width: 44px; height: 44px; border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 22px; color: var(--line); background: var(--yellow);
  border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
  flex-shrink: 0;
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }

#main {
  flex: 1; position: relative; z-index: 1;
  padding:
    14px
    max(14px, var(--safe-right))
    calc(var(--tabbar-h) + var(--safe-bottom) + 18px)
    max(14px, var(--safe-left));
}
.view { display: none; animation: fade-in 0.25s ease; }
.view.active { display: block; }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ===== Tabbar ===== */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(255, 255, 255, 0.92);
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 2px solid var(--line);
  box-shadow: 0 -4px 0 rgba(30,41,59,0.06);
}
@media (prefers-color-scheme: dark) {
  #tabbar { background: rgba(30, 41, 59, 0.92); background: color-mix(in srgb, var(--paper) 90%, transparent); }
}
.tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--ink-dim); font-weight: 800;
  min-height: 44px;
  padding: 0;
  transition: transform var(--t-fast);
  touch-action: manipulation;
}
.tab .tab-ico {
  font-size: 24px; filter: grayscale(0.3);
  transition: transform var(--t-base), filter var(--t-base);
}
.tab .tab-label { font-size: 11px; font-weight: 900; }
.tab.active { color: var(--pink-deep); }
.tab.active .tab-ico { transform: translateY(-3px) scale(1.22); filter: none; }
.tab.active::after {
  content: ""; position: absolute; bottom: calc(6px + var(--safe-bottom) * 0);
  width: 26px; height: 4px; border-radius: 4px; background: var(--pink-deep);
  animation: pill-pop var(--t-base);
}
.tab:active { transform: scale(0.96); }
@keyframes pill-pop { from { transform: scaleX(0.3); opacity: 0; } to { transform: scaleX(1); opacity: 1; } }

/* ===== Cards (chunky) ===== */
.card {
  background: var(--paper);
  border: 2.5px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
}

/* ===== Now card ===== */
.now-card {
  background: var(--paper);
  border: 2.5px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 18px 16px;
  box-shadow: var(--shadow-2);
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}
.now-card::before {
  content: ""; position: absolute; top: -40px; right: -40px;
  width: 140px; height: 140px; border-radius: 50%;
  background: radial-gradient(circle, var(--yellow), transparent 60%);
  opacity: 0.5; pointer-events: none;
}
.now-label {
  display: inline-block;
  font-size: 11px; letter-spacing: 0.2em; font-weight: 900;
  color: #fff; background: var(--pink-deep);
  padding: 3px 12px; border-radius: 999px;
  border: 2px solid var(--line); box-shadow: 0 2px 0 var(--line);
  text-transform: uppercase; margin-bottom: 12px;
  position: relative;
}
.now-players {
  text-align: center; font-size: 22px; font-weight: 900; line-height: 1.35;
  word-break: keep-all; overflow-wrap: anywhere; position: relative;
  color: var(--ink);
}
.now-players .vs-mid {
  display: inline-block; margin: 0 8px; color: var(--pink-deep); font-weight: 900;
  font-size: 14px; padding: 2px 8px; background: var(--yellow);
  border: 2px solid var(--line); border-radius: 8px;
  box-shadow: 0 2px 0 var(--line);
  transform: translateY(-4px);
}
.now-rates {
  display: flex; justify-content: center; gap: 14px;
  margin-top: 12px; font-size: 16px;
  flex-wrap: wrap;
}
.now-rates .rate-num { color: var(--ink); font-weight: 900; font-size: 22px; font-variant-numeric: tabular-nums; }
.now-rates .rate-delta { font-size: 13px; margin-left: 6px; font-weight: 900; padding: 2px 6px; border-radius: 6px; border: 2px solid var(--line); }
.rate-delta.plus { color: #fff; background: var(--green); }
.rate-delta.minus { color: #fff; background: var(--red); }
.rate-vs {
  font-size: 14px; font-weight: 900; color: var(--pink-deep);
  padding: 4px 10px; background: var(--yellow);
  border: 2px solid var(--line); border-radius: 8px;
  align-self: center;
}

.now-probs {
  display: flex; justify-content: center; align-items: center; gap: 10px;
  margin-top: 14px; color: var(--ink-dim); font-size: 13px; font-weight: 900;
}
.prob-bar {
  position: relative; flex: 1; max-width: 260px; height: 14px;
  border-radius: 999px; overflow: hidden;
  background: #fde68a;
  border: 2px solid var(--line);
}
.prob-bar .fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, var(--green), var(--lime));
  transition: width 0.5s cubic-bezier(0.2,0.8,0.2,1);
}
.event-badge {
  display: inline-flex; align-items: center; gap: 4px;
  margin-left: 8px; padding: 3px 10px;
  background: linear-gradient(135deg, var(--yellow), var(--orange));
  color: var(--line); font-weight: 900; font-size: 12px;
  border: 2px solid var(--line); border-radius: 999px;
  box-shadow: 0 2px 0 var(--line);
  animation: wobble 1.2s ease infinite;
}
@keyframes wobble { 0%,100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }

.now-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.win-btn {
  min-height: 64px; height: 68px;
  border-radius: 18px; font-size: 17px; font-weight: 900;
  color: #fff; border: 2.5px solid var(--line);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 5px 0 var(--line);
  transition: transform var(--t-fast), box-shadow var(--t-fast), filter var(--t-fast);
  letter-spacing: 0.04em;
  touch-action: manipulation;
}
.win-btn .ico { font-size: 24px; filter: drop-shadow(0 2px 0 rgba(0,0,0,0.2)); }
.win-btn.left { background: linear-gradient(145deg, #22c55e, #16a34a); }
.win-btn.right { background: linear-gradient(145deg, #06b6d4, #0891b2); }
.win-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--line); }
.win-btn:disabled { opacity: 0.4; filter: grayscale(0.8); box-shadow: 0 2px 0 var(--line); transform: translateY(3px); }

.now-sub-actions { display: flex; gap: 8px; margin-top: 10px; }
.sub-btn {
  flex: 1; min-height: 46px; height: 46px; border-radius: 14px;
  background: var(--paper-2); color: var(--ink);
  font-weight: 900; font-size: 13px;
  border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.sub-btn .btn-img { height: 22px; width: auto; vertical-align: middle; }
.sub-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }

/* ===== Add match card ===== */
.add-match {
  background: var(--paper);
  border: 2.5px solid var(--line);
  border-radius: var(--radius-lg); padding: 14px;
  box-shadow: var(--shadow-2);
  margin-bottom: 16px;
  position: relative;
}
.add-title {
  font-weight: 900; margin-bottom: 12px; font-size: 15px;
  color: var(--violet); display: flex; align-items: center; gap: 6px;
}
.add-row { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 8px; align-items: center; }
.add-row select {
  height: 48px; border-radius: 14px; padding: 0 28px 0 12px;
  background-color: var(--paper-2);
  border: 2px solid var(--line); color: var(--ink);
  font-size: 15px; font-weight: 800; min-width: 0;
  box-shadow: 0 3px 0 var(--line);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%231e293b' d='M6 8L0 0h12z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
@media (prefers-color-scheme: dark) {
  .add-row select {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%23f1f5f9' d='M6 8L0 0h12z'/></svg>");
  }
}
.add-row .vs {
  font-weight: 900; color: #fff; font-size: 12px;
  background: var(--pink); padding: 4px 8px; border-radius: 8px;
  border: 2px solid var(--line); box-shadow: 0 2px 0 var(--line);
}
.add-row #add-btn {
  min-width: 48px; height: 48px; padding: 0 14px; border-radius: 14px;
  background: linear-gradient(135deg, var(--orange), var(--pink));
  color: #fff; font-weight: 900; font-size: 14px;
  border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line);
  display: flex; align-items: center; justify-content: center; gap: 4px;
  touch-action: manipulation;
}
.add-row #add-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.add-hint { color: var(--red); font-size: 12px; margin-top: 8px; min-height: 14px; font-weight: 800; }

/* ===== Section title ===== */
.section-title {
  display: flex; align-items: center; gap: 8px;
  font-weight: 900; margin: 16px 2px 10px; font-size: 16px;
  color: var(--ink);
}
.section-title.sub { font-size: 13px; color: var(--ink-dim); }
.pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; padding: 2px 10px;
  border-radius: 999px; background: var(--yellow);
  color: var(--line); font-size: 12px; font-weight: 900;
  border: 2px solid var(--line);
  box-shadow: 0 2px 0 var(--line);
}

/* ===== Schedule list ===== */
.schedule-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.sched-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  background: var(--paper); border: 2px solid var(--line);
  border-radius: 14px; padding: 10px 12px;
  box-shadow: 0 3px 0 var(--line);
  min-width: 0;
}
.sched-item .ord {
  min-width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 900; background: var(--cyan); color: #fff;
  border: 2px solid var(--line); font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.sched-item .names { font-weight: 800; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sched-item .names .vs-mid { color: var(--pink-deep); font-weight: 900; margin: 0 6px; font-size: 11px; }
.sched-item .kind {
  font-size: 10px; padding: 2px 7px; border-radius: 999px; margin-left: 6px;
  border: 1.5px solid var(--line); font-weight: 900;
  white-space: nowrap;
}
.kind.auto { background: #bae6fd; color: #075985; }
.kind.self { background: var(--yellow); color: var(--line); }
.sched-item .actions { display: flex; gap: 6px; }
.sched-item .actions button {
  min-width: 44px; min-height: 44px;
  width: 44px; height: 44px; border-radius: 12px;
  border: 2px solid var(--line); box-shadow: 0 2px 0 var(--line);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 900;
  touch-action: manipulation;
}
.sched-item .actions .up-btn { background: var(--paper-2); color: var(--ink); }
.sched-item .actions .del-btn { background: var(--red); color: #fff; padding: 0; }
.sched-item .actions button:active { transform: translateY(2px); box-shadow: 0 0 0 var(--line); }
.sched-item .actions img { height: 20px; }

/* ===== Member list ===== */
.member-add { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-bottom: 14px; }
.member-add input {
  height: 50px; border-radius: 14px; padding: 0 14px;
  background: var(--paper); border: 2.5px solid var(--line); color: var(--ink);
  font-size: 16px; font-weight: 800;
  box-shadow: 0 3px 0 var(--line);
  min-width: 0;
}
.member-add input::placeholder { color: var(--ink-dim); font-weight: 700; }
.member-add input:focus { outline: none; box-shadow: 0 3px 0 var(--line), 0 0 0 3px rgba(236,72,153,0.25); }
.member-add button {
  min-height: 50px; height: 50px; padding: 0 18px; border-radius: 14px;
  background: linear-gradient(135deg, var(--green), var(--lime));
  color: var(--line); font-weight: 900; font-size: 15px;
  border: 2.5px solid var(--line); box-shadow: 0 4px 0 var(--line);
  display: flex; align-items: center; gap: 4px;
  touch-action: manipulation;
}
.member-add button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.member-add button img { height: 22px; }

.member-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.mem-item {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center;
  background: var(--paper); border: 2.5px solid var(--line);
  border-radius: 16px; padding: 10px 10px 10px 12px;
  box-shadow: 0 4px 0 var(--line);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
  min-width: 0;
  touch-action: manipulation;
}
.mem-item:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--line); }
.rank-badge {
  min-width: 44px; height: 44px; border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 13px;
  background: var(--paper-2); color: var(--ink);
  border: 2px solid var(--line); box-shadow: 0 2px 0 var(--line);
}
.rank-badge.kyu { background: linear-gradient(135deg, #cbd5e1, #94a3b8); color: var(--line); }
.rank-badge.dan { background: linear-gradient(135deg, #c4b5fd, #8b5cf6); color: #fff; }
.rank-badge.god { background: linear-gradient(135deg, #fde68a, #f59e0b); color: var(--line); }
.mem-item .mem-info { min-width: 0; }
.mem-item .mem-name { font-weight: 900; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mem-item .mem-sub { font-size: 11px; color: var(--ink-dim); font-weight: 700; }
.mem-item .rate-num {
  font-weight: 900; color: var(--pink-deep); font-variant-numeric: tabular-nums;
  font-size: 18px;
}
.mem-item .mem-action {
  min-width: 44px; min-height: 44px;
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--paper-2);
  border: 2px solid var(--line); box-shadow: 0 2px 0 var(--line);
  display: inline-flex; align-items: center; justify-content: center; font-size: 16px;
  touch-action: manipulation;
}
.mem-item .mem-action img { height: 24px; width: auto; }
.mem-item .mem-action:active { transform: translateY(2px); box-shadow: 0 0 0 var(--line); }
.member-list.absent .mem-item { opacity: 0.7; }

/* ===== History ===== */
.history-list { display: flex; flex-direction: column; gap: 12px; }
.hist-day {
  background: var(--paper); border: 2.5px solid var(--line);
  border-radius: 16px; padding: 12px 14px;
  box-shadow: 0 4px 0 var(--line);
}
.hist-day .day-label {
  font-weight: 900; font-size: 14px; color: #fff;
  background: var(--cyan); display: inline-block;
  padding: 3px 10px; border-radius: 999px;
  border: 2px solid var(--line); box-shadow: 0 2px 0 var(--line);
  margin-bottom: 10px;
}
.hist-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 14px; padding: 6px 0;
  border-top: 2px dotted var(--dotted); font-weight: 800;
  gap: 8px;
}
.hist-row:first-of-type { border-top: none; }
.hist-row .w { color: var(--green-deep); font-weight: 900; display: flex; align-items: center; gap: 4px; }
.hist-row .l { color: var(--ink-dim); }

/* ===== Ranking ===== */
.ranking-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.rank-row {
  display: grid; grid-template-columns: 48px 44px 1fr auto; gap: 10px; align-items: center;
  background: var(--paper); border: 2.5px solid var(--line);
  border-radius: 16px; padding: 10px 12px;
  box-shadow: 0 4px 0 var(--line);
  position: relative;
  min-width: 0;
}
.rank-row .place {
  width: 44px; height: 44px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 900; background: var(--paper-2); color: var(--ink-dim);
  border: 2px solid var(--line); box-shadow: 0 2px 0 var(--line);
  font-size: 16px;
}
.rank-row.top-1 .place {
  background: linear-gradient(135deg, #fde68a, #f59e0b); color: var(--line);
  font-size: 0;
}
.rank-row.top-1 .place::before {
  content: ""; width: 32px; height: 32px;
  background: url("assets/medal.png") no-repeat center/contain;
  filter: drop-shadow(0 2px 0 rgba(0,0,0,0.2));
}
.rank-row.top-2 .place { background: linear-gradient(135deg, #e5e7eb, #9ca3af); color: var(--line); }
.rank-row.top-3 .place { background: linear-gradient(135deg, #fca5a5, #f97316); color: #fff; }
.rank-row.top-1 { background: linear-gradient(135deg, #fff9db, #fef3c7); }
.rank-row.top-2 { background: linear-gradient(135deg, #f8fafc, #e2e8f0); }
.rank-row.top-3 { background: linear-gradient(135deg, #fef2e2, #fed7aa); }
@media (prefers-color-scheme: dark) {
  .rank-row.top-1 { background: linear-gradient(135deg, #78350f, #92400e); }
  .rank-row.top-2 { background: linear-gradient(135deg, #334155, #475569); }
  .rank-row.top-3 { background: linear-gradient(135deg, #7c2d12, #9a3412); }
}
.rank-row .rank-name { font-weight: 900; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-row .rank-sub { font-size: 11px; color: var(--ink-dim); font-weight: 700; }
.rank-row .rank-val {
  font-weight: 900; color: var(--pink-deep); font-variant-numeric: tabular-nums;
  font-size: 20px;
}
.rank-row.absent { opacity: 0.6; }

.rank-legend {
  margin-top: 22px; background: var(--paper); border: 2.5px solid var(--line);
  border-radius: 16px; padding: 14px;
  box-shadow: 0 4px 0 var(--line);
}
.legend-title { font-weight: 900; margin-bottom: 10px; font-size: 15px; color: var(--violet); }
.legend-row {
  display: flex; justify-content: space-between;
  padding: 6px 0; font-size: 13px; color: var(--ink-dim);
  border-top: 2px dotted var(--dotted); font-weight: 800;
}
.legend-row:first-of-type { border-top: none; }
.legend-row .t {
  color: #fff; background: var(--violet);
  padding: 2px 10px; border-radius: 999px;
  border: 2px solid var(--line); font-weight: 900; font-size: 12px;
}
.legend-row:nth-child(1) .t { background: linear-gradient(135deg, #fde68a, #f59e0b); color: var(--line); }

/* ===== Drawer ===== */
#drawer { position: fixed; inset: 0; z-index: 40; }
.drawer-bg {
  position: absolute; inset: 0;
  background: rgba(15,23,42,0.45); animation: fade-in 0.2s ease;
}
.drawer-panel {
  position: absolute; right: 0; top: 0; bottom: 0;
  width: min(86vw, 340px);
  background: var(--paper);
  border-left: 2.5px solid var(--line);
  padding:
    calc(16px + var(--safe-top)) max(16px, var(--safe-right))
    calc(16px + var(--safe-bottom)) 16px;
  display: flex; flex-direction: column; gap: 8px;
  animation: slide-right 0.26s cubic-bezier(0.2,0.8,0.2,1);
  box-shadow: -8px 0 0 rgba(30,41,59,0.08);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
@keyframes slide-right { from { transform: translateX(100%); } to { transform: translateX(0); } }
.drawer-title {
  font-weight: 900; font-size: 18px; margin-bottom: 10px;
  color: var(--pink-deep); text-align: center;
}
.drawer-item {
  text-align: left; padding: 14px 14px; border-radius: 14px;
  background: var(--paper-2);
  color: var(--ink); font-size: 15px; font-weight: 800;
  display: flex; align-items: center; gap: 10px;
  border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
  min-height: 50px;
  touch-action: manipulation;
}
.drawer-item img { height: 26px; }
.drawer-item:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.drawer-item.danger { background: var(--red-bg); color: var(--red); }
.drawer-spacer { flex: 1; }
.drawer-meta { font-size: 11px; color: var(--ink-dim); text-align: center; padding: 8px 0; line-height: 1.7; font-weight: 700; }

/* ===== Modal (bottom sheet) ===== */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; }
.modal-bg { position: absolute; inset: 0; background: rgba(15,23,42,0.5); animation: fade-in 0.2s; }
.modal-panel {
  position: relative; width: 100%;
  background: var(--paper);
  border-top: 2.5px solid var(--line);
  border-radius: 24px 24px 0 0;
  padding:
    18px max(16px, var(--safe-right))
    calc(18px + var(--safe-bottom)) max(16px, var(--safe-left));
  max-height: 92vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  animation: slide-up 0.28s cubic-bezier(0.2,0.8,0.2,1);
  box-shadow: 0 -8px 0 rgba(30,41,59,0.08);
}
@supports (max-height: 92dvh) {
  .modal-panel { max-height: 92dvh; }
}
.modal-panel.small { max-height: 70vh; }
@supports (max-height: 70dvh) {
  .modal-panel.small { max-height: 70dvh; }
}
/* iOS grabber */
.modal-panel::before {
  content: ""; display: block;
  width: 44px; height: 5px; border-radius: 999px;
  background: var(--ink-faint);
  margin: -8px auto 12px;
  opacity: 0.5;
}
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; }
.modal-name { font-size: 22px; font-weight: 900; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-real { font-size: 12px; color: var(--ink-dim); font-weight: 700; }

/* Status modal head enhancements */
.stat-head { align-items: flex-start; }
.stat-head-info { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.stat-head-badge {
  flex-shrink: 0;
}

/* Chart card */
.stat-chart-card {
  background: linear-gradient(135deg, #fdf2f8, #fff);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: 0 3px 0 var(--line);
  margin: 4px 0 14px;
}
@media (prefers-color-scheme: dark) {
  .stat-chart-card { background: linear-gradient(135deg, #500724, #1e293b); }
}
.chart-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 10px; margin-bottom: 8px;
}
.chart-label { font-weight: 900; font-size: 13px; color: var(--pink-deep); }
.chart-range { font-size: 11px; color: var(--ink-dim); font-weight: 700; margin-top: 2px; }
.chart-now { text-align: right; }
.chart-now-val {
  font-size: 24px; font-weight: 900; color: var(--ink);
  font-variant-numeric: tabular-nums; line-height: 1;
}
.chart-now-delta {
  margin-top: 4px; font-size: 11px; font-weight: 900;
  padding: 2px 8px; border-radius: 999px;
  border: 1.5px solid var(--line);
  display: inline-block;
  background: var(--paper-2);
  color: var(--ink-dim);
}
.chart-now-delta.plus { background: var(--green); color: #fff; }
.chart-now-delta.minus { background: var(--red); color: #fff; }
.chart-svg-wrap {
  width: 100%; height: 90px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.chart-svg-wrap svg { display: block; width: 100%; height: 100%; }

/* Recent form */
.stat-form {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 6px 0;
}
.form-pill {
  min-width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; border: 2px solid var(--line);
  font-size: 12px; font-weight: 900;
  box-shadow: 0 2px 0 var(--line);
}
.form-pill.w { background: var(--green); color: #fff; }
.form-pill.l { background: var(--red); color: #fff; }
.form-empty { color: var(--ink-dim); font-weight: 700; }

/* Chemistry */
.stat-chem { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chem-card {
  border: 2px solid var(--line); border-radius: 14px; padding: 10px 12px;
  box-shadow: 0 3px 0 var(--line); min-width: 0;
}
.chem-card.good { background: linear-gradient(135deg, #bbf7d0, #f0fdf4); }
.chem-card.bad { background: linear-gradient(135deg, #fecaca, #fff1f2); }
@media (prefers-color-scheme: dark) {
  .chem-card.good { background: linear-gradient(135deg, #14532d, #052e16); }
  .chem-card.bad { background: linear-gradient(135deg, #7f1d1d, #450a0a); }
  .chem-card { color: #f1f5f9; }
}
.chem-k { font-size: 11px; font-weight: 800; color: var(--ink-dim); margin-bottom: 4px; }
.chem-v { font-weight: 900; }
.chem-name { font-size: 15px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chem-sub { font-size: 11px; color: var(--ink-dim); font-weight: 800; margin-top: 2px; }
.chem-empty { color: var(--ink-dim); font-size: 13px; font-weight: 800; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat-card {
  background: var(--paper-2); border: 2px solid var(--line); border-radius: 14px;
  padding: 10px 14px; box-shadow: 0 3px 0 var(--line);
}
.stat-card:nth-child(1) { background: linear-gradient(135deg, #fde68a, #fff9db); }
.stat-card:nth-child(2) { background: linear-gradient(135deg, #ddd6fe, #f5f3ff); }
.stat-card:nth-child(3) { background: linear-gradient(135deg, #fbcfe8, #fdf2f8); }
.stat-card:nth-child(4) { background: linear-gradient(135deg, #bbf7d0, #f0fdf4); }
.stat-card:nth-child(5) { background: linear-gradient(135deg, #bae6fd, #f0f9ff); }
.stat-card:nth-child(6) { background: linear-gradient(135deg, #fed7aa, #fff7ed); }
@media (prefers-color-scheme: dark) {
  .stat-card:nth-child(1) { background: linear-gradient(135deg, #78350f, #422006); }
  .stat-card:nth-child(2) { background: linear-gradient(135deg, #4c1d95, #2e1065); }
  .stat-card:nth-child(3) { background: linear-gradient(135deg, #831843, #500724); }
  .stat-card:nth-child(4) { background: linear-gradient(135deg, #14532d, #052e16); }
  .stat-card:nth-child(5) { background: linear-gradient(135deg, #0c4a6e, #082f49); }
  .stat-card:nth-child(6) { background: linear-gradient(135deg, #7c2d12, #431407); }
  .stat-card { color: #f1f5f9; }
  .stat-card .stat-k, .stat-card .stat-v { color: #f1f5f9; }
}
.stat-k { font-size: 11px; color: var(--ink-dim); font-weight: 800; }
.stat-v { font-size: 22px; font-weight: 900; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.stat-actions button {
  min-height: 48px; height: 48px; border-radius: 14px; font-weight: 900; font-size: 14px;
  background: var(--paper-2); color: var(--ink);
  border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line);
  touch-action: manipulation;
}
.stat-actions button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.stat-actions button.danger { background: var(--red-bg); color: var(--red); }
.stat-section { margin-top: 16px; }
.stat-vs { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.stat-vs li {
  background: var(--paper-2); border: 2px solid var(--line); border-radius: 12px;
  padding: 8px 12px; font-size: 13px; font-weight: 800;
  display: flex; justify-content: space-between; box-shadow: 0 2px 0 var(--line);
  gap: 8px;
}
.stat-hist {
  background: var(--paper-2); border: 2px solid var(--line); border-radius: 14px;
  padding: 10px 14px; font-size: 13px; font-weight: 800;
  max-height: 260px; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  box-shadow: 0 3px 0 var(--line);
}
.stat-hist .day-label {
  color: #fff; background: var(--cyan); display: inline-block;
  padding: 2px 8px; border-radius: 999px; border: 2px solid var(--line);
  font-weight: 900; font-size: 12px; margin: 8px 0 4px;
}

.prompt-input {
  width: 100%; height: 52px; border-radius: 14px; padding: 0 14px;
  background: var(--paper-2); border: 2.5px solid var(--line); color: var(--ink);
  font-size: 16px; font-weight: 800; margin: 12px 0;
  box-shadow: 0 3px 0 var(--line);
}
.prompt-input:focus { outline: none; box-shadow: 0 3px 0 var(--line), 0 0 0 3px rgba(236,72,153,0.25); }
.prompt-actions { display: flex; gap: 10px; justify-content: flex-end; }
.prompt-actions button {
  min-height: 48px; height: 48px; padding: 0 20px; border-radius: 14px; font-weight: 900; font-size: 15px;
  background: var(--paper-2); color: var(--ink);
  border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line);
  touch-action: manipulation;
}
.prompt-actions button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.prompt-actions button.primary {
  background: linear-gradient(135deg, var(--orange), var(--pink)); color: #fff;
}

/* ===== Toast ===== */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 20px);
  background: #1e293b; color: #fff;
  padding: 12px 20px; border-radius: 999px;
  font-size: 13px; font-weight: 900;
  z-index: 60; animation: toast-in 0.25s ease;
  box-shadow: 0 6px 0 rgba(0,0,0,0.2);
  max-width: calc(100vw - 40px); text-align: center;
  border: 2.5px solid var(--yellow);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 24px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ===== Event (fireworks) overlay ===== */
#event-overlay {
  position: fixed; inset: 0; z-index: 35; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  background: url("assets/eventBack.png") center/cover no-repeat;
  background-color: rgba(0,0,0,0.05);
}
.event-text {
  font-size: clamp(48px, 16vw, 80px); font-weight: 900;
  background: linear-gradient(135deg, var(--yellow), var(--orange), var(--pink));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 6px 0 #fff) drop-shadow(0 8px 0 var(--line));
  animation: burst-text 1.8s ease forwards;
  z-index: 2;
  text-align: center;
}
@keyframes burst-text {
  0% { opacity: 0; transform: scale(0.4) rotate(-15deg); }
  25% { opacity: 1; transform: scale(1.2) rotate(6deg); }
  60% { transform: scale(1) rotate(0deg); }
  100% { opacity: 0; transform: scale(1.5); }
}
.fw {
  position: absolute; width: 60px; height: 60px;
  background: url("assets/hanabi_2.png") center/contain no-repeat;
  pointer-events: none;
  animation: fwRise 1.4s cubic-bezier(0.2,0.8,0.2,1) forwards;
}
@keyframes fwRise {
  0% { opacity: 0; transform: translateY(60vh) scale(0.2); }
  50% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-20vh) scale(1.4); }
}

/* ===== iPhone size adaptations ===== */
/* iPhone SE / mini (~375px) */
@media (max-width: 380px) {
  .now-players { font-size: 20px; }
  .win-btn { height: 60px; font-size: 16px; }
  .now-card { padding: 16px 14px; }
  .title-wrap .title { font-size: 16px; }
  .mem-item { grid-template-columns: auto 1fr auto auto; gap: 8px; padding: 10px 8px 10px 10px; }
  .rank-row { grid-template-columns: 40px 40px 1fr auto; }
  .rank-row .place { width: 36px; height: 36px; font-size: 14px; }
  .rank-row.top-1 .place::before { width: 26px; height: 26px; }
}
/* Very narrow (rare) */
@media (max-width: 340px) {
  .now-players { font-size: 18px; }
  .add-row { grid-template-columns: 1fr 1fr; }
  .add-row .vs { display: none; }
  .add-row #add-btn { grid-column: span 2; }
}

/* iPhone landscape */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --tabbar-h: 56px; --header-h: 48px; }
  #splash h1 { font-size: 24px; }
  .splash-ball { font-size: 54px; }
  .now-card { padding: 12px 14px; margin-bottom: 10px; }
  .win-btn { height: 54px; min-height: 54px; font-size: 15px; }
  .tab .tab-ico { font-size: 20px; }
}

/* Focus-visible for accessibility (keyboards etc) */
:focus-visible {
  outline: 3px solid var(--pink-deep);
  outline-offset: 2px;
}
button:focus { outline: none; }

/* PWA standalone (installed on home screen) tweaks */
@media (display-mode: standalone) {
  /* When installed, the status bar area is black-translucent — our safe-area padding handles spacing */
  #header { background: color-mix(in srgb, var(--paper) 95%, transparent); }
}

/* iPadOS / larger screen: keep comfortable width */
@media (min-width: 768px) {
  #main { max-width: 560px; margin: 0 auto; padding-left: 20px; padding-right: 20px; }
  #tabbar {
    left: 50%; right: auto; transform: translateX(-50%);
    width: min(100%, 560px);
    border-left: 2px solid var(--line);
    border-right: 2px solid var(--line);
    border-top-left-radius: 20px; border-top-right-radius: 20px;
    border-top: 2px solid var(--line);
  }
}
