:root {
  --ink: #17191f;
  --paper: #fff8e7;
  --cream: #f5e7c7;
  --red: #e4572e;
  --orange: #f6ae2d;
  --blue: #3b82f6;
  --green: #38a169;
  --purple: #805ad5;
  --shadow: 5px 5px 0 var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--cream); color: var(--ink); }
body { font-family: 'Courier New', monospace; font-size: 18px; letter-spacing: .01em; }
button, input { font: inherit; }
button { cursor: pointer; }

.crt-noise { position: fixed; inset: 0; pointer-events: none; opacity: .08; z-index: 50; background-image: repeating-linear-gradient(0deg, transparent 0 3px, #17191f 4px); mix-blend-mode: multiply; }
.shell { min-height: 100vh; position: relative; overflow: hidden; }
.topbar { height: 78px; display: flex; align-items: center; justify-content: space-between; padding: 16px clamp(18px, 5vw, 70px); border-bottom: 3px solid var(--ink); background: var(--paper); position: relative; z-index: 2; }
.brand { display: flex; align-items: center; gap: 13px; font-family: 'Courier New', monospace; font-weight: 900; font-size: clamp(12px, 1.5vw, 18px); }
.brand-mark { width: 40px; height: 40px; border: 3px solid var(--ink); background: var(--red); box-shadow: 4px 4px 0 var(--ink); display: grid; place-items: center; color: white; font-family: 'Courier New'; font-size: 17px; }
.user-chip { display: flex; align-items: center; gap: 12px; }
.pixel-avatar { width: 34px; height: 34px; border: 3px solid var(--ink); background: var(--orange); display: grid; place-items: center; font-family: 'Press Start 2P'; font-size: 12px; }
.ghost-btn, .solid-btn { border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); padding: 8px 13px; background: transparent; color: var(--ink); }
.ghost-btn:hover, .solid-btn:hover { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.solid-btn { background: var(--red); color: white; }
.solid-btn.blue { background: var(--blue); }
.solid-btn.green { background: var(--green); }

.page { max-width: 1280px; margin: 0 auto; padding: 42px clamp(18px, 5vw, 70px) 70px; }
.hero { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(280px, .8fr); gap: 30px; align-items: end; margin-bottom: 34px; }
.eyebrow { color: var(--red); font-family: 'Courier New'; font-weight: 900; font-size: 12px; line-height: 1.7; }
h1, h2, h3, p { margin: 0; }
h1 { font-family: 'Courier New'; font-weight: 900; font-size: clamp(28px, 5vw, 64px); line-height: 1.2; max-width: 720px; margin: 12px 0 17px; }
.hero-copy { font-size: 26px; line-height: 1.2; max-width: 650px; }
.hero-card { background: var(--ink); color: var(--paper); border: 3px solid var(--ink); padding: 20px; box-shadow: var(--shadow); transform: rotate(1deg); }
.hero-card .mini-label { color: var(--orange); font-family: 'Courier New'; font-weight: 900; font-size: 11px; }
.hero-card strong { display: block; font-size: 33px; margin: 13px 0 3px; }
.hero-card span { color: #b7bac1; }
.filter-row { display: flex; gap: 10px; align-items: center; margin: 28px 0 16px; flex-wrap: wrap; }
.filter-row button { border: 2px solid var(--ink); background: transparent; padding: 7px 13px; color: var(--ink); }
.filter-row button.active { background: var(--ink); color: var(--paper); }
.section-title { display: flex; justify-content: space-between; align-items: end; border-bottom: 3px solid var(--ink); padding-bottom: 10px; margin: 0 0 18px; }
.section-title h2 { font-family: 'Courier New'; font-weight: 900; font-size: 17px; }
.section-title span { font-size: 18px; color: #635d50; }
.game-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px; }
.game-card { border: 3px solid var(--ink); background: var(--paper); box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 350px; transition: transform .15s ease; }
.game-card:hover { transform: translateY(-5px); }
.game-art { min-height: 190px; position: relative; overflow: hidden; border-bottom: 3px solid var(--ink); image-rendering: pixelated; }
.game-art.gomoku { background: #e5a94f; background-image: linear-gradient(90deg, rgba(23,25,31,.18) 2px, transparent 2px), linear-gradient(rgba(23,25,31,.18) 2px, transparent 2px); background-size: 29px 29px; display: grid; place-items: center; }
.mini-board { width: 150px; height: 150px; border: 3px solid var(--ink); background: #ebbd67; background-image: linear-gradient(90deg, rgba(23,25,31,.45) 2px, transparent 2px), linear-gradient(rgba(23,25,31,.45) 2px, transparent 2px); background-size: 21px 21px; position: relative; }
.mini-board:before, .mini-board:after { content: ''; position: absolute; width: 23px; height: 23px; border-radius: 50%; border: 3px solid var(--ink); top: 38px; left: 47px; background: var(--ink); box-shadow: 42px 42px 0 var(--paper), -21px 63px 0 var(--ink); }
.mini-board:after { background: var(--paper); left: 89px; top: 17px; }
.game-art.mario { background: #36a9e1; }
.mario-sky { position: absolute; inset: auto 0 0; height: 53px; background: #64c12b; border-top: 4px solid var(--ink); box-shadow: inset 0 -20px #8c542d; }
.mario-cloud { position: absolute; width: 72px; height: 18px; background: white; top: 30px; left: 22px; box-shadow: 18px -13px 0 white, 38px 0 0 white; }
.mario-cloud.two { top: 85px; left: auto; right: 28px; transform: scale(.7); }
.mario-hero { position: absolute; bottom: 45px; left: 32%; width: 34px; height: 43px; background: var(--red); border: 3px solid var(--ink); box-shadow: 7px 9px 0 var(--ink), -3px 22px 0 var(--orange); }
.question-block { position: absolute; right: 23%; top: 38px; width: 29px; height: 29px; background: var(--orange); border: 3px solid var(--ink); color: white; text-align: center; font-family: 'Courier New'; font-weight: 900; font-size: 16px; line-height: 22px; }
.game-art.tank { background: #7ca56b; background-image: linear-gradient(135deg, transparent 20%, rgba(23,25,31,.12) 20% 25%, transparent 25% 50%, rgba(23,25,31,.12) 50% 55%, transparent 55%); background-size: 43px 43px; }
.tank-shell { position: absolute; width: 56px; height: 44px; background: var(--green); border: 3px solid var(--ink); left: 35%; top: 52%; transform: translate(-50%,-50%); box-shadow: inset 0 -9px #277149; }
.tank-shell:before { content: ''; position: absolute; width: 10px; height: 27px; background: var(--ink); top: -22px; left: 21px; }
.tank-shell:after { content: ''; position: absolute; inset: 10px 13px; background: var(--orange); border: 3px solid var(--ink); }
.tank-shell.enemy { left: 70%; top: 33%; background: var(--red); }
.game-meta { padding: 17px 18px 19px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.game-meta h3 { font-family: 'Courier New'; font-weight: 900; font-size: 16px; }
.game-meta p { line-height: 1.1; color: #514b40; font-size: 19px; }
.tag-row { display: flex; gap: 7px; margin-top: auto; padding-top: 10px; }
.tag { border: 2px solid var(--ink); padding: 2px 7px; font-size: 16px; background: #ffe0a8; }
.tag.blue { background: #b9d2ff; }
.tag.green { background: #c9efbc; }
.coming { border: 3px dashed #948a76; min-height: 160px; margin-top: 30px; display: grid; place-items: center; color: #736b5b; text-align: center; background: rgba(255,248,231,.45); }
.coming strong { display: block; font-family: 'Courier New'; font-weight: 900; font-size: 13px; margin-bottom: 9px; }
.status-strip { margin-top: 22px; display: flex; gap: 9px; flex-wrap: wrap; color: #635d50; font-size: 17px; }
.status-dot { width: 9px; height: 9px; display: inline-block; border-radius: 50%; background: var(--green); margin-right: 5px; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: radial-gradient(circle at 15% 20%, #ffe0a8 0 8%, transparent 8.2%), radial-gradient(circle at 90% 85%, #b9d2ff 0 9%, transparent 9.2%), var(--cream); }
.login-box { width: min(460px, 100%); border: 3px solid var(--ink); background: var(--paper); box-shadow: 8px 8px 0 var(--ink); padding: 30px; }
.login-box h1 { font-size: 24px; margin: 16px 0 9px; }
.login-box p { font-size: 21px; color: #635d50; margin-bottom: 24px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 17px; }
.field input, .field select { width: 100%; border: 3px solid var(--ink); background: white; padding: 9px 11px; outline: none; }
.field input:focus { box-shadow: 3px 3px 0 var(--blue); }
.login-box .solid-btn { width: 100%; margin-top: 6px; font-family: 'Courier New'; font-weight: 900; font-size: 13px; padding: 13px; }
.hint { margin-top: 16px; border-top: 2px dashed #c7bda6; padding-top: 12px; font-size: 17px; color: #736b5b; }
.error { color: var(--red); min-height: 22px; font-size: 18px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(23,25,31,.74); display: grid; place-items: center; padding: 18px; z-index: 10; }
.modal { width: min(1240px, 100%); max-height: calc(100vh - 28px); overflow: auto; border: 3px solid var(--ink); background: var(--paper); box-shadow: 8px 8px 0 #000; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 15px; padding: 16px 20px; border-bottom: 3px solid var(--ink); background: #ffe0a8; }
.modal-head h2 { font-family: 'Courier New'; font-weight: 900; font-size: 16px; }
.modal-body { padding: 20px; }
.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.canvas-wrap { position: relative; min-height: 560px; background: #14161b; border: 3px solid var(--ink); padding: 12px; display: grid; place-items: center; overflow: hidden; }
canvas { display: block; width: 100%; max-width: 1080px; height: auto; image-rendering: pixelated; background: #eee; outline: none; }
.result-overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 22px; background: rgba(23,25,31,.78); color: var(--paper); z-index: 2; text-align: center; }
.result-overlay[hidden] { display: none; }
.result-panel { width: min(440px, 92%); border: 3px solid var(--paper); background: var(--ink); box-shadow: 6px 6px 0 var(--red); padding: 24px; }
.result-panel h2 { font-family: 'Courier New'; font-weight: 900; font-size: clamp(22px, 4vw, 38px); margin-bottom: 10px; }
.result-panel p { color: #d9d5c8; line-height: 1.35; margin-bottom: 16px; }
.result-panel .solid-btn, .result-panel .ghost-btn { margin: 4px; }
.stat-block { display: grid; gap: 7px; margin-top: 10px; }
.stat-line { display: grid; grid-template-columns: 42px 1fr 54px; gap: 7px; align-items: center; font-size: 15px; }
.stat-track { height: 14px; border: 2px solid var(--ink); background: #d8d2c2; }
.stat-fill { height: 100%; transition: width .12s linear; }
.stat-fill.hp { background: var(--red); }
.stat-fill.energy { background: var(--blue); }
.unit-highlight { color: #9d6a00; font-weight: 900; }
.skill-list { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin: 10px 0; }
.skill-button { padding: 7px 5px; font-size: 14px; text-align: left; box-shadow: 2px 2px 0 var(--ink); }
.skill-button small { display: block; color: #635d50; font-size: 12px; margin-top: 3px; }
.skill-button:disabled { cursor: not-allowed; opacity: .48; transform: none; box-shadow: 2px 2px 0 var(--ink); }
.mono-actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 9px 0; }
.mono-hand, .mono-items, .mono-shop { display: grid; gap: 6px; margin: 7px 0 12px; }
.mono-card { text-align: left; padding: 7px; box-shadow: 2px 2px 0 var(--ink); }
.mono-card strong { display: block; font-size: 14px; }
.mono-card small { display: block; color: #635d50; line-height: 1.15; margin-top: 3px; }
.mono-card.white { background: #fff; }
.mono-card.green { background: #d5f2cf; }
.mono-card.blue { background: #cfe2ff; }
.mono-card.purple { background: #eadcff; }
.mono-items button, .mono-shop button { padding: 6px 8px; font-size: 14px; text-align: left; box-shadow: 2px 2px 0 var(--ink); }
.mono-log { max-height: 115px; overflow: auto; background: #17191f; color: #fff8e7; padding: 7px; font-size: 13px; line-height: 1.25; }
.mono-room-code { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px; border: 2px dashed var(--ink); background: #ffe0a8; font-size: 13px; }
.mono-room-code button { padding: 4px 7px; font-size: 12px; box-shadow: 2px 2px 0 var(--ink); }
.mono-turn-banner { display: grid; gap: 3px; padding: 9px; margin: 8px 0; border: 3px solid var(--ink); background: #e6e0d2; }
.mono-turn-banner.active { background: #c9efbc; animation: turnPulse .9s steps(2, end) infinite; }
.mono-turn-banner strong { font-size: 16px; }
.mono-turn-banner span, .rule-hint { font-size: 13px; line-height: 1.25; }
.mono-merge { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-bottom: 10px; }
.mono-merge select { min-width: 0; border: 2px solid var(--ink); background: white; padding: 6px; }
.mono-shop button strong, .mono-shop button small { display: block; }
.mono-shop button small { margin-top: 3px; color: #635d50; }
.lobby-roster { display: grid; gap: 7px; margin: 12px 0 18px; text-align: left; }
.lobby-roster div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed #736b5b; padding: 5px 0; }
.danger-link { width: 100%; border: 0; background: transparent; color: var(--red); text-decoration: underline; font-size: 12px; margin: 5px 0; }
.game-busy button { cursor: wait; }
@keyframes turnPulse { 50% { box-shadow: 3px 3px 0 var(--green); } }
.game-info { display: grid; gap: 12px; }
.info-card { border: 3px solid var(--ink); padding: 13px; background: #fffdf7; }
.info-card h3 { font-family: 'Courier New'; font-weight: 900; font-size: 12px; margin-bottom: 10px; }
.info-card p { font-size: 20px; line-height: 1.12; }
.key { display: inline-block; border: 2px solid var(--ink); background: white; padding: 1px 5px; min-width: 24px; text-align: center; }
.modal-actions { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 15px; }
.room-list { display: grid; gap: 9px; margin: 10px 0 18px; }
.room { border: 2px solid var(--ink); background: white; padding: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.room small { color: #736b5b; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.admin-grid .info-card { min-height: 180px; }
.account-row { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px dashed #c7bda6; padding: 6px 0; }
.account-row:last-child { border-bottom: 0; }
.account-password-edit { display: flex; gap: 6px; align-items: center; margin-top: 7px; }
.account-password-edit input { width: 145px; border: 2px solid var(--ink); padding: 5px 7px; background: white; }
.account-password-edit button { padding: 4px 8px; box-shadow: 2px 2px 0 var(--ink); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); border: 3px solid var(--paper); box-shadow: 4px 4px 0 var(--red); padding: 10px 16px; z-index: 30; }

@media (max-width: 840px) {
  .hero { grid-template-columns: 1fr; }
  .game-grid { grid-template-columns: 1fr; }
  .game-card { min-height: auto; }
  .game-layout, .admin-grid { grid-template-columns: 1fr; }
  .topbar { height: auto; gap: 12px; align-items: flex-start; }
  .user-chip { font-size: 17px; }
  h1 { font-size: 30px; }
}
