:root {
  --bg1: #4b3bff;
  --bg2: #7b2ff7;
  --card: #ffffff;
  --ink: #1d1d2c;
  --muted: #6b6f85;
  --line: #e4e6f0;
  --green: #36c95f;
  --green-d: #23a548;
  --blue: #2f8cff;
  --blue-d: #1a6fd6;
  --orange: #ff9a1f;
  --red: #ff4d4d;
  --yellow: #ffd21f;
  --soft: #f4f5fb;
  --radius: 16px;
  --shadow: 0 6px 0 rgba(0, 0, 0, .15), 0 12px 30px rgba(20, 0, 80, .25);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  background-color: var(--bg1);
  background-image:
    radial-gradient(rgba(255, 255, 255, .09) 2px, transparent 2.5px),
    linear-gradient(135deg, var(--bg1), var(--bg2));
  background-size: 28px 28px, 100% 100%;
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.error { color: var(--red); font-weight: 700; min-height: 1.2em; margin: 8px 0 0; text-align: center; }

.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 800;
  font-family: 'Baloo 2', 'Nunito', sans-serif; font-size: 1.15rem; color: #fff;
  background: #8a8fa8; box-shadow: 0 4px 0 rgba(0, 0, 0, .2);
  transition: transform .08s, filter .15s;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.big { font-size: 1.6rem; padding: 10px 18px; }
.btn-green { background: var(--green); }
.btn-blue { background: var(--blue); }
.btn-orange { background: var(--orange); }
.btn-small { font-size: .95rem; padding: 8px 12px; }

/* ================= GİRİŞ ================= */
#home { max-width: 1000px; margin: 0 auto; padding: 24px 16px 48px; display: flex; flex-direction: column; align-items: center; }
.logo {
  font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: clamp(3rem, 11vw, 5.5rem);
  margin: 10px 0 0; letter-spacing: 2px; line-height: 1;
  text-shadow: 0 5px 0 rgba(0, 0, 0, .25);
}
.logo span { display: inline-block; animation: bob 2.4s ease-in-out infinite; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; }
.logo span:nth-child(1) { color: #ff4d4d; animation-delay: 0s; }
.logo span:nth-child(2) { color: #ff8c1a; animation-delay: .1s; }
.logo span:nth-child(3) { color: #ffd21f; animation-delay: .2s; }
.logo span:nth-child(4) { color: #4cd137; animation-delay: .3s; }
.logo span:nth-child(5) { color: #22c1ff; animation-delay: .4s; }
.logo span:nth-child(6) { color: #ff5fd2; animation-delay: .5s; }
.logo span:nth-child(7) { color: #fff; animation-delay: .6s; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-6px) rotate(-3deg); } }
.tagline { color: #fff; font-weight: 800; font-size: 1.15rem; margin: 6px 0 22px; opacity: .95; }

.home-card { width: 100%; max-width: 440px; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.field-label { font-weight: 800; font-size: .9rem; color: var(--muted); margin-bottom: -6px; }
#nameInput, #codeInput {
  width: 100%; border: 3px solid var(--line); border-radius: 12px; padding: 12px 14px;
  font-size: 1.15rem; font-weight: 700; outline: none; transition: border-color .15s;
}
#nameInput:focus, #codeInput:focus { border-color: var(--blue); }

.avatar-editor {
  position: relative; display: grid; grid-template-columns: 1fr 150px 1fr; align-items: center;
  background: linear-gradient(180deg, #eef0ff, #e1e4ff); border-radius: 14px; padding: 12px 8px 26px;
}
.avatar-preview { width: 150px; height: 170px; justify-self: center; }
.avatar-preview svg { width: 100%; height: 100%; animation: wiggle 3s ease-in-out infinite; }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(3deg); } }
.arrows { display: flex; flex-direction: column; gap: 6px; }
.arrows.left { align-items: flex-end; }
.arrows.right { align-items: flex-start; }
.arrows button {
  width: 36px; height: 34px; border: 0; border-radius: 10px; background: #fff; font-size: 1.5rem; font-weight: 800;
  line-height: 1; box-shadow: 0 3px 0 rgba(0, 0, 0, .15); color: var(--bg1);
}
.arrows button:active { transform: translateY(2px); box-shadow: none; }
.part-labels { position: absolute; bottom: 6px; left: 0; right: 0; text-align: center; font-size: .75rem; color: var(--muted); font-weight: 700; }
.part-labels span { margin: 0 6px; }
.part-labels span::before { content: '↕ '; opacity: .5; }
.part-labels span:not(:first-child)::before { content: '· '; }
.dice { position: absolute; top: 8px; right: 8px; border: 0; background: #fff; border-radius: 10px; font-size: 1.3rem; padding: 2px 6px; box-shadow: 0 3px 0 rgba(0, 0, 0, .15); }
.join-info { text-align: center; font-weight: 700; color: var(--muted); }
.join-info b { color: var(--bg1); letter-spacing: 2px; }
.code-join { display: flex; gap: 8px; }
#codeInput { text-transform: uppercase; letter-spacing: 3px; font-size: 1rem; padding: 8px 12px; }

.info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 34px; width: 100%; }
.info { padding: 18px; }
.info h3 { margin: 0 0 6px; font-family: 'Baloo 2', sans-serif; font-size: 1.3rem; }
.info p { margin: 0; color: #3b3f55; line-height: 1.5; }

/* ================= OYUN ================= */
#game { height: 100dvh; display: flex; flex-direction: column; padding: 10px; gap: 10px; max-width: 1500px; margin: 0 auto; }
.topbar {
  display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: 14px;
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px 12px; min-height: 64px;
}
.timer {
  width: 54px; height: 54px; border-radius: 50%; border: 4px solid var(--ink); display: grid; place-items: center;
  font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 1.35rem; background: #fff; position: relative;
}
.timer.low { color: var(--red); border-color: var(--red); animation: pulse .5s ease-in-out infinite alternate; }
@keyframes pulse { to { transform: scale(1.08); } }
.round { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 1.3rem; white-space: nowrap; }
.word-area { text-align: center; min-width: 0; }
.word-label { font-size: .8rem; letter-spacing: 2px; color: var(--muted); font-weight: 800; }
.word { font-family: 'Baloo 2', monospace; font-weight: 800; font-size: 1.7rem; letter-spacing: 4px; line-height: 1.1; overflow-wrap: anywhere; }
.word .gap { display: inline-block; width: .6em; }
.word sup { font-size: .8rem; color: var(--muted); letter-spacing: 0; margin-left: 4px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { border: 0; background: var(--soft); border-radius: 10px; font-size: 1.2rem; padding: 6px 8px; }
.room-code { border: 2px dashed var(--bg1); background: #f0efff; color: var(--bg1); border-radius: 10px; padding: 6px 10px; font-weight: 800; letter-spacing: 2px; }

.game-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: 250px 1fr 310px; gap: 10px; }

/* Oyuncular */
.players { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.players-head { display: flex; justify-content: space-between; padding: 10px 14px; font-weight: 800; border-bottom: 2px solid var(--line); }
.players-head span:last-child { background: var(--soft); border-radius: 20px; padding: 0 10px; }
#playerList { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.player { display: grid; grid-template-columns: 30px 1fr 42px; align-items: center; gap: 6px; padding: 5px 10px; border-bottom: 1px solid var(--line); position: relative; }
.player:nth-child(even) { background: #fafbff; }
.player.guessed { background: #d9f8df !important; }
.player.drawing { background: #fff6d6 !important; }
.player.offline { opacity: .45; }
.player .rank { font-weight: 800; font-size: .9rem; color: var(--muted); }
.player .pinfo { min-width: 0; text-align: center; line-height: 1.15; }
.player .pname { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.player.me .pname { color: var(--blue); }
.player .pscore { font-size: .85rem; color: var(--muted); font-weight: 700; }
.player .pav { width: 42px; height: 46px; position: relative; }
.player .pav svg { width: 100%; height: 100%; }
.player .badges { position: absolute; left: 6px; bottom: 1px; font-size: .75rem; }
.player .kick { position: absolute; right: 2px; top: 2px; border: 0; background: var(--red); color: #fff; border-radius: 6px; font-size: .7rem; padding: 0 5px; opacity: 0; transition: opacity .15s; }
.player:hover .kick { opacity: 1; }
@media (hover: none) { .player .kick { opacity: .8; } }

/* Sahne */
.stage { min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.lobby { padding: 16px 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.lobby h2 { margin: 0; font-family: 'Baloo 2', sans-serif; }
.lobby h2 small { font-size: .85rem; color: var(--muted); font-family: 'Nunito', sans-serif; font-weight: 700; }
.settings-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 14px; }
.settings-grid label { display: flex; flex-direction: column; gap: 4px; font-weight: 800; font-size: .88rem; color: #3b3f55; }
select, textarea, .invite input {
  border: 2px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff; font-weight: 700; outline: none;
}
select:focus, textarea:focus { border-color: var(--blue); }
select:disabled, textarea:disabled, input:disabled { background: var(--soft); color: var(--muted); }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 700; font-size: .92rem; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--green); margin: 1px 0 0; flex-shrink: 0; }
.check small { color: var(--muted); font-weight: 600; }
.check.inline { align-items: center; }
.custom-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.custom-head h3 { margin: 0; font-family: 'Baloo 2', sans-serif; font-size: 1.25rem; }
.badge { font-family: 'Nunito', sans-serif; font-size: .8rem; background: #eef0ff; color: var(--bg1); border-radius: 20px; padding: 2px 10px; vertical-align: middle; }
textarea { min-height: 140px; flex: 1; resize: vertical; font-weight: 600; line-height: 1.5; }
.hidden-note { background: var(--soft); border-radius: 10px; padding: 20px; text-align: center; color: var(--muted); font-weight: 700; }
.estimate { margin: 0; color: var(--muted); font-weight: 700; font-size: .88rem; }
.lobby-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(140px, 220px); gap: 10px; }
.invite { display: flex; }
.invite input { flex: 1; min-width: 0; border-radius: 10px 0 0 10px; font-size: 1rem; color: var(--blue); }
.invite .btn { border-radius: 0 10px 10px 0; }

/* Tahta */
.board-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.canvas-box { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#board {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  aspect-ratio: 4 / 3; max-width: 100%; max-height: 100%; width: auto; height: 100%;
  touch-action: none; display: block; cursor: crosshair;
}
.overlay {
  position: absolute; inset: 0; margin: auto; aspect-ratio: 4 / 3; max-width: 100%; max-height: 100%; height: 100%;
  background: rgba(29, 20, 80, .82); border-radius: var(--radius); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: safe center; gap: 14px; padding: 20px; text-align: center;
  animation: fadeIn .25s ease-out; overflow-y: auto;
}
@keyframes fadeIn { from { opacity: 0; } }
.overlay h2 { margin: 0; font-family: 'Baloo 2', sans-serif; font-size: clamp(1.4rem, 3.5vw, 2.3rem); }
.overlay h2 b { color: var(--yellow); }
.overlay .sub { margin: 0; opacity: .85; font-weight: 700; }
.choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.choices button {
  border: 3px solid #fff; background: transparent; color: #fff; border-radius: 12px; padding: 10px 20px;
  font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 1.4rem;
}
.choices button:hover { background: #fff; color: var(--bg2); }
.ov-avatar { width: 90px; height: 100px; }
.ov-avatar svg { width: 100%; height: 100%; animation: wiggle 1s ease-in-out infinite; }
.delta-list { list-style: none; margin: 0; padding: 0; width: min(380px, 100%); max-height: 50%; overflow-y: auto; }
.delta-list li { display: flex; justify-content: space-between; padding: 3px 10px; font-weight: 700; }
.delta-list .plus { color: #6dff8e; }
.delta-list .zero { color: #ff9e9e; }

/* Final */
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; }
.pod { display: flex; flex-direction: column; align-items: center; width: 110px; }
.pod .pav { width: 70px; height: 80px; }
.pod .pav svg { width: 100%; height: 100%; }
.pod .pname { font-weight: 800; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod .block { width: 100%; border-radius: 10px 10px 0 0; display: grid; place-items: center; font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 1.8rem; color: var(--ink); }
.pod.p1 .block { height: 90px; background: var(--yellow); }
.pod.p2 .block { height: 64px; background: #dfe4ea; }
.pod.p3 .block { height: 46px; background: #f0a868; }
.pod.p1 { order: 2; } .pod.p2 { order: 1; } .pod.p3 { order: 3; }
.pod.p1 .pav { animation: bob 1.2s ease-in-out infinite; }
.pod .pts { font-size: .85rem; opacity: .9; }
.rank-list { list-style: none; margin: 0; padding: 0; width: min(420px, 100%); max-height: 34%; overflow-y: auto; background: rgba(255, 255, 255, .08); border-radius: 10px; }
.rank-list li { display: grid; grid-template-columns: 40px 1fr auto; padding: 4px 12px; font-weight: 700; }
.rank-list li.me { background: rgba(255, 210, 31, .25); }

/* Araç çubuğu */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; }
.current-color { width: 46px; height: 46px; border-radius: 10px; border: 3px solid #fff; box-shadow: var(--shadow); }
.palette { display: grid; grid-template-columns: repeat(13, 24px); grid-template-rows: 22px 22px; border-radius: 8px; overflow: hidden; box-shadow: var(--shadow); }
.palette button { border: 0; padding: 0; width: 24px; height: 22px; }
.palette button:hover { transform: scale(1.2); position: relative; z-index: 1; box-shadow: 0 0 0 2px #fff; }
.sizes { display: flex; gap: 4px; background: #fff; border-radius: 10px; padding: 4px; box-shadow: var(--shadow); }
.sizes button { width: 38px; height: 38px; border: 0; border-radius: 8px; background: transparent; display: grid; place-items: center; }
.sizes button.active { background: #e8e0ff; }
.sizes button i { display: block; border-radius: 50%; background: var(--ink); }
.tools { display: flex; gap: 4px; }
.tool { width: 46px; height: 46px; border: 0; border-radius: 10px; background: #fff; font-size: 1.35rem; box-shadow: var(--shadow); }
.tool.active { background: #b388ff; }
.tool:active { transform: translateY(2px); }

/* Sohbet */
.chat { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.chat-log { flex: 1; overflow-y: auto; padding: 6px 0; font-size: .95rem; }
.chat-log div { padding: 4px 12px; overflow-wrap: anywhere; }
.chat-log div:nth-child(even) { background: #f7f8fc; }
.chat-log b { font-weight: 800; }
.chat-log .system { color: var(--muted); font-weight: 700; }
.chat-log .info { color: var(--blue-d); font-weight: 800; }
.chat-log .join { color: var(--green-d); font-weight: 800; }
.chat-log .leave, .chat-log .warn { color: #e0472f; font-weight: 800; }
.chat-log .correct { color: #fff; background: var(--green) !important; font-weight: 800; }
.chat-log .reveal { color: #fff; background: var(--bg1) !important; font-weight: 800; }
.chat-log .close { color: #b26b00; background: #fff3d0 !important; font-weight: 800; }
.chat-log .guessed { color: #1d8a3a; }
.chat-log .host b { color: var(--bg2); }
.chat-log .host b::after { content: ' 👩‍🏫'; }
#chatForm { padding: 8px; border-top: 2px solid var(--line); }
#chatInput { width: 100%; border: 2px solid var(--line); border-radius: 10px; padding: 10px 12px; font-weight: 700; outline: none; }
#chatInput:focus { border-color: var(--blue); }
#chatInput:disabled { background: var(--soft); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, calc(100% + 40px)); pointer-events: none; background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 12px; font-weight: 800; transition: transform .25s; z-index: 100; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { transform: translate(-50%, 0); }

/* ================= RESPONSIVE ================= */
@media (max-width: 1150px) {
  .game-grid { grid-template-columns: 210px 1fr 260px; }
  .palette { grid-template-columns: repeat(13, 20px); }
  .palette button { width: 20px; }
}
@media (max-width: 900px) {
  #game { height: auto; min-height: 100dvh; padding: 8px; }
  .topbar { grid-template-columns: auto 1fr auto; gap: 8px; padding: 6px 8px; }
  .round { display: none; }
  .timer { width: 46px; height: 46px; font-size: 1.1rem; border-width: 3px; }
  .word { font-size: 1.3rem; letter-spacing: 3px; }
  .game-grid { grid-template-columns: 1fr 1fr; grid-template-rows: auto 300px; }
  .stage { grid-column: 1 / -1; grid-row: 1; }
  .players { grid-row: 2; }
  .chat { grid-row: 2; }
  #board { width: 100%; height: auto; }
  .overlay { height: auto; width: 100%; }
  .board-wrap.final #board { display: none; }
  .board-wrap.final .overlay { position: static; aspect-ratio: auto; max-height: none; }
  .settings-grid { grid-template-columns: repeat(2, 1fr); }
  .lobby-actions { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr; }
  .player { grid-template-columns: 22px 1fr 34px; padding: 4px 6px; }
  .player .pav { width: 34px; height: 38px; }
  .top-actions .room-code { display: none; }
}
@media (max-width: 520px) {
  .palette { grid-template-columns: repeat(13, 1fr); width: 100%; }
  .palette button { width: auto; }
  .toolbar { gap: 6px; }
  .current-color { display: none; }
  .tool { width: 40px; height: 40px; font-size: 1.15rem; }
  .sizes button { width: 32px; height: 32px; }
  .overlay h2 { font-size: 1.2rem; }
  .choices button { font-size: 1.1rem; padding: 6px 12px; }
  .pod { width: 80px; }
  .overlay { gap: 8px; padding: 12px; }
  .pod .pav { width: 46px; height: 52px; }
  .pod.p1 .block { height: 56px; } .pod.p2 .block { height: 42px; } .pod.p3 .block { height: 30px; }
  .pod .block { font-size: 1.3rem; }
  .rank-list { max-height: none; }
}
