@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Noto+Sans+JP:wght@400;700&family=Share+Tech+Mono&display=swap');

  :root {
    --green: #00ff41;
    --green-dim: #00aa2a;
    --green-dark: #003a10;
    --amber: #ffb000;
    --amber-dim: #cc8800;
    --red: #ff2222;
    --cyan: #00ffff;
    --black: #000000;
    --dark: #050505;
    --panel: #0a0a0a;
    --text: #e8e8e8;
    --text-dim: #888888;
    --border: rgba(0,255,65,0.25);
    --gold: #ffb000;
    --gold-light: #ffcc44;
    --crimson: #cc0000;
    --crimson-light: #ff2222;
    --win: #00ff41;
    --lose: #ff2222;
  }

  * { margin:0; padding:0; box-sizing:border-box; }

  /* スキャンラインはタイトル画面のみ */
  #screen-title::after {
    content: '';
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(0,0,0,0.12) 2px,
      rgba(0,0,0,0.12) 4px
    );
    pointer-events: none;
    z-index: 1;
  }

  body {
    background: var(--black);
    color: var(--text);
    font-family: 'Noto Sans JP', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    cursor: default;
  }

  /* CRTグロー効果 */
  body {
    text-shadow: none;
  }



  /* ===== SCREEN MANAGEMENT ===== */
  .screen { display:none; }
  .screen.active { display:flex; }

  /* ===== TITLE SCREEN ===== */
  #screen-title {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 40px 20px;
    position: relative;
  }

  .title-bg-lines {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
  }
  .title-bg-lines::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
      repeating-linear-gradient(0deg, transparent, transparent 59px, rgba(201,168,76,0.04) 60px),
      repeating-linear-gradient(90deg, transparent, transparent 59px, rgba(201,168,76,0.04) 60px);
  }

  .crown-icon {
    font-size: 48px;
    animation: crownFloat 0.5s steps(2) infinite;
    filter: drop-shadow(0 0 12px var(--amber));
    margin-bottom: 8px;
  }
  @keyframes crownFloat {
    0%,100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
  }

  .title-kod {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(40px, 10vw, 88px);
    color: var(--amber);
    letter-spacing: 0.05em;
    line-height: 1;
    margin-bottom: 10px;
    text-shadow: 3px 3px 0 #663300, 0 0 20px var(--amber), 0 0 40px rgba(255,176,0,0.4);
    animation: titleFlicker 5s ease-in-out infinite;
  }
  @keyframes titleFlicker {
    0%,94%,100%{opacity:1} 95%{opacity:0.7} 96%{opacity:1} 97%{opacity:0.85} 98%{opacity:1}
  }

  .title-jp {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: clamp(14px, 3.5vw, 20px);
    color: var(--green);
    letter-spacing: 0.2em;
    line-height: 1;
    margin-bottom: 6px;
    text-shadow: 0 0 10px var(--green);
  }

  .title-sub {
    font-family: 'Share Tech Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.25em;
    color: #e8e8e8;
    text-transform: uppercase;
    margin-bottom: 36px;
    animation: blink 1.2s step-end infinite;
  }
  @keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

  .title-tagline {
    font-size: 13px;
    color: #e8e8e8;
    margin-bottom: 60px;
    letter-spacing: 0.1em;
    border-left: 2px solid var(--gold);
    padding-left: 16px;
    font-style: italic;
  }

  /* Stage selection */
  .stage-label {
    font-family: 'Share Tech Mono', monospace;
    font-size: 11px;
    letter-spacing: 0.3em;
    color: var(--gold);
    margin-bottom: 20px;
    text-align: center;
  }

  .stages {
    display: flex;
    gap: 16px;
    margin-bottom: 40px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .stage-card {
    background: #000;
    border: 2px solid rgba(0,255,65,0.2);
    padding: 16px 20px;
    cursor: pointer;
    transition: all 0.1s;
    min-width: 140px;
    text-align: center;
    position: relative;
  }
  .stage-card:hover, .stage-card.selected {
    border-color: var(--green);
    background: rgba(0,255,65,0.05);
    box-shadow: 0 0 12px rgba(0,255,65,0.3);
  }
  .stage-card.selected::before {
    content: '►';
    position: absolute;
    left: 6px; top: 50%;
    transform: translateY(-50%);
    color: var(--green);
    font-size: 10px;
    animation: blink 0.8s step-end infinite;
  }
  .stage-card .stage-name {
    font-family: 'Share Tech Mono', monospace;
    font-size: 9px;
    color: var(--amber);
    letter-spacing: 0.2em;
    margin-bottom: 8px;
  }
  .stage-card .stage-title {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 16px;
    color: var(--green);
    margin-bottom: 6px;
    text-shadow: 0 0 8px var(--green);
  }
  .stage-card .stage-desc {
    font-size: 12px;
    color: #e8e8e8;
    font-family: 'Noto Sans JP', sans-serif;
  }

  .stage-card.locked {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
  }
  .stage-lock {
    font-size: 10px;
    color: #888;
    font-family: 'Share Tech Mono', monospace;
    margin-top: 6px;
    letter-spacing: 0.1em;
  }


  /* Mode selection */
  .mode-label {
    font-family: 'Share Tech Mono', monospace;
    font-size: 11px;
    letter-spacing: 0.3em;
    color: var(--gold);
    margin-bottom: 16px;
    text-align: center;
  }

  .modes {
    display: flex;
    gap: 12px;
    margin-bottom: 40px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .mode-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 10px 24px;
    cursor: pointer;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 13px;
    transition: all 0.2s;
  }
  .mode-btn:hover, .mode-btn.selected {
    border-color: var(--gold);
    color: #e8e8e8;
    background: rgba(0,255,65,0.05);
  }

  /* Topic input */
  .topic-area {
    width: 100%;
    max-width: 560px;
    margin-bottom: 32px;
  }
  .topic-label {
    font-family: 'Share Tech Mono', monospace;
    font-size: 11px;
    letter-spacing: 0.3em;
    color: var(--gold);
    margin-bottom: 10px;
    display: block;
  }
  .topic-input {
    width: 100%;
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 14px 16px;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
  }
  .topic-input:focus { border-color: var(--gold); }
  .topic-input::placeholder { color: var(--text-dim); }

  .topic-suggestions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
  }
  .topic-chip {
    background: transparent;
    border: 1px solid rgba(0,255,65,0.3);
    color: #aaaaaa;
    padding: 4px 12px;
    font-size: 11px;
    cursor: pointer;
    font-family: 'Noto Sans JP', sans-serif;
    transition: all 0.15s;
  }
  .topic-chip:hover {
    border-color: var(--gold);
    color: var(--text);
  }

  .start-btn {
    background: #cc0000;
    border: 2px solid #ff4444;
    color: #ffffff;
    padding: 14px 40px;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.15em;
    cursor: pointer;
    transition: all 0.15s;
    box-shadow: 0 0 16px rgba(255,0,0,0.4);
  }
  .start-btn:hover {
    background: #ff0000;
    box-shadow: 0 0 28px rgba(255,0,0,0.7);
  }
  .start-btn:disabled {
    background: #333;
    border-color: #555;
    color: #666;
    cursor: not-allowed;
    box-shadow: none;
  }

  /* ===== GAME SCREEN ===== */
  #screen-game {
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    max-width: 900px;
    margin: 0 auto;
    padding: 0;
    width: 100%;
    overflow: hidden;
  }

  /* Header */
  .game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid rgba(255,176,0,0.15);
    background: rgba(0,0,0,0.95);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 100;
    flex-wrap: wrap;
    gap: 12px;
  }

  .header-left {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .back-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 6px 12px;
    cursor: pointer;
    font-size: 12px;
    font-family: 'Share Tech Mono', monospace;
    transition: all 0.2s;
  }
  .back-btn:hover { border-color: var(--gold); color: var(--text); }

  .opponent-badge {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .opponent-icon { font-size: 20px; }
  .opponent-info .opp-stage {
    font-family: 'Share Tech Mono', monospace;
    font-size: 9px;
    color: var(--gold);
    letter-spacing: 0.2em;
  }
  .opponent-info .opp-name {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 15px;
    font-weight: 700;
  }

  .header-right {
    display: flex;
    align-items: center;
    gap: 16px;
  }

  .mode-indicator {
    font-family: 'Share Tech Mono', monospace;
    font-size: 10px;
    color: var(--text-dim);
    letter-spacing: 0.15em;
  }

  .turn-counter {
    font-family: 'Share Tech Mono', monospace;
    font-size: 12px;
    color: var(--gold);
  }

  /* Win rate bar */
  .winrate-bar-wrap {
    padding: 10px 24px;
    background: rgba(10,10,10,0.95);
    border-bottom: 1px solid rgba(255,176,0,0.15);
    position: sticky;
    top: 57px;
    z-index: 99;
    backdrop-filter: blur(10px);
  }

  .winrate-labels {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 11px;
  }
  .winrate-labels .user-label { color: #00ff41; }
  .winrate-labels .ai-label { color: #ff4444; }

  .winrate-track {
    height: 8px;
    background: rgba(220,30,30,0.85);
    position: relative;
    overflow: hidden;
  }
  .winrate-fill {
    height: 100%;
    background: linear-gradient(90deg, #00cc33, #00ff41);
    transition: width 0.4s cubic-bezier(0.34,1.56,0.64,1);
    position: relative;
  }
  .winrate-fill::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: white;
    box-shadow: 0 0 6px rgba(255,255,255,0.8);
  }
  .winrate-center-line {
    position: absolute;
    left: 50%;
    top: -2px;
    bottom: -2px;
    width: 1px;
    background: rgba(255,255,255,0.3);
  }

  .winrate-pct {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 10px;
    color: var(--text-dim);
  }

  .ko-warning {
    text-align: center;
    font-family: 'Share Tech Mono', monospace;
    font-size: 10px;
    color: #ff4444;
    letter-spacing: 0.2em;
    margin-top: 4px;
    animation: blink 1s step-end infinite;
  }
  @keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

  /* Topic display */
  .topic-display {
    padding: 10px 24px;
    background: rgba(201,168,76,0.05);
    border-bottom: 1px solid rgba(255,176,0,0.15);
  }
  .topic-display-label {
    font-family: 'Share Tech Mono', monospace;
    font-size: 9px;
    color: var(--gold);
    letter-spacing: 0.3em;
    margin-bottom: 2px;
  }
  .topic-display-text {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 14px;
    font-weight: 700;
  }

  /* Chat area */
  .chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #030303;
  }
  .chat-area::-webkit-scrollbar { width: 4px; }
  .chat-area::-webkit-scrollbar-track { background: transparent; }
  .chat-area::-webkit-scrollbar-thumb { background: rgba(255,176,0,0.3); }

  /* Messages */
  .msg {
    display: flex;
    gap: 12px;
    animation: msgIn 0.3s ease;
  }
  @keyframes msgIn {
    from { opacity:0; transform: translateY(10px); }
    to { opacity:1; transform: translateY(0); }
  }

  .msg.user { flex-direction: row-reverse; }

  .msg-avatar {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    border: 1px solid rgba(255,176,0,0.2);
    background: #0d0d0d;
  }

  .msg-body { max-width: 75%; }
  .msg-sender {
    font-family: 'Share Tech Mono', monospace;
    font-size: 9px;
    color: #888;
    letter-spacing: 0.15em;
    margin-bottom: 4px;
  }
  .msg.user .msg-sender { text-align: left; }

  .msg-bubble {
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.7;
    white-space: pre-wrap;
  }
  .msg.ai .msg-bubble {
    background: #0d0d0d;
    border: 1px solid rgba(255,176,0,0.2);
    border-left: 2px solid rgba(255,176,0,0.5);
    border-radius: 0;
  }
  .msg.user .msg-bubble {
    background: rgba(255,176,0,0.07);
    border: 1px solid rgba(255,176,0,0.3);
    border-right: 2px solid rgba(255,176,0,0.5);
    border-radius: 0;
    text-align: left;
  }

  /* Judge message */
  .msg.judge .msg-bubble {
    background: linear-gradient(135deg, rgba(139,26,26,0.3), rgba(100,15,15,0.2));
    border: 1px solid rgba(201,168,76,0.5);
    border-radius: 8px;
    font-style: italic;
    position: relative;
  }
  .msg.judge .msg-bubble::before {
    content: '👑 ディベート王の判定';
    display: block;
    font-family: 'Share Tech Mono', monospace;
    font-size: 9px;
    color: var(--gold);
    letter-spacing: 0.2em;
    margin-bottom: 6px;
    font-style: normal;
  }

  .judge-score {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 11px;
  }
  .judge-score .js-user { color: var(--win); }
  .judge-score .js-ai { color: var(--lose); }

  /* Typing indicator */
  .typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--panel);
    border: 1px solid var(--border);
    width: fit-content;
  }
  .typing-dot {
    width: 6px; height: 6px;
    background: var(--text-dim);
    border-radius: 50%;
    animation: typingBounce 1.2s ease-in-out infinite;
  }
  .typing-dot:nth-child(2) { animation-delay: 0.2s; }
  .typing-dot:nth-child(3) { animation-delay: 0.4s; }
  @keyframes typingBounce {
    0%,60%,100% { transform: translateY(0); opacity:0.4; }
    30% { transform: translateY(-6px); opacity:1; }
  }

  /* Input area */
  .input-area {
    border-top: 1px solid rgba(255,176,0,0.15);
    padding: 16px 24px;
    background: rgba(0,0,0,0.95);
    backdrop-filter: blur(10px);
    display: flex;
    gap: 12px;
    align-items: flex-end;
    position: sticky;
    bottom: 0;
    z-index: 10;
  }

  .user-input {
    flex: 1;
    background: #0a0a0a;
    border: 1px solid rgba(255,176,0,0.25);
    color: #ffffff;
    padding: 12px 16px;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 14px;
    resize: none;
    outline: none;
    min-height: 48px;
    max-height: 160px;
    transition: border-color 0.2s;
    line-height: 1.6;
  }
  .user-input:focus { border-color: var(--amber); outline: none; box-shadow: 0 0 8px rgba(255,176,0,0.3); }
  .user-input:disabled { opacity: 0.4; }
  .user-input::placeholder { color: var(--text-dim); }

  .send-btn {
    background: #cc0000;
    border: 2px solid #ff4444;
    color: #ffffff;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 13px;
    font-weight: 700;
    padding: 12px 20px;
    cursor: pointer;
    font-family: 'Share Tech Mono', monospace;
    font-size: 12px;
    letter-spacing: 0.1em;
    transition: all 0.2s;
    height: 48px;
    white-space: nowrap;
  }
  .send-btn:hover { box-shadow: 0 0 20px rgba(139,26,26,0.4); }
  .send-btn:disabled { opacity:0.4; cursor:not-allowed; }

  /* ===== RESULT SCREEN ===== */
  #screen-result {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 40px 20px;
    text-align: center;
  }

  .result-crown { font-size: 72px; margin-bottom: 16px; animation: crownFloat 3s ease-in-out infinite; }

  .result-verdict {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: clamp(32px, 8vw, 56px);
    font-weight: 900;
    margin-bottom: 8px;
  }
  .result-verdict.win { color: var(--gold-light); }
  .result-verdict.lose { color: var(--text-dim); }

  .result-subtitle {
    font-family: 'Share Tech Mono', monospace;
    font-size: 12px;
    letter-spacing: 0.3em;
    color: var(--text-dim);
    margin-bottom: 40px;
  }

  .result-verdict-text {
    max-width: 560px;
    background: var(--panel);
    border: 1px solid var(--border);
    padding: 24px;
    font-size: 14px;
    line-height: 1.8;
    font-style: italic;
    text-align: left;
    margin-bottom: 32px;
    position: relative;
  }
  .result-verdict-text::before {
    content: '👑';
    position: absolute;
    top: -14px;
    left: 20px;
    font-size: 20px;
  }

  .result-stats {
    display: flex;
    gap: 24px;
    margin-bottom: 40px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .result-stat {
    background: var(--panel);
    border: 1px solid var(--border);
    padding: 16px 24px;
    text-align: center;
  }
  .result-stat .rs-label {
    font-family: 'Share Tech Mono', monospace;
    font-size: 9px;
    color: var(--gold);
    letter-spacing: 0.2em;
    margin-bottom: 4px;
  }
  .result-stat .rs-value {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 24px;
    font-weight: 700;
  }

  .result-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .btn-retry, .btn-next {
    padding: 14px 32px;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.15em;
    cursor: pointer;
    transition: all 0.2s;
    clip-path: polygon(6px 0, 100% 0, calc(100% - 6px) 100%, 0 100%);
  }
  .btn-retry {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
  }
  .btn-retry:hover { border-color: var(--gold); color: var(--text); }
  .btn-next {
    background: linear-gradient(135deg, var(--crimson), var(--crimson-light));
    border: 1px solid rgba(201,168,76,0.4);
    color: var(--gold-light);
  }
  .btn-next:hover { box-shadow: 0 0 30px rgba(139,26,26,0.5); }

  /* ===== KO FLASH ===== */
  .ko-flash {
    position: fixed;
    inset: 0;
    background: rgba(139,26,26,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: koFlash 4s ease forwards;
    pointer-events: none;
  }
  @keyframes koFlash {
    0% { opacity:0; }
    20% { opacity:1; }
    80% { opacity:1; }
    100% { opacity:0; }
  }
  .ko-text {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 80px;
    font-weight: 900;
    color: white;
    text-shadow: 0 0 40px rgba(255,255,255,0.5);
    animation: koScale 0.6s ease forwards;
  }
  @keyframes koScale {
    0% { transform: scale(2); opacity:0; }
    40% { transform: scale(1); opacity:1; }
    100% { transform: scale(0.95); opacity:1; }
  }

  /* Divider in chat */
  .chat-divider {
    text-align: center;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 12px;
    color: #cccccc;
    letter-spacing: 0.1em;
    padding: 8px 0;
    border-top: 1px solid rgba(255,176,0,0.15);
    border-bottom: 1px solid rgba(255,176,0,0.15);
    margin: 8px 0;
  }

  /* Responsive */
  @media (max-width: 600px) {
    .stages { flex-direction: column; align-items: center; }
    .stage-card { width: 100%; max-width: 300px; }
    .msg-body { max-width: 90%; }
    .game-header { padding: 12px 16px; }
    .chat-area { padding: 16px; }
    .input-area { padding: 12px 16px; }
  }