* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', 'Hiragino Sans', sans-serif; background: #0a0e1a; color: #e0e0e0; min-height: 100vh; }
.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }

h1 { font-size: 2rem; text-align: center; padding-top: 60px; color: #7eb8ff; }
.subtitle { text-align: center; color: #888; margin: 8px 0 30px; }

.lobby-form { max-width: 400px; margin: 0 auto; padding: 20px; }
.lobby-form input, .lobby-form select { width: 100%; padding: 10px 14px; margin: 6px 0; border: 1px solid #333; border-radius: 6px; background: #151a2a; color: #e0e0e0; font-size: 1rem; }
.lobby-form input:focus { border-color: #7eb8ff; outline: none; }
.lobby-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.lobby-actions button { padding: 10px 20px; border: none; border-radius: 6px; background: #2a5db0; color: #fff; font-size: 1rem; cursor: pointer; }
.lobby-actions button:hover { background: #3a6dd0; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; }
.room-info { margin-top: 16px; padding: 12px; background: #151a2a; border-radius: 6px; text-align: center; }
.room-id { font-family: monospace; font-size: 1.1rem; color: #7eb8ff; user-select: all; }
.btn-small { padding: 4px 10px; border: 1px solid #555; border-radius: 4px; background: #1a1f30; color: #aaa; font-size: 0.8rem; cursor: pointer; }
.btn-small:hover { background: #252b40; color: #fff; }

.deck-header { padding: 16px 20px; border-bottom: 1px solid #222; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.deck-header h2 { color: #7eb8ff; font-size: 1.3rem; }
.deck-header p { color: #888; font-size: 0.85rem; }
.deck-info { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.deck-info span { font-size: 1.1rem; color: #7eb8ff; font-weight: bold; }
.btn-start { padding: 8px 20px; border: none; border-radius: 6px; background: #2a8a4a; color: #fff; font-size: 1rem; cursor: pointer; }
.btn-start:disabled { background: #333; color: #666; cursor: not-allowed; }
.btn-start:not(:disabled):hover { background: #3aaa5a; }
.btn-danger { border-color: #a44; color: #c66; }

.deck-layout { display: grid; grid-template-columns: 1fr 280px; height: calc(100vh - 70px); }
.card-filters { grid-column: 1 / -1; display: flex; gap: 8px; padding: 10px 20px; background: #0d1120; border-bottom: 1px solid #222; flex-wrap: wrap; }
.card-filters input, .card-filters select { padding: 6px 10px; border: 1px solid #333; border-radius: 4px; background: #151a2a; color: #e0e0e0; font-size: 0.9rem; }
.card-filters input { flex: 1; min-width: 180px; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; padding: 12px 20px; overflow-y: auto; align-content: start; }

.card-item { background: #151a2a; border: 1px solid #2a2a3a; border-radius: 6px; padding: 8px; cursor: pointer; transition: all 0.15s; position: relative; }
.card-item:hover { border-color: #7eb8ff; transform: translateY(-2px); }
.card-item.in-deck { border-color: #4a8a4a; }
.card-cost { position: absolute; top: 4px; left: 4px; background: #2a5db0; color: #fff; border-radius: 50%; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 0.85rem; }
.card-img { width: 100%; aspect-ratio: 488/680; object-fit: cover; border-radius: 4px; background: #0a0e1a; }
.card-name { font-size: 0.78rem; margin-top: 4px; line-height: 1.2; color: #ccc; }
.card-meta { font-size: 0.7rem; color: #888; margin-top: 2px; }
.card-stats { font-size: 0.75rem; color: #7eb8ff; margin-top: 2px; }
.card-effect { font-size: 0.68rem; color: #999; margin-top: 3px; max-height: 40px; overflow: hidden; line-height: 1.3; }
.class-forest { border-left: 3px solid #4caf50; }
.class-sword { border-left: 3px solid #ffc107; }
.class-rune { border-left: 3px solid #2196f3; }
.class-dragon { border-left: 3px solid #ff5722; }
.class-abyss { border-left: 3px solid #9c27b0; }
.class-haven { border-left: 3px solid #ffeb3b; }
.class-portal { border-left: 3px solid #00bcd4; }
.class-neutral { border-left: 3px solid #9e9e9e; }

.deck-panel { background: #0d1120; border-left: 1px solid #222; padding: 12px; overflow-y: auto; }
.deck-panel h3 { color: #7eb8ff; margin-bottom: 8px; font-size: 1rem; }
.deck-list-item { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 4px; margin-bottom: 3px; background: #151a2a; font-size: 0.8rem; cursor: pointer; }
.deck-list-item:hover { background: #1a2030; }
.deck-list-cost { background: #2a5db0; color: #fff; border-radius: 50%; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: bold; flex-shrink: 0; }
.deck-list-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-list-remove { color: #c66; cursor: pointer; font-weight: bold; padding: 0 4px; }

.battle-top, .battle-bottom { padding: 8px 16px; }
.player-info { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.p-name { font-weight: bold; font-size: 1rem; }
.p-hp { color: #e57373; }
.my-hp { color: #ef5350; font-weight: bold; }
.p-pp { color: #64b5f6; }
.my-pp { color: #42a5f5; font-weight: bold; }
.p-sep { color: #ffd54f; }
.p-deck { color: #888; }
.p-hand { color: #aaa; }
.p-grave { color: #777; }

.battle-field { display: flex; flex-direction: column; align-items: center; padding: 10px 16px; }
.field-row { display: flex; gap: 8px; min-height: 100px; padding: 8px; background: #0d1120; border-radius: 8px; width: 100%; max-width: 700px; justify-content: center; flex-wrap: wrap; }
.opponent-field { border: 1px solid #3a2020; }
.my-field { border: 1px solid #20303a; }
.field-divider { color: #555; font-size: 0.9rem; margin: 4px 0; }

.field-card { width: 90px; padding: 6px; border-radius: 6px; background: #1a2040; border: 1px solid #333; cursor: pointer; text-align: center; font-size: 0.72rem; transition: all 0.15s; }
.field-card:hover { border-color: #7eb8ff; transform: scale(1.05); }
.field-card.selected { border-color: #ffd54f; box-shadow: 0 0 8px rgba(255,213,79,0.4); }
.field-card.can-attack { border-color: #4caf50; }
.field-card.evolved { border-color: #ff9800; background: #1a2540; }
.field-card.super-evolved { border-color: #ffd54f; background: #202530; }
.field-card .fc-img { width: 100%; aspect-ratio: 488/680; object-fit: cover; border-radius: 3px; background: #0a0e1a; }
.field-card .fc-name { margin-top: 3px; font-size: 0.68rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field-card .fc-stats { color: #7eb8ff; font-weight: bold; font-size: 0.8rem; margin-top: 2px; }
.field-card .fc-ward { color: #ffd54f; font-size: 0.65rem; }
.field-card.targetable { border-color: #e57373; }

.battle-actions { text-align: center; margin: 6px 0; }
.btn-action { padding: 8px 24px; border: none; border-radius: 6px; background: #2a5db0; color: #fff; font-size: 1rem; cursor: pointer; }
.btn-action:disabled { background: #333; color: #666; cursor: not-allowed; }
.btn-action:not(:disabled):hover { background: #3a6dd0; }

.hand-area { display: flex; gap: 6px; padding: 10px 16px; overflow-x: auto; background: #0a0e1a; border-top: 1px solid #222; min-height: 140px; align-items: flex-end; }
.hand-card { min-width: 100px; padding: 6px; border-radius: 6px; background: #151a2a; border: 2px solid #333; cursor: pointer; text-align: center; font-size: 0.72rem; transition: all 0.15s; flex-shrink: 0; }
.hand-card:hover { border-color: #7eb8ff; transform: translateY(-4px); }
.hand-card.playable { border-color: #4caf50; }
.hand-card.selected { border-color: #ffd54f; box-shadow: 0 0 8px rgba(255,213,79,0.4); }
.hand-card .hc-cost { background: #2a5db0; color: #fff; border-radius: 50%; width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; font-weight: bold; font-size: 0.85rem; }
.hand-card .hc-img { width: 100%; aspect-ratio: 488/680; object-fit: cover; border-radius: 3px; margin-top: 4px; background: #0a0e1a; }
.hand-card .hc-name { margin-top: 3px; font-size: 0.7rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hand-card .hc-stats { color: #7eb8ff; font-size: 0.75rem; }
.hand-card .hc-type { color: #888; font-size: 0.65rem; }

.battle-log { position: fixed; top: 10px; right: 10px; width: 240px; max-height: 200px; overflow-y: auto; background: rgba(10,14,26,0.9); border: 1px solid #222; border-radius: 6px; padding: 8px; font-size: 0.75rem; color: #aaa; z-index: 10; }
.log-entry { padding: 2px 0; border-bottom: 1px solid #1a1a2a; }
.log-entry:last-child { border-bottom: none; }

.game-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center; z-index: 100; }
.overlay-content { background: #151a2a; padding: 40px 60px; border-radius: 12px; text-align: center; border: 1px solid #333; }
.overlay-content h2 { color: #7eb8ff; font-size: 2rem; margin-bottom: 12px; }
.overlay-content p { color: #aaa; margin-bottom: 20px; }
.overlay-content button { padding: 10px 30px; border: none; border-radius: 6px; background: #2a5db0; color: #fff; font-size: 1rem; cursor: pointer; }

.error-toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #c62828; color: #fff; padding: 10px 24px; border-radius: 6px; font-size: 0.9rem; z-index: 200; animation: fadeInOut 2.5s forwards; }
@keyframes fadeInOut { 0% { opacity: 0; } 10% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }

@media (max-width: 700px) {
  .deck-layout { grid-template-columns: 1fr; }
  .deck-panel { max-height: 200px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}
