:root {
  color-scheme: light dark;
  --bg: #f4f4f5;
  --panel: #ffffff;
  --panel-2: #f7f7f8;
  --text: #18181b;
  --muted: #71717a;
  --border: #d4d4d8;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --shadow: 0 8px 30px rgba(0, 0, 0, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f10;
    --panel: #18181b;
    --panel-2: #222225;
    --text: #fafafa;
    --muted: #a1a1aa;
    --border: #3f3f46;
    --accent: #60a5fa;
    --accent-soft: #172554;
    --shadow: 0 8px 30px rgba(0, 0, 0, .2);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.app-shell {
  width: min(100%, 860px);
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px calc(88px + env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  padding: 6px 0 14px;
  border-bottom: 1px solid var(--border);
}
.brand-button {
  border: 0;
  background: transparent;
  color: inherit;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 4px 0;
  text-align: left;
}
.brand-icon { font-size: 30px; line-height: 1; }
.brand-button strong {
  display: block;
  font-size: clamp(19px, 4vw, 30px);
  line-height: 1.15;
  font-weight: 900;
  letter-spacing: .01em;
}
.brand-button small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; letter-spacing: .14em; }

.icon-button {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 14px;
  min-width: 46px;
  min-height: 46px;
  display: inline-grid;
  place-items: center;
  font-size: 24px;
}
.icon-button.primary { background: var(--accent); color: white; border-color: var(--accent); }

.main-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 22px;
}
.nav-card {
  min-height: 82px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 16px;
  padding: 10px 6px;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.nav-card.active { border: 2px solid var(--accent); background: var(--accent-soft); }
.nav-card strong { font-size: 14px; }
.nav-card small { font-size: 11px; color: var(--muted); }
.nav-emoji { font-size: 24px; line-height: 1; margin-bottom: 2px; }

.view { display: none; }
.view.active { display: block; }
.home-section + .home-section { margin-top: 28px; }
.section-heading, .library-title-row, .library-toolbar, .detail-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.section-heading { margin-bottom: 10px; }
.section-heading h1, .section-heading h2, .library-title-row h1 { margin: 0; font-size: 22px; }
.eyebrow { font-size: 12px; font-weight: 800; letter-spacing: .05em; color: var(--muted); margin: 0 0 2px; }
.playing-text { color: var(--danger); }
.completed-text {
  background: linear-gradient(90deg,#ef4444,#f59e0b,#22c55e,#0ea5e9,#8b5cf6,#ec4899);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.count-badge { border: 1px solid var(--border); border-radius: 999px; padding: 5px 10px; font-size: 13px; white-space: nowrap; }
.playing-count { border: 2px solid var(--danger); }
.game-stack { display: grid; gap: 12px; }

.game-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  padding: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.game-card.playing { border: 2px solid var(--danger); background: linear-gradient(135deg, rgba(220,38,38,.08), var(--panel) 46%); }
.rainbow-wrap {
  border-radius: 20px;
  padding: 3px;
  background: linear-gradient(110deg,#ef4444,#f59e0b,#eab308,#22c55e,#06b6d4,#3b82f6,#8b5cf6,#ec4899,#ef4444);
  background-size: 260% 260%;
  animation: rainbowMove 5s linear infinite;
}
.rainbow-wrap .game-card { border: 0; border-radius: 17px; }
.rainbow-wrap .game-card::after {
  content: "";
  position: absolute;
  inset: -45%;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 42%, rgba(255,255,255,.55) 49%, transparent 56%);
  transform: translateX(-55%);
  animation: shine 4.5s ease-in-out infinite;
}
.sparkle { position: absolute; z-index: 3; pointer-events: none; animation: twinkle 1.8s ease-in-out infinite; }
.sparkle.s1 { top: 9px; right: 16px; }
.sparkle.s2 { top: 34px; right: 46px; animation-delay: .55s; }
.sparkle.s3 { bottom: 9px; right: 23px; animation-delay: 1.05s; }

.game-row { display: flex; gap: 14px; align-items: flex-start; position: relative; z-index: 2; }
.cover-button { border: 0; background: transparent; padding: 0; flex: 0 0 auto; }
.cover-box {
  width: 72px;
  aspect-ratio: 3 / 4;
  border-radius: 9px;
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--panel-2);
  display: grid;
  place-items: center;
}
.cover-box img { width: 100%; height: 100%; object-fit: cover; }
.cover-placeholder { padding: 7px; text-align: center; font-size: 10px; line-height: 1.25; word-break: break-word; }
.cover-placeholder strong { display: block; font-size: 11px; margin-bottom: 7px; }
.game-main { min-width: 0; flex: 1; }
.game-topline { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; }
.game-title-button { border: 0; background: transparent; padding: 0; text-align: left; min-width: 0; color: inherit; }
.platform-label { color: var(--muted); font-size: 11px; font-weight: 800; }
.game-title { margin: 3px 0 0; font-size: 18px; line-height: 1.25; overflow-wrap: anywhere; }
.status-pill { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 999px; padding: 5px 8px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.status-pill.playing { border: 2px solid var(--danger); color: var(--danger); }
.game-meta { margin-top: 10px; display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; font-size: 12px; }
.game-meta span { color: var(--muted); display: block; margin-bottom: 2px; }
.rating-row { margin-top: 9px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.rating-label { font-size: 11px; color: var(--muted); margin-right: 3px; }
.star-button { border: 0; background: transparent; padding: 0 1px; min-width: 25px; min-height: 36px; font-size: 23px; line-height: 1; color: #a3a3a3; }
.star-button.on { color: #f5b301; text-shadow: 0 1px 2px rgba(0,0,0,.2); }
.rating-score { color: var(--muted); font-size: 11px; margin-left: 4px; }

.trophy-summary { margin-top: 10px; border: 1px solid var(--border); border-radius: 12px; padding: 9px 10px; }
.trophy-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; font-weight: 800; }
.trophy-bar { height: 8px; border-radius: 999px; background: var(--panel-2); overflow: hidden; margin-top: 7px; }
.trophy-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg,#b7791f,#f6c344); }

.empty-state { border: 1px dashed var(--border); border-radius: 18px; padding: 24px 16px; text-align: center; color: var(--muted); background: var(--panel); }
.empty-state strong { color: var(--text); display: block; margin-bottom: 6px; }

.library-toolbar, .detail-toolbar { margin-bottom: 14px; }
.back-button, .secondary-button, .primary-button {
  min-height: 44px;
  border-radius: 12px;
  padding: 9px 14px;
  font-weight: 700;
}
.back-button, .secondary-button { border: 1px solid var(--border); background: var(--panel); }
.primary-button { border: 1px solid var(--accent); background: var(--accent); color: white; }
.library-title-row { margin-bottom: 12px; }
.library-title-row p { margin: 3px 0 0; font-size: 13px; }
.search-box { display: block; margin-bottom: 14px; }
.search-box span, .field > span { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.search-box input, .field input, .field select, .field textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  padding: 10px 12px;
  font-size: 16px;
  outline: none;
}
.field textarea { min-height: 110px; resize: vertical; }
.search-box input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

.detail-hero { display: flex; gap: 18px; padding: 16px; border: 1px solid var(--border); border-radius: 18px; background: var(--panel); box-shadow: var(--shadow); }
.detail-cover { width: 150px; aspect-ratio: 3/4; border-radius: 12px; border: 1px solid var(--border); overflow: hidden; background: var(--panel-2); flex: 0 0 auto; display: grid; place-items: center; }
.detail-cover img { width: 100%; height: 100%; object-fit: cover; }
.detail-copy { min-width: 0; flex: 1; }
.detail-copy h1 { margin: 4px 0 10px; font-size: 26px; line-height: 1.2; overflow-wrap: anywhere; }
.detail-section { margin-top: 14px; border: 1px solid var(--border); border-radius: 18px; background: var(--panel); padding: 16px; }
.detail-section h2 { margin: 0 0 12px; font-size: 18px; }
.detail-grid { display: grid; grid-template-columns: 110px 1fr; gap: 10px 14px; font-size: 14px; }
.detail-grid dt { color: var(--muted); }
.detail-grid dd { margin: 0; }
.trophy-detail-grid { margin-top: 14px; display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 8px; }
.trophy-medal { border: 1px solid var(--border); border-radius: 12px; padding: 10px 5px; text-align: center; }
.trophy-medal .medal { font-size: 22px; }
.trophy-medal strong { display: block; margin-top: 3px; font-size: 19px; }
.trophy-medal small { color: var(--muted); font-size: 10px; }
.memo-box { white-space: pre-wrap; line-height: 1.7; }
.detail-actions { margin-top: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.danger-button { min-height: 44px; border: 1px solid #ef4444; background: transparent; color: #ef4444; border-radius: 12px; font-weight: 800; }

.game-dialog, .install-dialog { border: 0; padding: 0; background: transparent; color: var(--text); width: min(94vw, 660px); max-height: 92vh; }
.game-dialog::backdrop, .install-dialog::backdrop { background: rgba(0,0,0,.55); }
.dialog-form, .install-card { background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 18px; max-height: 90vh; overflow: auto; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.dialog-header h2 { margin: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid.compact { margin-top: 10px; }
.field.full, .trophy-form.full, .cover-preview-wrap.full { grid-column: 1 / -1; }
.field small { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.trophy-form { border: 1px solid var(--border); border-radius: 14px; padding: 12px; background: var(--panel-2); }
.trophy-form-title { font-weight: 800; }
.cover-preview-wrap { display: flex; align-items: flex-start; gap: 12px; }
.cover-preview-wrap img { width: 100px; aspect-ratio: 3/4; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
.danger-link { border: 0; background: transparent; color: #ef4444; font-weight: 700; padding: 8px 0; }
.dialog-actions { margin-top: 16px; display: flex; justify-content: flex-end; gap: 8px; }
.install-card h2 { margin-top: 0; }
.install-card p { line-height: 1.6; }

.app-footer {
  width: min(100%, 860px);
  margin: 0 auto;
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
}
.app-footer button { border: 0; background: transparent; color: var(--accent); font-weight: 800; padding: 8px 0; }

@keyframes rainbowMove { 0%{background-position:0% 50%} 100%{background-position:260% 50%} }
@keyframes shine { 0%,62%{transform:translateX(-55%)} 85%,100%{transform:translateX(55%)} }
@keyframes twinkle { 0%,100%{opacity:.25;transform:scale(.7)} 50%{opacity:1;transform:scale(1.25)} }
@media (prefers-reduced-motion: reduce) {
  .rainbow-wrap, .rainbow-wrap .game-card::after, .sparkle { animation: none; }
}

@media (max-width: 600px) {
  .app-shell { padding-left: 10px; padding-right: 10px; }
  .brand-icon { display: none; }
  .brand-button strong { font-size: 19px; }
  .nav-card { min-height: 76px; }
  .nav-card strong { font-size: 12px; }
  .game-card { padding: 12px; }
  .cover-box { width: 62px; }
  .game-row { gap: 10px; }
  .game-topline { display: block; }
  .status-pill { margin-top: 7px; }
  .game-meta { grid-template-columns: 1fr 1fr; }
  .detail-hero { flex-direction: column; }
  .detail-cover { width: 126px; }
  .detail-grid { grid-template-columns: 96px 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full, .trophy-form.full, .cover-preview-wrap.full { grid-column: auto; }
  .trophy-detail-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .app-footer span { text-align: right; }
}

.detail-hero.playing { border: 2px solid var(--danger); background: linear-gradient(135deg, rgba(220,38,38,.08), var(--panel) 46%); }


/* Online game information lookup */
.lookup-panel {
  grid-column: 1 / -1;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: var(--panel-2);
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 10px 12px;
  align-items: center;
}
.lookup-panel strong { display: block; }
.lookup-panel small { display: block; margin-top: 4px; color: var(--muted); line-height: 1.5; }
.lookup-button { min-height: 44px; border: 1px solid var(--accent); border-radius: 12px; background: var(--accent); color: white; padding: 9px 14px; font-weight: 800; }
.lookup-button:disabled { opacity: .55; cursor: wait; }
.lookup-status { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.lookup-dialog { border: 0; padding: 0; background: transparent; color: var(--text); width: min(94vw, 760px); max-height: 92vh; }
.lookup-dialog::backdrop { background: rgba(0,0,0,.55); }
.lookup-card { background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 18px; max-height: 90vh; overflow: auto; }
.lookup-description { margin: -4px 0 14px; line-height: 1.6; }
.lookup-results { display: grid; gap: 10px; }
.lookup-result { border: 1px solid var(--border); border-radius: 16px; padding: 12px; display: grid; grid-template-columns: 88px minmax(0,1fr); gap: 13px; background: var(--panel-2); }
.lookup-result-warning { border-style: dashed; }
.lookup-cover { width: 88px; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden; background: var(--panel); border: 1px solid var(--border); display: grid; place-items: center; }
.lookup-cover img { width: 100%; height: 100%; object-fit: cover; }
.lookup-cover-placeholder { font-size: 10px; color: var(--muted); text-align: center; padding: 8px; }
.lookup-copy { min-width: 0; }
.lookup-copy h3 { margin: 0 0 7px; font-size: 17px; line-height: 1.35; overflow-wrap: anywhere; }
.lookup-copy p { margin: 3px 0; font-size: 12px; color: var(--muted); line-height: 1.45; }
.lookup-copy p strong { color: var(--text); }
.lookup-warning { color: #b45309 !important; font-weight: 700; }
.lookup-select { margin-top: 9px; }
@media (max-width: 600px) {
  .lookup-panel { grid-template-columns: 1fr; }
  .lookup-button { width: 100%; }
  .lookup-status { grid-column: auto; }
  .lookup-result { grid-template-columns: 72px minmax(0,1fr); padding: 10px; }
  .lookup-cover { width: 72px; }
}
