:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f2f5;
  --border: #e5e7eb;
  --text: #1c2029;
  --text-soft: #767b8a;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --green: #16a34a;
  --red: #dc2626;
  --p0: #e08a1c;
  --p0-soft: #fef3e0;
  --p1: #e0529c;
  --p1-soft: #fce7f3;
  --p2: #2e93c9;
  --p2-soft: #e3f2fb;
  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20,20,30,0.04), 0 4px 16px rgba(20,20,30,0.05);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}
.stamp-font { font-weight: 700; }
.wrap {
  max-width: 480px; margin: 0 auto;
  padding: 20px 16px calc(40px + env(safe-area-inset-bottom));
}
@media (min-width: 480px) {
  .wrap { padding-top: 32px; }
}

.doc-head { padding: 4px 2px 18px; }
.doc-id { font-size: 11.5px; color: var(--text-soft); margin-bottom: 6px; font-family: ui-monospace, 'SF Mono', Menlo, monospace; }
h1 { font-size: 22px; line-height: 1.25; margin: 0 0 6px; font-weight: 700; letter-spacing: -0.01em; color: var(--text); }
.sub { font-size: 13.5px; color: var(--text-soft); margin: 0; line-height: 1.5; }

.section-label {
  font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; font-weight: 600;
  color: var(--text-soft); margin: 26px 0 10px;
  display: flex; align-items: center; gap: 10px;
}
.section-label::after { content: ''; flex: 1; border-top: 1px solid var(--border); }

/* oyuncu renkleri */
.player-0 { --pcolor: var(--p0); --pcolor-soft: var(--p0-soft); }
.player-1 { --pcolor: var(--p1); --pcolor-soft: var(--p1-soft); }
.player-2 { --pcolor: var(--p2); --pcolor-soft: var(--p2-soft); }

/* kimlik secimi */
.whoami-row { display: flex; gap: 8px; }
.whoami-btn {
  flex: 1; min-height: 44px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 4px; text-align: center; cursor: pointer; font-weight: 600; font-size: 12.5px; color: var(--text);
  transition: border-color .15s, background .15s, color .15s, transform .1s;
  overflow-wrap: break-word;
}
.whoami-btn:active { transform: scale(0.97); }
.whoami-btn .em { display: block; font-size: 20px; margin-bottom: 4px; }
.whoami-btn.active { background: var(--pcolor, var(--accent)); color: #fff; border-color: var(--pcolor, var(--accent)); }
.logout-link {
  display: block; margin-top: 8px; background: none; border: none; padding: 6px 2px; min-height: 32px;
  font-size: 11.5px; color: var(--text-soft); text-decoration: underline; cursor: pointer; font-family: inherit;
}
.logout-link:hover, .logout-link:active { color: var(--red); }

.auth-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-top: 10px; box-shadow: var(--shadow); }
.auth-title { font-weight: 700; font-size: 13.5px; margin-bottom: 4px; }
.auth-hint { font-size: 11.5px; color: var(--text-soft); margin-bottom: 10px; line-height: 1.4; }
.auth-box input[type=password] {
  display: block; width: 100%; min-height: 44px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 10px; font-size: 16px; color: var(--text); font-family: inherit; margin-bottom: 8px;
}
.auth-box input[type=password]:focus { outline: none; border-color: var(--accent); }
.auth-error { color: var(--red); font-size: 12px; margin-bottom: 8px; }
.auth-actions { display: flex; gap: 8px; }
.auth-actions button { flex: 1; min-height: 44px; border-radius: var(--radius-sm); font-size: 12.5px; font-weight: 600; cursor: pointer; font-family: inherit; }
#auth-submit { background: var(--accent); color: #fff; border: none; }
#auth-submit:disabled { opacity: .5; }
#auth-cancel { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
#auth-cancel:hover, #auth-cancel:active { border-color: var(--text-soft); }

.roster { display: flex; gap: 8px; margin-bottom: 4px; }
.badge { flex: 1; background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--pcolor, var(--border)); border-radius: var(--radius); padding: 12px 8px 10px; position: relative; text-align: center; }
.badge::before {
  content: attr(data-rank); position: absolute; top: -7px; right: -6px; background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700; width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 0 0 2px var(--bg);
}
.badge-emoji {
  font-size: 18px; width: 34px; height: 34px; margin: 0 auto 6px; border-radius: 50%;
  background: var(--pcolor-soft, var(--surface-2)); display: flex; align-items: center; justify-content: center;
}
.badge-name { font-weight: 600; font-size: 12.5px; }

.memo { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px; margin-top: 18px; box-shadow: var(--shadow); position: relative; }
.memo-row { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-soft); padding-bottom: 10px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.leader-line { display: flex; align-items: center; gap: 10px; }
.leader-name { font-weight: 700; font-size: 20px; color: var(--pcolor, var(--text)); }
.leader-tag { font-size: 11px; color: var(--accent); background: var(--accent-soft); padding: 3px 9px; border-radius: 100px; font-weight: 600; }
.empty-leader { font-size: 13px; color: var(--text-soft); }
.stat-row { display: flex; gap: 10px; margin-top: 14px; }
.stat { flex: 1; min-width: 0; }
.stat .n { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-weight: 700; font-size: 17px; color: var(--text); white-space: nowrap; }
.stat .l { font-size: 10px; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }

.rank-list { margin-top: 8px; }
.rank-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.rank-row:last-child { border-bottom: none; }
.rank-no { font-weight: 700; width: 16px; color: var(--text-soft); font-size: 12px; }
.rank-row.first .rank-no { color: var(--accent); }
.rank-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pcolor, var(--border)); flex-shrink: 0; }
.rank-nm { flex: 1; font-weight: 600; }
.rank-bar { flex: 1.2; height: 6px; background: var(--surface-2); border-radius: 100px; overflow: hidden; }
.rank-bar > div { height: 100%; background: var(--accent); border-radius: 100px; }
.rank-w { font-family: ui-monospace, 'SF Mono', Menlo, monospace; width: 30px; text-align: right; font-size: 12px; color: var(--text-soft); }

.form-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px; margin-top: 10px; box-shadow: var(--shadow); }
.form-locked { text-align: center; color: var(--text-soft); font-size: 13px; padding: 10px 0; }
.date-line { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.date-line label { font-size: 11px; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.date-line input[type=date] { min-height: 40px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); padding: 6px 10px; font-size: 15px; font-family: inherit; }

.entry-field { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 13.5px; }
.entry-field .ef-name { flex: 1; min-width: 0; color: var(--text); }
.entry-field .ef-input { display: flex; align-items: center; gap: 4px; min-height: 44px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 10px; }
.entry-field input[type=number] { width: 64px; background: transparent; border: none; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 16px; text-align: right; color: var(--text); }
.entry-field input:focus { outline: none; }
.entry-field .unit { font-size: 11px; color: var(--text-soft); }

.file-row { margin-bottom: 14px; }
.file-row label { font-size: 11px; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; display: block; margin-bottom: 8px; }
.file-row .opt { text-transform: none; font-weight: 400; letter-spacing: 0; opacity: .7; }
.file-drop {
  position: relative; min-height: 76px; border: 1.5px dashed var(--border); border-radius: var(--radius); padding: 20px 12px;
  text-align: center; cursor: pointer; background: var(--surface-2); transition: border-color .15s, background .15s;
}
.file-drop:hover, .file-drop:active { border-color: var(--accent); }
.file-drop.drag-active { border-color: var(--accent); background: var(--accent-soft); }
.file-drop.has-file { border-style: solid; border-color: var(--accent); background: var(--accent-soft); }
.file-drop input { display: none; }
.file-drop-inner { display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.file-icon { font-size: 24px; opacity: .8; }
#file-drop-text { font-size: 13px; color: var(--text-soft); }
.file-remove {
  display: none; align-items: center; justify-content: center; position: absolute; top: 6px; right: 6px;
  width: 36px; height: 36px; background: var(--surface); border: 1px solid var(--border); border-radius: 50%;
  color: var(--text-soft); cursor: pointer; font-size: 13px; padding: 0;
}
.file-remove:hover, .file-remove:active { color: var(--red); border-color: var(--red); }
.file-preview { margin-top: 10px; max-width: 100%; max-height: 160px; border-radius: var(--radius-sm); border: 1px solid var(--border); display: none; }

.submit-btn {
  width: 100%; min-height: 48px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius);
  padding: 13px; font-weight: 600; font-size: 14.5px; cursor: pointer; margin-top: 8px;
  transition: opacity .15s, transform .1s; font-family: inherit;
}
.submit-btn:hover:not(:disabled) { opacity: .92; }
.submit-btn:disabled { opacity: .4; cursor: not-allowed; }
.submit-btn:active:not(:disabled) { transform: scale(0.99); }

.msg { font-size: 12.5px; margin-top: 10px; min-height: 15px; }
.msg.ok { color: var(--green); }
.msg.err { color: var(--red); }

.log-item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.log-item:last-child { border-bottom: none; }
.log-date { font-family: ui-monospace, 'SF Mono', Menlo, monospace; color: var(--text-soft); width: 46px; font-size: 11px; padding-top: 4px; flex-shrink: 0; }
.log-body { flex: 1; }
.log-times { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.log-time { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 11.5px; padding: 6px 8px; border-radius: 100px; background: var(--surface-2); color: var(--text-soft); display: inline-flex; align-items: center; gap: 6px; }
.log-time.win { background: var(--pcolor-soft, var(--accent-soft)); color: var(--pcolor, var(--accent)); font-weight: 700; }
.log-thumb { width: 32px; height: 24px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); cursor: zoom-in; vertical-align: middle; }
.del-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
  background: none; border: none; color: var(--text-soft); cursor: pointer; font-size: 13px; padding: 0; margin-left: 2px;
}
.del-btn:hover, .del-btn:active { color: var(--red); }
.empty-log { font-size: 12.5px; color: var(--text-soft); text-align: center; padding: 16px 0; }

.foot { text-align: center; font-size: 11px; color: var(--text-soft); margin-top: 26px; line-height: 1.6; }
.loading { text-align: center; padding: 60px 0; color: var(--text-soft); font-size: 13px; }

.stamp-overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; z-index: 999; }
.stamp-el {
  font-weight: 700; font-size: 22px; color: var(--accent); border: 2px solid var(--accent); border-radius: 16px;
  padding: 14px 26px; transform: scale(1.3); opacity: 0; text-align: center;
  animation: stampdown 0.7s cubic-bezier(.2,1.4,.4,1) forwards;
  background: var(--surface); box-shadow: var(--shadow);
}
@keyframes stampdown {
  0% { transform: scale(1.4); opacity: 0; }
  40% { transform: scale(0.97); opacity: 1; }
  55% { transform: scale(1.02); }
  70% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1); opacity: 0; }
}

.gate-wrap {
  min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
.gate-box {
  width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px 22px; box-shadow: var(--shadow); text-align: center;
}
.gate-icon { font-size: 28px; margin-bottom: 8px; }
.gate-title { font-size: 19px; font-weight: 700; margin: 0 0 8px; color: var(--text); }
.gate-sub { font-size: 13px; color: var(--text-soft); line-height: 1.5; margin: 0 0 18px; }
.gate-box input[type=password] {
  display: block; width: 100%; min-height: 44px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 12px; font-size: 16px; color: var(--text); font-family: inherit;
  margin-bottom: 8px; text-align: center;
}
.gate-box input[type=password]:focus { outline: none; border-color: var(--accent); }
.gate-box #gate-submit {
  width: 100%; min-height: 46px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius);
  font-weight: 600; font-size: 13.5px; cursor: pointer; margin-top: 6px; font-family: inherit;
}
.gate-box #gate-submit:disabled { opacity: .5; }

.confetti-piece {
  position: fixed; top: -12px; width: 8px; height: 14px; border-radius: 2px;
  pointer-events: none; z-index: 1000; opacity: 0.95;
  animation-name: confetti-fall; animation-timing-function: ease-in; animation-fill-mode: forwards;
}
@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(105vh) rotate(var(--rot, 360deg)); opacity: 0; }
}

.lightbox {
  position: fixed; inset: 0; background: rgba(15,17,24,0.85); display: flex; align-items: center;
  justify-content: center; z-index: 998; cursor: zoom-out; padding: 24px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; }
