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

body {
    font-family: "Courier New", Courier, monospace;
    background-color: #1a0e08;
    color: #F7E7CE;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

canvas { display: block; }

/* ===== Screen Overlays ===== */
.screen-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    background: rgba(26, 14, 8, 0.92);
    transition: opacity 0.4s ease;
}
.screen-overlay.hidden { opacity: 0; pointer-events: none; }

/* Title screen rotating backgrounds */
#title-bg { position: absolute; inset: 0; z-index: -1; overflow: hidden; }
.title-bg-slide {
    position: absolute; inset: 0;
    opacity: 0; transition: opacity 1.2s ease;
    display: flex; align-items: center; justify-content: center;
}
.title-bg-slide.active { opacity: 1; }

/* Variant A: Fight Poster — TM2 portrait on left */
.title-bg-a {
    background: linear-gradient(90deg, rgba(26,14,8,0.3) 0%, rgba(26,14,8,0.95) 60%);
}
.title-bg-a img {
    position: absolute; left: -5%; top: 0; height: 100%;
    object-fit: cover; object-position: top;
    mask-image: linear-gradient(90deg, rgba(0,0,0,1) 30%, rgba(0,0,0,0) 80%);
    -webkit-mask-image: linear-gradient(90deg, rgba(0,0,0,1) 30%, rgba(0,0,0,0) 80%);
}

/* Peach of Man egg — background for the Choose Your Arena screen. Two Magritte-style
   peach paintings toggle on the left side when the egg is unlocked or active. */
#mode-peach-bg {
    position: absolute; inset: 0; z-index: 0;
    overflow: hidden; pointer-events: none;
}
.peach-bg-slide {
    position: absolute; inset: 0;
    opacity: 0; transition: opacity 1.2s ease;
    background: linear-gradient(90deg, rgba(26,14,8,0.3) 0%, rgba(26,14,8,0.95) 60%);
}
.peach-bg-slide.active { opacity: 1; }
.peach-bg-slide img {
    position: absolute; left: -5%; top: 0; height: 100%;
    object-fit: cover; object-position: top;
    mask-image: linear-gradient(90deg, rgba(0,0,0,1) 30%, rgba(0,0,0,0) 80%);
    -webkit-mask-image: linear-gradient(90deg, rgba(0,0,0,1) 30%, rgba(0,0,0,0) 80%);
}

/* Variant B: Dual portrait — TM1 left vs TM2 right */
.title-bg-c { overflow: hidden; }
.title-bg-c img {
    position: absolute; top: 0; height: 100%;
    object-fit: cover; object-position: top; width: 45%;
}
.title-bg-c img:first-child {
    left: -5%;
    mask-image: linear-gradient(90deg, rgba(0,0,0,0.8) 20%, rgba(0,0,0,0) 70%);
    -webkit-mask-image: linear-gradient(90deg, rgba(0,0,0,0.8) 20%, rgba(0,0,0,0) 70%);
}
.title-bg-c img:last-child {
    right: -5%;
    mask-image: linear-gradient(270deg, rgba(0,0,0,0.8) 20%, rgba(0,0,0,0) 70%);
    -webkit-mask-image: linear-gradient(270deg, rgba(0,0,0,0.8) 20%, rgba(0,0,0,0) 70%);
}

.screen-box {
    text-align: center;
    max-width: 700px;
    padding: 2.5rem 2rem;
    max-height: 90vh;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.screen-box::-webkit-scrollbar { display: none; }
/* Screens with content that routinely exceeds 90vh get a visible scrollbar so
   users know they can scroll. */
#bossselect-screen .screen-box,
#controls-screen .screen-box { scrollbar-width: thin; scrollbar-color: #555 transparent; }
#bossselect-screen .screen-box { max-width: 820px; }
#bossselect-screen .screen-box::-webkit-scrollbar,
#controls-screen .screen-box::-webkit-scrollbar { display: block; width: 6px; }
#bossselect-screen .screen-box::-webkit-scrollbar-thumb,
#controls-screen .screen-box::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }
#bossselect-screen .screen-box::-webkit-scrollbar-track,
#controls-screen .screen-box::-webkit-scrollbar-track { background: transparent; }

.screen-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 2.8rem;
    font-weight: 900;
    color: #F7E7CE;
    margin-bottom: 0.5rem;
    line-height: 1.2;
}
.title-wrap {
    position: relative;
    display: inline-block;
    padding-top: 2.2rem;
}
.title-signature {
    font-family: 'Pinyon Script', 'Snell Roundhand', 'Apple Chancery', cursive;
    font-size: 3.2rem;
    color: #F7E7CE;
    position: absolute;
    top: -0.4rem;
    left: -0.8rem;
    white-space: nowrap;
    text-shadow: 0 2px 8px rgba(0,0,0,0.6), 0 0 2px rgba(247,231,206,0.3);
    pointer-events: none;
    letter-spacing: 0.02em;
}

.screen-subtitle {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.1rem;
    color: #d4a574;
    margin-bottom: 1.5rem;
    font-style: italic;
}

.screen-instructions {
    color: #F7E7CE;
    font-size: 0.85rem;
    line-height: 1.8;
    margin-bottom: 2rem;
    opacity: 0.75;
}

.screen-score {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 4rem;
    font-weight: 900;
    color: #00ff88;
    margin: 0.5rem 0;
    text-shadow: 0 0 30px rgba(0, 255, 136, 0.4);
}

.screen-btn {
    display: inline-block;
    padding: 14px 40px;
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.15rem;
    font-weight: 700;
    background: #F7E7CE;
    color: #2c1810;
    border: 3px solid #F7E7CE;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.5px;
}
.screen-btn:hover { background: transparent; color: #F7E7CE; }
.screen-btn + .screen-btn { margin-left: 12px; }
.continue-btn {
    display: inline-block;
    padding: 14px 40px;
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.15rem;
    font-weight: 700;
    background: transparent;
    color: #FFD700;
    border: 2px solid #FFD700;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.5px;
    width: 220px;
    box-sizing: border-box;
}
.continue-btn:hover { background: #FFD700; color: #2c1810; }
.continue-info { font-size: 0.75rem; color: #D4A574; font-style: italic; }

/* Mode & Difficulty cards */
.card-row {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: 1.4rem;
    flex-wrap: wrap;
}

.mode-card {
    background: rgba(212, 165, 116, 0.1);
    border: 2px solid rgba(212, 165, 116, 0.3);
    border-radius: 14px;
    padding: 18px 16px 14px;
    text-align: center;
    width: 150px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: border-color 0.2s, background 0.2s;
    cursor: pointer;
}
.mode-card:hover { border-color: #d4a574; background: rgba(212,165,116,0.2); }
.mode-card.locked { opacity: 0.4; cursor: not-allowed; }
.mode-card.locked:hover { border-color: rgba(212,165,116,0.3); background: rgba(212,165,116,0.1); }

.mode-card-icon { font-size: 2rem; }
.mode-card-title {
    font-family: 'Playfair Display', serif;
    font-size: 1rem;
    font-weight: 700;
    color: #F7E7CE;
}
.mode-card-desc {
    font-family: 'Courier New', monospace;
    font-size: 0.65rem;
    color: rgba(247,231,206,0.6);
    line-height: 1.5;
    flex: 1;
}

.diff-card {
    background: rgba(212, 165, 116, 0.1);
    border: 2px solid rgba(212, 165, 116, 0.3);
    border-radius: 14px;
    padding: 18px 20px 16px;
    text-align: center;
    width: 160px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}
.diff-card:hover { border-color: #d4a574; background: rgba(212,165,116,0.2); }
.diff-card-title {
    font-family: 'Playfair Display', serif;
    font-size: 1.15rem;
    font-weight: 700;
    color: #F7E7CE;
    margin-bottom: 4px;
}
.diff-card-desc {
    font-family: 'Courier New', monospace;
    font-size: 0.7rem;
    color: rgba(247,231,206,0.6);
    line-height: 1.5;
}

/* Leaderboard */
.leaderboard { margin-top: 1.5rem; opacity: 0; transition: opacity 0.6s ease; }
.leaderboard.visible { opacity: 1; }
.leaderboard-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.3rem; font-weight: 700; color: #d4a574; margin-bottom: 0.8rem;
}
.leaderboard table { width: 100%; border-collapse: collapse; font-family: "Courier New", monospace; font-size: 0.9rem; }
.leaderboard th { color: #d4a574; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; padding: 4px 8px 8px; border-bottom: 1px solid rgba(212,165,116,0.3); }
.leaderboard td { color: #F7E7CE; padding: 6px 8px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.leaderboard tr.rank-1 td { color: #ffd700; }
.leaderboard tr.rank-2 td { color: #c0c0c0; }
.leaderboard tr.rank-3 td { color: #cd7f32; }
.leaderboard tr.rank-you td { color: #00ff88; font-weight: bold; }
.leaderboard .rank-num { text-align: center; width: 30px; }
.leaderboard .rank-score { text-align: right; width: 50px; }

.lb-name-form { margin-top: 1rem; display: flex; gap: 0.5rem; justify-content: center; align-items: center; }
.lb-name-input { padding: 8px 12px; font-family: "Courier New", monospace; font-size: 1rem; border: 2px solid #d4a574; background: rgba(255,255,255,0.1); color: #F7E7CE; outline: none; width: 160px; }
.lb-name-input::placeholder { color: rgba(247,231,206,0.4); }
.lb-name-input:focus { border-color: #00ff88; box-shadow: 0 0 8px rgba(0,255,136,0.2); }
.lb-submit-btn { padding: 8px 18px; font-family: 'Playfair Display', serif; font-size: 0.9rem; font-weight: 700; background: #d4a574; color: #2c1810; border: 2px solid #d4a574; cursor: pointer; transition: all 0.2s; }
.lb-submit-btn:hover { background: #00ff88; border-color: #00ff88; }
.lb-submit-btn:disabled { opacity: 0.5; cursor: default; }

/* ===== Name Entry Screen ===== */
.name-form { margin: 1.5rem 0 1rem 0; display: flex; flex-direction: column; gap: 0.8rem; align-items: center; }
.name-input {
    padding: 12px 16px;
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.2rem;
    border: 2px solid #d4a574;
    background: rgba(255,255,255,0.08);
    color: #F7E7CE;
    outline: none;
    width: 280px;
    text-align: center;
    letter-spacing: 0.02em;
}
.name-input::placeholder { color: rgba(247,231,206,0.35); font-style: italic; }
.name-input:focus { border-color: #00ff88; box-shadow: 0 0 12px rgba(0,255,136,0.25); }
.name-error {
    color: #ff4444;
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 0.85rem;
    font-style: italic;
    min-height: 1.2em;
}
#title-names { font-size: 0.85rem; color: #d4a574; margin-top: 0.4rem; margin-bottom: 0.3rem; font-family: 'Playfair Display', Georgia, serif; }
#title-names .edit-pencil { cursor: pointer; color: #d4a574; opacity: 0.6; margin-left: 0.4rem; font-size: 0.9em; transition: opacity 0.2s; }
#title-names .edit-pencil:hover { opacity: 1; color: #F7E7CE; }

/* ===== The Almanack of Renown ===== */
.almanack-box { max-width: 960px !important; padding: 1.5rem 1rem !important; }
.almanack-parchment {
    background: linear-gradient(135deg, #f4e3c0 0%, #e8d2a0 50%, #f4e3c0 100%);
    border: 3px double #8b6f3a;
    box-shadow: 0 0 30px rgba(0,0,0,0.5), inset 0 0 40px rgba(139,111,58,0.15);
    padding: 2rem 1.5rem 1.5rem 1.5rem;
    color: #3a2816;
    position: relative;
}
.almanack-parchment::before,
.almanack-parchment::after {
    content: '';
    position: absolute;
    left: 8px; right: 8px;
    height: 2px;
    background: #8b6f3a;
    opacity: 0.35;
}
.almanack-parchment::before { top: 4px; }
.almanack-parchment::after  { bottom: 4px; }
.almanack-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 2.1rem;
    font-weight: 900;
    color: #3a2816;
    text-align: center;
    margin: 0 0 0.2rem 0;
    letter-spacing: 0.02em;
    text-shadow: 0 1px 0 rgba(255,255,255,0.4);
}
.almanack-subtitle {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 0.95rem;
    color: #6b4f2a;
    text-align: center;
    font-style: italic;
    margin: 0 0 1.2rem 0;
}
.almanack-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Playfair Display', Georgia, serif;
}
.almanack-table thead th {
    font-size: 0.95rem;
    font-weight: 700;
    color: #3a2816;
    border-bottom: 2px double #8b6f3a;
    padding: 0.6rem 0.5rem;
    text-align: center;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
.almanack-table thead th.almanack-record-col { text-align: left; width: 34%; }
.almanack-table tbody td {
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid rgba(139,111,58,0.35);
    font-size: 0.9rem;
    vertical-align: middle;
}
.almanack-table tbody tr:last-child td { border-bottom: none; }
.almanack-record-name {
    font-weight: 700;
    font-style: italic;
    color: #3a2816;
    padding-left: 0.3rem !important;
}
.almanack-cell { text-align: center; }
.almanack-holder {
    font-family: 'Pinyon Script', 'Snell Roundhand', 'Apple Chancery', cursive;
    font-size: 1.15rem;
    color: #3a2816;
    line-height: 1.1;
    margin-bottom: 0.15rem;
}
.almanack-value {
    font-family: 'Courier New', monospace;
    font-size: 0.82rem;
    color: #6b4f2a;
    letter-spacing: 0.03em;
}
.almanack-empty {
    font-style: italic;
    color: #a08560;
    font-size: 0.78rem;
}

/* ===== The Chronicle of Champions ===== */
.chronicle-box { max-width: 640px !important; }
.chronicle-frame {
    background: rgba(26,14,8,0.5);
    border: 2px solid #d4a574;
    padding: 1.5rem 1.2rem 1rem 1.2rem;
    box-shadow: 0 0 20px rgba(0,0,0,0.4);
}
.chronicle-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.9rem;
    font-weight: 900;
    color: #F7E7CE;
    text-align: center;
    margin: 0 0 0.2rem 0;
}
.chronicle-subtitle {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 0.9rem;
    color: #d4a574;
    text-align: center;
    font-style: italic;
    margin: 0 0 1rem 0;
}
.chronicle-tabs {
    display: flex;
    justify-content: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-bottom: 0.6rem;
}
.chronicle-diff-tabs { margin-bottom: 1rem; }
.chronicle-tab {
    padding: 6px 14px;
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 0.85rem;
    font-weight: 700;
    background: transparent;
    color: #d4a574;
    border: 1px solid #d4a574;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.02em;
}
.chronicle-tab:hover { background: rgba(212,165,116,0.15); color: #F7E7CE; }
.chronicle-tab.active { background: #d4a574; color: #2c1810; }
.chronicle-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Playfair Display', Georgia, serif;
    color: #F7E7CE;
}
.chronicle-table thead th {
    font-size: 0.8rem;
    color: #d4a574;
    border-bottom: 1px solid #d4a574;
    padding: 0.4rem 0.5rem;
    text-align: left;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-weight: 700;
}
.chronicle-table .chron-rank { width: 12%; text-align: center; }
.chronicle-table .chron-score { width: 32%; text-align: right; font-family: 'Courier New', monospace; }
.chronicle-table tbody td {
    padding: 0.5rem 0.5rem;
    border-bottom: 1px solid rgba(212,165,116,0.2);
    font-size: 0.9rem;
}
.chronicle-table tbody tr.rank-1 td { color: #FFD700; font-weight: 700; }
.chronicle-table tbody tr.rank-2 td { color: #C0C0C0; font-weight: 700; }
.chronicle-table tbody tr.rank-3 td { color: #CD7F32; font-weight: 700; }
.chronicle-table tbody tr.rank-you td { background: rgba(0,255,136,0.1); }
.lb-message { font-size: 0.85rem; color: #d4a574; font-style: italic; margin-top: 0.5rem; }

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 24px;
    margin: 1rem auto;
    max-width: 320px;
    text-align: left;
}
.stat-label { font-size: 0.75rem; color: #d4a574; text-transform: uppercase; letter-spacing: 1px; }
.stat-value { font-family: 'Playfair Display', serif; font-size: 1.1rem; color: #F7E7CE; font-weight: 700; }

/* Controls legend */
.controls-grid {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 4px 12px;
    text-align: left;
    margin: 1rem auto;
    max-width: 460px;
    align-items: center;
}
.ctrl-header { font-size: 0.75rem; font-weight: 700; text-align: center; padding-bottom: 4px; border-bottom: 1px solid rgba(212,165,116,0.3); margin-bottom: 2px; }
.ctrl-key { font-family: 'Courier New', monospace; color: #00ff88; font-size: 0.85rem; text-align: center; }
.ctrl-key.p2-key { color: #DAA520; }
.ctrl-key.rebindable { cursor: pointer; padding: 2px 8px; border: 1px solid rgba(0,255,136,0.2); border-radius: 4px; transition: all 0.15s; }
.ctrl-key.rebindable:hover { border-color: #00ff88; background: rgba(0,255,136,0.1); }
.ctrl-key.rebindable.listening { color: #ffd700; border-color: #ffd700; background: rgba(255,215,0,0.15); animation: pulse-bind 0.8s ease infinite; }
@keyframes pulse-bind { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }
.menu-highlight { outline: 2px solid #d4a574 !important; outline-offset: 4px; }
#gamepad-cursor {
    position: fixed; z-index: 99999; pointer-events: none;
    width: 20px; height: 20px; display: none;
    border-radius: 50%; border: 2px solid #d4a574;
    background: rgba(212,165,116,0.3);
    transform: translate(-50%, -50%);
}
.ctrl-action { font-size: 0.85rem; color: rgba(247,231,206,0.8); }

/* Back link */
.back-link {
    display: inline-block;
    margin-top: 1.2rem;
    font-family: 'Playfair Display', serif;
    font-size: 0.9rem;
    color: #d4a574;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
}
.back-link:hover { opacity: 1; }

/* Touch controls */
.touch-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 160px;
    pointer-events: none;
    z-index: 5;
    display: none;
}
.touch-controls.active { display: block; }
.touch-btn {
    position: absolute;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(247,231,206,0.15);
    border: 2px solid rgba(247,231,206,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Courier New', monospace;
    font-size: 0.7rem;
    color: rgba(247,231,206,0.6);
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
}
.touch-btn:active { background: rgba(247,231,206,0.35); }
.touch-dpad { bottom: 50px; left: 20px; }
.touch-dpad-up { left: 48px; bottom: 108px; }
.touch-dpad-down { left: 48px; bottom: 0; }
.touch-dpad-left { left: 0; bottom: 54px; }
.touch-dpad-right { left: 96px; bottom: 54px; }
.touch-action { bottom: 50px; right: 20px; }
.touch-j { right: 128px; bottom: 70px; }
.touch-k { right: 60px; bottom: 108px; }
.touch-l { right: 60px; bottom: 32px; }
.touch-block { right: 128px; bottom: 0px; }
#homeBtn {
  position: fixed;
  top: 10px;
  left: 12px;
  z-index: 20;
  background: rgba(20, 10, 6, 0.8);
  color: #d4a574;
  border: 1.5px solid #6b4c3b;
  border-radius: 4px;
  padding: 5px 12px;
  font-size: 12px;
  font-family: 'Playfair Display', serif;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
  display: none;
}
#homeBtn:hover { background: #d4a574; color: #1a0e08; border-color: #d4a574; }