:root {
    --ink: #172033;
    --paper: #f1f5f9;
    --paper-light: #ffffff;
    --red: #ef4444;
    --blue: #3b82f6;
    --yellow: #f59e0b;
    --green: #10b981;
    --nav-height: 60px;
}

body[data-maedn-room] {
    --game-ui-accent: #f5c542;
    --game-ui-panel: #172744f2;
    --game-ui-primary-background: #e83f4b;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
    margin: 0;
    color: var(--ink);
    background: radial-gradient(circle at 50% 28%, #49699e 0, #263c6c 43%, #101a36 100%);
    font-family: Arial, Helvetica, sans-serif;
}

button, input { font: inherit; }

.maedn-nav {
    position: fixed;
    z-index: 20;
    inset: 0 0 auto;
    min-height: calc(var(--nav-height) + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px));
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    color: #fff;
    background: #111827f2;
    box-shadow: 0 3px 18px #0f172a38;
}

.maedn-nav a { color: inherit; text-decoration: none; }
.maedn-nav > a:first-child { display: flex; align-items: center; gap: 5px; font-size: .9rem; }
.maedn-nav svg { width: 22px; fill: none; stroke: currentColor; stroke-width: 2; }
.maedn-wordmark { font-weight: 800; letter-spacing: -.035em; text-align: center; }
#maedn-room-label { justify-self: end; color: #c7d2fe; font-size: .78rem; }

.maedn-sound-toggle {
    position: fixed;
    z-index: 30;
    right: max(16px, env(safe-area-inset-right, 0px));
    bottom: max(16px, env(safe-area-inset-bottom, 0px));
    display: grid;
    width: 48px;
    height: 48px;
    padding: 0;
    place-items: center;
    border: 1px solid #ffffff80;
    border-radius: 50%;
    color: #fff;
    background: #111827e8;
    box-shadow: 0 6px 18px #0f172a66;
    cursor: pointer;
}
.maedn-sound-toggle:hover { background: #263c6c; }
.maedn-sound-toggle:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.maedn-sound-toggle svg { width: 24px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; }
.maedn-debug-dice { position: fixed; z-index: 30; left: max(16px, env(safe-area-inset-left, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px)); display: flex; align-items: center; gap: 7px; padding: 8px 10px; border-radius: 10px; color: #fff; background: #111827e8; font-size: .75rem; font-weight: 700; }
.maedn-debug-dice input { width: 56px; border: 1px solid #ffffff80; border-radius: 5px; padding: 4px; color: var(--ink); background: #fff; }
.maedn-debug-dice-clear { padding: 0 2px; border: 0; color: #fff; background: transparent; font-size: 1.25rem; line-height: 1; cursor: pointer; }

#maedn-app { min-height: 100dvh; }

.maedn-landing {
    min-height: 100dvh;
    padding: calc(var(--nav-height) + env(safe-area-inset-top, 0px) + 38px) 20px 32px;
    display: grid;
    place-items: center;
}

.maedn-panel {
    width: min(480px, 100%);
    padding: clamp(24px, 6vw, 44px);
    border: 1px solid #fff9;
    border-radius: 26px;
    background: #ffffffeb;
    box-shadow: 0 24px 70px #0f172a24;
    backdrop-filter: blur(10px);
}

.maedn-panel h1 { margin: 0 0 10px; font-size: clamp(2rem, 8vw, 3.25rem); line-height: .96; letter-spacing: -.065em; }
.maedn-panel h2 { margin: 0 0 8px; }
.maedn-panel p { color: #64748b; line-height: 1.5; }
.maedn-kicker { display: block; margin-bottom: 12px; color: var(--red); font-size: .75rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }

.maedn-form { display: grid; gap: 14px; margin-top: 24px; }
.maedn-form label { display: grid; gap: 7px; font-size: .82rem; font-weight: 700; }
.maedn-form input {
    width: 100%;
    padding: 13px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: #fff;
}

.maedn-primary, .maedn-secondary, .maedn-link-button {
    min-height: 46px;
    padding: 11px 18px;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 800;
}
.maedn-primary { color: #fff; background: #e83f4b; box-shadow: 0 8px 22px #e83f4b35; }
.maedn-secondary { color: var(--ink); background: #e2e8f0; }
.maedn-link-button { min-height: auto; padding: 6px; color: #64748b; background: transparent; }
button:disabled { cursor: default; opacity: .48; }

.maedn-players, .maedn-recent-list { display: grid; gap: 9px; margin: 20px 0; padding: 0; list-style: none; }
.maedn-players li, .maedn-recent-session { padding: 12px 14px; border-radius: 12px; background: #fff9; }
.maedn-lobby { display: grid; }
.maedn-lobby-players { margin-bottom: 12px; }
.maedn-lobby-player { display: flex; align-items: center; gap: 9px; }
.maedn-lobby-player strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.maedn-lobby-player small { margin-left: auto; color: #64748b; }
.maedn-lobby-player-pawn,
.maedn-color-option > span {
    position: relative;
    display: block;
    border: 1px solid color-mix(in srgb, var(--pawn-color) 76%, #000);
    border-radius: 50%;
    background: var(--pawn-color);
}
.maedn-lobby-player-pawn {
    --pawn-color: var(--lobby-player-color);
    width: 22px; height: 22px;
    flex: 0 0 22px;
}
.maedn-lobby-player-pawn::after,
.maedn-color-option > span::after {
    content: '';
    position: absolute;
    left: 50%;
    border: 1px solid color-mix(in srgb, var(--pawn-color) 76%, #000);
    border-radius: 50%;
    background: var(--pawn-color);
    transform: translateX(-50%);
}
.maedn-lobby-player-pawn::after { top: -6px; width: 13px; height: 13px; }
.maedn-color-picker { display: grid; gap: 10px; padding: 14px 0; }
.maedn-color-options { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 20px; }
.maedn-color-option {
    display: grid;
    place-items: center;
    width: 50px; height: 50px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
}
.maedn-color-option > span {
    --pawn-color: var(--choice-color);
    width: 32px; height: 32px;
}
.maedn-color-option > span::after { top: -18px; width: 19px; height: 19px; }
.maedn-color-option.selected { border-color: var(--choice-color); }
.maedn-color-option:focus-visible { outline: 3px solid var(--choice-color); outline-offset: 2px; }
.maedn-lobby-actions { display: grid; gap: 9px; }
.maedn-rule-option { display: flex !important; grid-template-columns: none !important; align-items: flex-start; gap: 10px; padding: 13px 14px; border: 1px solid #cbd5e1; border-radius: 12px; background: #ffffffaa; cursor: pointer; }
.maedn-rule-option input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--red); }
.maedn-rule-option span { display: grid; gap: 3px; }
.maedn-rule-option small, .maedn-rule-note { color: #64748b; font-size: .78rem; line-height: 1.4; }
.maedn-bot-controls { display: flex; align-items: end; gap: 8px; }
.maedn-bot-controls label { display: grid; gap: 6px; flex: 1; min-width: 0; font-size: .82rem; color: #475569; }
.maedn-bot-controls select { width: 100%; min-width: 0; min-height: 44px; border: 1px solid #cbd5e1; border-radius: 3px; padding: 0 11px; background: #fff; color: var(--ink); }
.maedn-share { display: flex; gap: 8px; }
.maedn-share input { flex: 1; min-width: 0; min-height: 44px; padding: 0 11px; border-radius: 3px; }
.maedn-icon-button { display: grid; width: 44px; min-width: 44px; height: 44px; min-height: 44px; padding: 10px; place-items: center; border-radius: 3px; }
.maedn-icon-button svg { display: block; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.maedn-recent { margin-top: 28px; padding-top: 20px; }
.maedn-recent h2 { font-size: 1rem; }
.maedn-recent-session { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.maedn-recent-session small { display: block; color: #64748b; margin-top: 4px; }
.maedn-resume-buttons { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.maedn-resume-buttons button { border: 0; border-radius: 999px; padding: 5px 9px; cursor: pointer; color: #fff; background: #0f766e; }
.maedn-delete { border: 0; background: transparent; cursor: pointer; font-size: 1.2rem; }

.maedn-game {
    min-height: 100dvh;
    padding: calc(var(--nav-height) + env(safe-area-inset-top, 0px) + 14px) max(12px, env(safe-area-inset-right, 0px)) max(18px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
    display: grid;
    place-items: center;
}

.maedn-play-area { width: min(100%, calc(100dvh - var(--nav-height) - 132px)); display: grid; gap: 10px; }
.maedn-board-shell { position: relative; width: 100%; margin: auto; aspect-ratio: 1; }
.maedn-board-layer { position: absolute; inset: 0; }
.maedn-board {
    position: relative;
    overflow-anchor: none;
    width: 100%; height: 100%;
    display: grid;
    grid-template-columns: repeat(11, 1fr);
    grid-template-rows: repeat(11, 1fr);
    padding: 2.2%;
    border: 6px solid #b61212;
    border-radius: 4px;
    background: #fffeba;
    box-shadow: 0 12px 25px rgba(0, 0, 0, 0.33), inset 0 0 20px rgba(0, 0, 0, 0.22);
}
.maedn-board::before {
    content: '';
    position: absolute;
    z-index: 6;
    inset: 4px;
    border: 3px solid #252121;
    border-radius: 2px;
    pointer-events: none;
}
.maedn-start-arrow {
    position: relative;
    z-index: 2;
    width: 158.4%; height: 32.4%;
    place-self: center;
    background: #252121;
    transform: rotate(var(--arrow-rotation));
    pointer-events: none;
    -webkit-mask: url('/public/img/maedn/arrow.svg') center / contain no-repeat;
    mask: url('/public/img/maedn/arrow.svg') center / contain no-repeat;
}
.maedn-board-word {
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    user-select: none;
}
.maedn-board-word img { display: block; height: auto; }
.maedn-board-word-mensch {
    grid-row: 3 / span 2;
    grid-column: 2 / span 3;
}
.maedn-board-word-mensch img { width: 90%; }
.maedn-board-word-aergere {
    grid-row: 3 / span 2;
    grid-column: 8 / span 3;
}
.maedn-board-word-aergere img { width: 56.9%; }
.maedn-board-word-dich {
    grid-row: 8 / span 2;
    grid-column: 2 / span 3;
}
.maedn-board-word-dich img { width: 43.5%; }
.maedn-board-word-nicht {
    grid-row: 8 / span 2;
    grid-column: 8 / span 3;
}
.maedn-board-word-nicht img { width: 46.7%; }

.maedn-field, .maedn-yard-field {
    position: relative;
    width: 68%; height: 68%;
    place-self: center;
    border: max(1px, .16vw) solid #252121;
    border-radius: 50%;
    background: #fffdf5;
    box-shadow: inset 0 2px 4px #544b3e26;
}
.maedn-yard-entry {
    position: relative;
    width: 68%; height: 68%;
    place-self: center;
    visibility: hidden;
    pointer-events: none;
    transform: translate(var(--entry-x), var(--entry-y));
}
.maedn-field.home-0, .maedn-field.start-0, .maedn-yard-field.seat-0 { background: color-mix(in srgb, var(--red) 72%, white); }
.maedn-field.home-1, .maedn-field.start-1, .maedn-yard-field.seat-1 { background: color-mix(in srgb, var(--blue) 72%, white); }
.maedn-field.home-2, .maedn-field.start-2, .maedn-yard-field.seat-2 { background: color-mix(in srgb, var(--yellow) 75%, white); }
.maedn-field.home-3, .maedn-field.start-3, .maedn-yard-field.seat-3 { background: color-mix(in srgb, var(--green) 72%, white); }
.maedn-pawn {
    position: absolute;
    z-index: 4;
    inset: 0;
    width: 100%; height: 100%;
    padding: 0;
    border: 0;
    border-radius: 50%;
    color: var(--ink);
    background: transparent;
    cursor: default;
    box-shadow: none;
}
.maedn-pawn::before,
.maedn-pawn::after {
    content: '';
    position: absolute;
    left: 50%;
    display: block;
    border: 1px solid color-mix(in srgb, currentColor 76%, #000);
    border-radius: 50%;
    background: currentColor;
    transform: translateX(-50%);
}
.maedn-pawn::before { bottom: 3%; width: 90%; height: 90%; }
.maedn-pawn::after { top: -30%; width: 61%; height: 61%; }
.maedn-pawn.seat-0 { color: var(--red); }
.maedn-pawn.seat-1 { color: var(--blue); }
.maedn-pawn.seat-2 { color: var(--yellow); }
.maedn-pawn.seat-3 { color: var(--green); }
.maedn-pawn:disabled { opacity: 1; }
.maedn-pawn.playable { cursor: pointer; }

.maedn-player-strip { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 20px; min-height: 32px; }
.maedn-player {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: white;
    min-width: 0;
    white-space: nowrap;
}
.maedn-player-pawn {
    position: relative;
    width: 18px; height: 18px;
    flex: 0 0 18px;
    border: 1px solid color-mix(in srgb, var(--player-color) 76%, #000);
    border-radius: 50%;
    background: var(--player-color);
}
.maedn-player-pawn::after {
    content: '';
    position: absolute;
    left: 50%; top: -5px;
    width: 11px; height: 11px;
    border: 1px solid color-mix(in srgb, var(--player-color) 76%, #000);
    border-radius: 50%;
    background: var(--player-color);
    transform: translateX(-50%);
}
.maedn-player strong { text-underline-offset: 4px; text-decoration-thickness: 3px; }
.maedn-player.current strong { text-decoration-line: underline; text-decoration-color: var(--player-color); }
.maedn-you-label { color: #bcbfc9; font-size: .82rem; }
.maedn-player-name { padding: 0; border: 0; background: transparent; color: inherit; font: inherit; font-weight: 700; cursor: pointer; text-underline-offset: 4px; text-decoration-thickness: 3px; }
.maedn-player.current .maedn-player-name { text-decoration-line: underline; text-decoration-color: var(--player-color); }
.maedn-reaction-bubble { position: absolute; z-index: 14; left: 50%; top: calc(100% + 7px); min-width: 2.2rem; max-width: min(240px, 80vw); padding: .3rem .5rem; border: 0; border-radius: .8rem; color: #202020; background: #fff; box-shadow: 0 .25rem .7rem #0007; font-size: 1.45rem; line-height: 1; transform: translateX(-50%); animation: maedn-reaction-pop .2s ease-out; }
.maedn-reaction-bubble::after { content: ''; position: absolute; left: 50%; top: -6px; border: 7px solid transparent; border-bottom-color: #fff; border-top: 0; transform: translateX(-50%); }
.maedn-player.start-roll-winner .maedn-reaction-bubble { color: #fff; background: var(--player-color); }
.maedn-player.start-roll-winner .maedn-reaction-bubble::after { border-bottom-color: var(--player-color); }
.maedn-reaction-bubble.message { font-size: .88rem; line-height: 1.25; overflow-wrap: anywhere; }
.maedn-reaction-picker, .maedn-reaction-composer { position: absolute; z-index: 15; left: 50%; top: calc(100% + 7px); display: flex; gap: 4px; padding: 5px; border-radius: 10px; background: #102319f2; box-shadow: 0 .3rem 1rem #0008; transform: translateX(-50%); }
.maedn-reaction-picker > div { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.maedn-reaction-picker button { padding: 3px; border: 0; border-radius: 5px; background: transparent; font-size: 1.1rem; line-height: 1; cursor: pointer; }
.maedn-reaction-picker button:hover, .maedn-reaction-picker button:focus-visible { background: #31543b; outline: none; }
.maedn-reaction-picker .keyboard { align-self: center; }
.maedn-reaction-composer input { width: min(210px, 52vw); padding: 6px; border: 1px solid #86a98e; border-radius: 5px; color: #fff; background: #1d3c2b; }
.maedn-reaction-composer button { padding: 6px 9px; border: 0; border-radius: 5px; color: #102319; background: #e4efd4; cursor: pointer; }
@keyframes maedn-reaction-pop { from { opacity: 0; transform: translateX(-50%) scale(.65) translateY(6px); } to { opacity: 1; transform: translateX(-50%); } }

.maedn-dice-panel {
    position: absolute;
    z-index: 8;
    inset: 0;
    overflow: hidden;
    border: 0;
    border-radius: 4%;
    background: transparent;
    box-shadow: none;
    pointer-events: none;
    touch-action: auto;
}
#maedn-dice-box { position: absolute; inset: 0; }
#maedn-dice-box canvas { width: 100%; height: 100%; display: block; }
.maedn-dice-choice { position: absolute; z-index: 2; inset: 0; pointer-events: none; }
.maedn-die-choice { position: absolute; width: 68px; height: 68px; padding: 0; border: 3px solid transparent; border-radius: 50%; color: transparent; background: transparent; box-shadow: none; font-size: 0; transform: translate(-50%, -50%); cursor: pointer; pointer-events: auto; }
.maedn-die-choice.selected { border-color: #facc15; box-shadow: 0 0 0 2px #facc15aa; }
.maedn-die-choice.used { opacity: .28; cursor: default; }
.maedn-dice-hint { min-height: 1em; margin: 10px 0 0; color: white; text-align: center; font-size: .82rem; pointer-events: none; }
.maedn-dice-panel.ready { cursor: grab; pointer-events: auto; touch-action: none; }
.maedn-dice-panel.ready:active { cursor: grabbing; }

.maedn-result { padding: 18px; border-radius: 18px; text-align: center; background: #fff9; }
.maedn-result h2 { margin: 0 0 6px; }

#maedn-status {
    position: fixed; z-index: 50; left: 50%; bottom: max(20px, env(safe-area-inset-bottom, 0px));
    max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 999px;
    color: #fff; background: #111827; box-shadow: 0 8px 30px #0f172a4d;
    transform: translate(-50%, 30px); opacity: 0; pointer-events: none; transition: .2s ease;
}
#maedn-status.visible { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 760px) {
    :root { --nav-height: 52px; }
    .maedn-wordmark { font-size: .82rem; }
    .maedn-nav > a:first-child span { display: none; }
    .maedn-play-area { width: min(100%, 62dvh); }
    .maedn-player-strip { gap: 7px 13px; }
    .maedn-player { font-size: .76rem; }
    .maedn-player strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .maedn-player-pawn { width: 15px; height: 15px; flex-basis: 15px; }
    .maedn-player-pawn::after { top: -4px; width: 9px; height: 9px; }
}

@media (max-height: 680px) and (orientation: landscape) {
    .maedn-play-area { width: min(100%, calc(100dvh - var(--nav-height) - 102px)); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
