:root {
  --ink: #f6ecd2;
  --ink-dim: #c9b98f;
  --wood: #2a1a0e;
  --wood2: #3b2614;
  --gold: #f2c14e;
  --gold2: #d99a1e;
  --sea: #0a2a3d;
  --panel: rgba(18, 12, 6, 0.86);
  --line: rgba(242, 193, 78, 0.28);
  --red: #e8483f;
  --green: #5ccf7a;
  --blue: #59b6ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #061b29; color: var(--ink); font-family: 'Nunito', system-ui, sans-serif; user-select: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 5; }
.card {
  background: linear-gradient(180deg, rgba(43, 28, 14, 0.94), rgba(24, 15, 7, 0.94));
  border: 1px solid var(--line); border-radius: 16px; padding: 20px 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,230,170,.08);
  backdrop-filter: blur(4px);
}
.lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-dim); margin: 10px 0 6px; font-weight: 800; }
.hint { color: var(--ink-dim); font-size: 13px; margin: 8px 0; min-height: 1em; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.row > * { flex: 1; }
input {
  width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0,0,0,.35);
  color: var(--ink); font: 700 16px 'Nunito', sans-serif; outline: none;
}
input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(242,193,78,.18); }
#codeInput { text-transform: uppercase; text-align: center; letter-spacing: .3em; max-width: 110px; }
.btn {
  padding: 11px 16px; border-radius: 10px; border: 1px solid var(--line); cursor: pointer;
  background: linear-gradient(180deg, #4a3119, #2e1d0d); color: var(--ink); font: 800 15px 'Nunito', sans-serif;
  transition: transform .08s, filter .15s, box-shadow .15s; box-shadow: 0 3px 0 rgba(0,0,0,.4);
}
.btn:hover:not(:disabled) { filter: brightness(1.2); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 1px 0 rgba(0,0,0,.4); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.gold { background: linear-gradient(180deg, #f7cf63, #c98712); color: #2b1803; border-color: #ffe08a; text-shadow: 0 1px 0 rgba(255,255,255,.35); }
.btn.big { width: 100%; padding: 14px; font-size: 18px; margin-top: 16px; }
kbd { display: inline-block; min-width: 22px; padding: 1px 6px; margin: 0 2px; border-radius: 5px; border: 1px solid rgba(255,255,255,.25); border-bottom-width: 3px; background: rgba(255,255,255,.08); font: 700 11px 'Nunito', sans-serif; color: var(--ink); text-align: center; }

/* MENÜ */
#menu { background: radial-gradient(ellipse at center, rgba(0,0,0,0) 30%, rgba(0,10,20,.55) 100%); overflow: auto; }
.menu-wrap { display: grid; grid-template-columns: 380px 420px; grid-template-rows: auto auto; gap: 18px 22px; align-items: start; max-width: 100%; }
.logo { grid-column: 1 / -1; text-align: center; text-shadow: 0 4px 30px rgba(0,0,0,.7); }
.logo h1 { font-family: 'Pirata One', Georgia, serif; font-weight: 400; font-size: clamp(56px, 9vw, 112px); margin: 0; line-height: .95; color: var(--gold);
  background: linear-gradient(180deg, #ffe7a3 10%, #f2b734 55%, #a8650c 100%); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 0 #3b2306) drop-shadow(0 10px 24px rgba(0,0,0,.6)); }
.logo-sub { letter-spacing: .4em; text-transform: uppercase; font-size: 13px; color: var(--ink-dim); font-weight: 800; }
.logo-tag { letter-spacing: .25em; font-size: 14px; font-weight: 800; color: #9fd6ea; margin-top: 6px; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.colors button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(0,0,0,.4); cursor: pointer; box-shadow: inset 0 -4px 0 rgba(0,0,0,.25); }
.colors button.sel { border-color: #fff; transform: scale(1.12); box-shadow: 0 0 0 3px rgba(242,193,78,.6); }
.online-box { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.online-box > .btn { width: 100%; }
.help-card h3 { margin: 0 0 10px; font-family: 'Pirata One', serif; font-weight: 400; font-size: 28px; color: var(--gold); }
.steps div { display: flex; flex-direction: column; margin-bottom: 10px; }
.steps b { color: var(--gold); font-size: 15px; }
.steps span { font-size: 14px; color: var(--ink); opacity: .9; line-height: 1.45; }
.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; font-size: 13px; color: var(--ink-dim); margin-top: 6px; }
@media (max-width: 860px) { .menu-wrap { grid-template-columns: minmax(0, 420px); } }

/* LOBİ */
.lobby-card { width: min(520px, 100%); }
.lobby-head { display: flex; justify-content: space-between; align-items: end; }
.room-code { font-family: 'Nunito', sans-serif; font-weight: 900; font-size: 46px; color: var(--gold); letter-spacing: .12em; line-height: 1; }
.lobby-timer { text-align: right; } #lobbyTimer { font-size: 30px; font-weight: 800; }
.lobby-list { margin: 14px 0 6px; display: flex; flex-direction: column; gap: 6px; }
.lobby-slot { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: rgba(0,0,0,.28); border: 1px solid rgba(255,255,255,.06); font-weight: 700; }
.lobby-slot .dot { width: 16px; height: 16px; border-radius: 50%; box-shadow: inset 0 -3px 0 rgba(0,0,0,.3); }
.lobby-slot .tag { margin-left: auto; font-size: 12px; color: var(--ink-dim); }
.lobby-slot.empty { opacity: .45; font-style: italic; font-weight: 400; }

/* MARKET */
#market { background: rgba(3, 12, 20, .55); }
#market.in-battle { background: transparent; pointer-events: none; justify-content: flex-end; align-items: stretch; }
#market.in-battle .market-panel { pointer-events: auto; width: min(760px, 100%); max-height: 100%; }
.market-panel { width: min(1100px, 100%); max-height: 100%; display: flex; flex-direction: column; background: linear-gradient(180deg, rgba(48,31,15,.97), rgba(25,16,8,.97)); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 30px 80px rgba(0,0,0,.6); overflow: hidden; }
.market-top { display: flex; align-items: center; gap: 14px; padding: 14px 20px; border-bottom: 1px solid var(--line); background: rgba(0,0,0,.25); flex-wrap: wrap; }
.market-title { font-family: 'Pirata One', serif; font-size: 36px; color: var(--gold); margin-right: auto; line-height: 1; }
.gold-pill { display: flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 30px; background: rgba(0,0,0,.4); border: 1px solid var(--line); font-weight: 800; font-size: 22px; color: var(--gold); }
.coin-ico { width: 20px; height: 20px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff3b0, #f2c14e 45%, #b07a10); box-shadow: 0 0 0 2px #8a5a06 inset; display: inline-block; }
.m-timer { font-weight: 800; font-size: 20px; min-width: 60px; text-align: center; }
.market-body { display: flex; min-height: 0; flex: 1; overflow: hidden; }
.ship-side { width: 320px; padding: 14px 18px; border-right: 1px solid var(--line); overflow: auto; flex-shrink: 0; }
#market.in-battle .ship-side { display: none; }
#shipPreview { width: 100%; height: auto; border-radius: 12px; background: radial-gradient(ellipse at center, #1d6a8a, #0b3349); box-shadow: inset 0 0 30px rgba(0,0,0,.5); }
.stats { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 13px; margin-top: 10px; }
.stats span:nth-child(odd) { color: var(--ink-dim); }
.stats span:nth-child(even) { font-weight: 800; text-align: right; }
.crew-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.crew-slot { padding: 7px 9px; border-radius: 9px; background: rgba(0,0,0,.3); border: 1px dashed rgba(255,255,255,.15); font-size: 12px; font-weight: 700; display: flex; align-items: center; gap: 6px; min-height: 38px; }
.crew-slot.filled { border-style: solid; }
.crew-slot .stars { margin-left: auto; color: var(--gold); letter-spacing: -1px; }
.shop-side { flex: 1; display: flex; flex-direction: column; min-width: 0; padding: 14px 18px; overflow: hidden; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0,0,0,.25); color: var(--ink-dim); font: 800 15px 'Nunito', sans-serif; cursor: pointer; }
.tab.active { background: linear-gradient(180deg, #5a3c1c, #3a2510); color: var(--gold); border-color: var(--gold2); }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; overflow: auto; padding-right: 4px; flex: 1; align-content: start; }
.item { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: 12px; background: linear-gradient(180deg, rgba(255,240,200,.07), rgba(0,0,0,.2)); border: 1px solid rgba(255,255,255,.08); }
.item:hover { border-color: var(--line); }
.item .ih { display: flex; align-items: center; gap: 10px; }
.item canvas { width: 44px; height: 44px; border-radius: 10px; background: rgba(0,0,0,.35); flex-shrink: 0; }
.item .nm { font-weight: 800; font-size: 15px; line-height: 1.15; }
.item .lv { font-size: 11px; color: var(--gold); font-weight: 800; }
.item .ds { font-size: 12.5px; color: var(--ink-dim); line-height: 1.35; flex: 1; }
.item .per { font-size: 12px; color: #9fe0b0; font-weight: 700; }
.item .btn { padding: 8px 10px; font-size: 14px; display: flex; justify-content: center; gap: 6px; align-items: center; }
.item.owned { border-color: rgba(92, 207, 122, .5); }
.item .badge { position: absolute; top: 8px; right: 8px; font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 20px; background: var(--green); color: #082; color: #0b2a12; }
.ready-list { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; font-size: 12px; }
.ready-list span { padding: 4px 10px; border-radius: 20px; background: rgba(0,0,0,.3); }
.ready-list span.ok { color: var(--green); }
@media (max-width: 800px) { .ship-side { display: none; } }

/* SONUÇ */
.results-card { width: min(560px, 100%); text-align: center; }
.results-card h2 { font-family: 'Pirata One', serif; font-weight: 400; font-size: 52px; margin: 0 0 12px; color: var(--gold); }
.res-list { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.res-row { display: grid; grid-template-columns: 40px 18px 1fr 70px 70px 50px; gap: 8px; align-items: center; padding: 9px 12px; border-radius: 10px; background: rgba(0,0,0,.3); font-weight: 700; }
.res-row.me { outline: 2px solid var(--gold); }
.res-row.first { background: linear-gradient(90deg, rgba(242,193,78,.3), rgba(0,0,0,.3)); }
.res-row .pl { font-family: 'Pirata One', serif; font-size: 24px; color: var(--gold); }
.res-row .dot { width: 14px; height: 14px; border-radius: 50%; }
.res-row small { color: var(--ink-dim); font-size: 11px; display: block; font-weight: 600; }
.res-head { font-size: 11px; color: var(--ink-dim); background: none; padding: 0 12px; text-transform: uppercase; letter-spacing: .08em; }

/* SOHBET + BİLDİRİM */
#chatBox { position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); width: min(420px, 90vw); z-index: 8; }
#toasts { position: fixed; top: 90px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 9; pointer-events: none; }
.toast { padding: 8px 16px; border-radius: 30px; background: rgba(15,10,5,.85); border: 1px solid var(--line); font-weight: 800; animation: tin .25s ease-out, tout .4s ease-in 2.4s forwards; }
@keyframes tin { from { opacity: 0; transform: translateY(-10px); } }
@keyframes tout { to { opacity: 0; transform: translateY(-10px); } }

/* ---------- DOKUNMATİK + KÜÇÜK EKRAN ---------- */
html, body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none;
  touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
#rotate { cursor: pointer; }
canvas#game { touch-action: none; }
#touch { position: fixed; inset: 0; z-index: 4; pointer-events: none; touch-action: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
#touch[data-mode="island"] .battle-only { display: none; }
#joyZone { position: absolute; left: 0; bottom: 0; width: 45%; height: 72%; pointer-events: auto; touch-action: none; }
#joy { position: absolute; left: calc(26px + env(safe-area-inset-left)); bottom: calc(26px + env(safe-area-inset-bottom)); width: 124px; height: 124px; border-radius: 50%;
  background: radial-gradient(circle, rgba(20,13,6,.35), rgba(20,13,6,.6)); border: 2px solid rgba(242,193,78,.45); }
#joyKnob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe7a3, #d99a1e); box-shadow: 0 3px 8px rgba(0,0,0,.5); }
#sailBtns { position: absolute; left: calc(170px + env(safe-area-inset-left)); bottom: calc(30px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
#tRight { position: absolute; right: calc(18px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom)); width: 230px; height: 200px; }
.tbtn { position: relative; pointer-events: auto; touch-action: none; width: 68px; height: 68px; border-radius: 50%; overflow: hidden;
  border: 2px solid rgba(242,193,78,.6); background: rgba(20,13,6,.62); color: var(--ink); font: 800 12px 'Nunito', sans-serif; --cd: 0; }
.tbtn::after { content: ''; position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
  background: conic-gradient(rgba(0,0,0,.62) calc(var(--cd) * 360deg), transparent 0); }
.tbtn.on { background: rgba(242,193,78,.4); transform: scale(.94); }
.tbtn.off { opacity: .35; }
.tbtn.big { width: 96px; height: 96px; font-size: 17px; border-color: #ffb36a; background: rgba(120,40,10,.6); }
.tbtn.small { width: 52px; height: 52px; font-size: 10px; }
#tRight .tbtn { position: absolute; }
#tFire { right: 0; bottom: 0; }
#tAlt { right: 108px; bottom: 4px; }
#tAbility { right: 72px; bottom: 84px; }
#touch[data-mode="island"] #tAbility { right: 6px; bottom: 6px; width: 90px; height: 90px; font-size: 16px; }
#tAmmo { right: 4px; bottom: 108px; }
#tMarket { right: 152px; bottom: 100px; }
#rotate { display: none; position: fixed; inset: 0; z-index: 50; background: #061b29; align-items: center; justify-content: center; text-align: center; font: 800 20px 'Nunito', sans-serif; line-height: 1.8; padding: 24px; }
@media (orientation: portrait) and (pointer: coarse) { #rotate { display: flex; } }

@media (max-height: 560px) {
  .screen { padding: 8px; align-items: flex-start; overflow: auto; }
  .card { padding: 12px 14px; }
  .menu-wrap { grid-template-columns: minmax(0, 340px) minmax(0, 380px); gap: 8px 14px; margin: 0 auto; }
  .logo h1 { font-size: 46px; } .logo-sub, .logo-tag { font-size: 10px; margin-top: 0; }
  .btn.big { padding: 10px; margin-top: 10px; font-size: 16px; }
  .help-card h3 { font-size: 20px; margin-bottom: 4px; } .steps span { font-size: 12px; } .steps div { margin-bottom: 5px; }
  .keys { display: none; }
  .lobby-card, .results-card { margin: 0 auto; }
  .lobby-slot { padding: 6px 10px; } .room-code { font-size: 32px; }
  .results-card h2 { font-size: 30px; margin-bottom: 6px; } .res-row { padding: 4px 10px; }
  #market { align-items: stretch; }
  .market-panel { margin: 0 auto; }
  .market-top { padding: 6px 12px; gap: 8px; } .market-title { font-size: 24px; }
  .gold-pill { font-size: 17px; padding: 3px 10px; } .m-timer { font-size: 15px; }
  .ship-side { display: none; }
  .shop-side { padding: 8px 10px; } .tabs { margin-bottom: 8px; } .tab { padding: 7px; font-size: 13px; }
  .shop-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 7px; }
  .item { padding: 8px; gap: 4px; } .item canvas { width: 32px; height: 32px; } .item .nm { font-size: 13px; } .item .ds { font-size: 11px; }
  .item .btn { padding: 7px; font-size: 13px; }
  #toasts { top: 70px; } .toast { font-size: 12px; padding: 5px 12px; }
}
@media (pointer: coarse) { .keys { display: none; } }

/* ---------- profil, sıralama, bağlantı ---------- */
.profile-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; font-size: 13px; color: var(--ink-dim); }
.profile-row b { color: var(--gold); }
.btn.small-btn { padding: 7px 12px; font-size: 13px; flex: 0 0 auto; }
#board .res-row { grid-template-columns: 40px 18px 1fr 70px 70px 70px; }
#boardList { max-height: 55vh; overflow: auto; }
#netStatus { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 20; padding: 9px 18px; border-radius: 30px;
  background: rgba(120, 30, 20, .92); border: 1px solid #ff8a6a; color: #fff; font-weight: 800; font-size: 14px; text-align: center; max-width: 92vw; }
