:root {
  --bg: #0f1412;
  --panel: #171d1a;
  --panel-2: #1e2622;
  --line: #2c3832;
  --text: #e8efe9;
  --muted: #93a39a;
  --accent: #d4a017;
  --accent-2: #2f6fed;
  --ok: #2f9e6b;
  --warn: #c97b2b;
  --bad: #c44b4b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --font: "IBM Plex Sans JP", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1000px 500px at 10% -10%, rgba(212, 160, 23, 0.16), transparent 55%),
    radial-gradient(800px 400px at 100% 0%, rgba(47, 111, 237, 0.12), transparent 50%),
    linear-gradient(180deg, #121816, var(--bg));
}

.app {
  width: min(1760px, calc(100% - 20px));
  margin: 16px auto 40px;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 18px;
}
.brand {
  margin: 0 0 6px;
  letter-spacing: 0.18em;
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
}
h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 32px);
  font-weight: 700;
}
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr));
  gap: 10px;
}
.stat {
  background: rgba(23, 29, 26, 0.9);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat span {
  display: block;
  font-size: 22px;
  font-weight: 700;
}
.stat label {
  color: var(--muted);
  font-size: 12px;
}

.toolbar, .claim-box, .panel {
  background: rgba(23, 29, 26, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px;
  margin-bottom: 14px;
}
.toolbar .left, .toolbar .right, .claim-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.hint { color: var(--muted); font-size: 12px; }

button, .file-btn, select, input, textarea {
  font: inherit;
}
button, .file-btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
button:hover, .file-btn:hover { border-color: #4a5b52; }
button.primary {
  background: linear-gradient(180deg, #e0b12a, #b88710);
  color: #1a1405;
  border-color: transparent;
  font-weight: 700;
}
button.ghost { background: transparent; }
button.done { opacity: 0.7; cursor: default; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

input, select, textarea {
  background: #121816;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
}
#search { min-width: 180px; }
#keyword { width: 140px; }

.claim-box {
  padding: 12px 14px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.claim-box code {
  margin: 0 8px;
  color: #ffe6a3;
}
.code-pill {
  min-width: 88px;
  text-align: center;
  background: rgba(47, 158, 107, 0.15);
  border: 1px solid rgba(47, 158, 107, 0.4);
  color: #8fe0b8;
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.code-pill.got {
  background: rgba(212, 160, 23, 0.2);
  border-color: rgba(212, 160, 23, 0.55);
  color: #ffe6a3;
  animation: pulse 1.1s ease-in-out 3;
}
.auto-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  user-select: none;
}
.poll-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 10px;
  font-size: 12px;
  color: var(--muted);
}
.poll-status.running::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2f9e6b;
  box-shadow: 0 0 0 0 rgba(47, 158, 107, 0.7);
  animation: blink 1.2s infinite;
}
.poll-status.error { color: #ff9d9d; }
.poll-status.got { color: #ffe6a3; font-weight: 600; }

.code-banner {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  width: min(380px, calc(100vw - 24px));
  pointer-events: none;
}
.code-banner[hidden] { display: none !important; }
.code-banner-inner {
  pointer-events: auto;
  position: relative;
  background: linear-gradient(180deg, #2a352e, #171d1a);
  border: 1px solid rgba(212, 160, 23, 0.55);
  border-radius: 16px;
  padding: 18px 16px 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: pop-in 0.25s ease-out;
}
.banner-close {
  position: absolute;
  top: 6px;
  right: 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
}
.code-banner-inner p {
  margin: 0 0 8px;
  color: var(--accent);
  letter-spacing: 0.12em;
  font-size: 13px;
  font-weight: 600;
}
.banner-code {
  font-size: 42px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: #ffe6a3;
  margin: 8px 0 10px;
  min-height: 52px;
  line-height: 1.2;
  user-select: all;
}
.banner-meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 14px;
  word-break: break-all;
}
.banner-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.layout {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 14px;
}

.panel { padding: 14px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.panel-head h2 {
  margin: 0;
  font-size: 16px;
}

.pool-panel .table-wrap {
  overflow: auto;
  max-height: min(68vh, 740px);
  border: 1px solid var(--line);
  border-radius: 10px;
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 500;
  position: sticky;
  top: 0;
  background: #1a211d;
  z-index: 2;
}

tr:hover td { background: rgba(255,255,255,0.02); }
tr.active td { background: rgba(212, 160, 23, 0.08); }

.email-cell {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  border: 1px solid transparent;
}
.badge.idle {
  background: rgba(196, 75, 75, 0.2);
  border-color: rgba(196, 75, 75, 0.45);
  color: #ff9d9d;
}
.badge.in_use {
  background: rgba(201, 123, 43, 0.18);
  border-color: rgba(201, 123, 43, 0.45);
  color: #ffc48a;
}
.badge.registered {
  background: rgba(212, 160, 23, 0.22);
  border-color: rgba(212, 160, 23, 0.55);
  color: #ffe6a3;
}
.badge.dead {
  background: rgba(120, 120, 120, 0.2);
  border-color: rgba(150, 150, 150, 0.4);
  color: #c0c0c0;
}

.ops {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: center;
}
.ops button {
  padding: 5px 9px;
  font-size: 12px;
  border-radius: 8px;
  flex-shrink: 0;
}
button.danger {
  background: rgba(196, 75, 75, 0.18);
  border-color: rgba(196, 75, 75, 0.45);
  color: #ff9d9d;
}
button.danger:hover {
  border-color: #ff9d9d;
  background: rgba(196, 75, 75, 0.28);
}

.phone-input,
.note-input {
  display: block;
  width: 128px;
  background: #121816;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
}
.note-input { width: 150px; }

.reg-time {
  color: #ffe6a3;
  font-variant-numeric: tabular-nums;
  min-width: 88px;
}
.lottery-btn {
  min-width: 118px;
  padding: 5px 10px !important;
  font-size: 12px !important;
  border-radius: 8px !important;
  white-space: nowrap;
}
.lottery-btn.pending {
  background: rgba(196, 75, 75, 0.18) !important;
  border: 1px solid rgba(196, 75, 75, 0.5) !important;
  color: #ff9d9d !important;
}
.lottery-btn.drawn,
.lottery-btn.drawn:disabled {
  background: rgba(47, 158, 107, 0.2) !important;
  border: 1px solid rgba(47, 158, 107, 0.55) !important;
  color: #8fe0b8 !important;
  opacity: 1 !important;
  cursor: default !important;
}

.side .detail.empty {
  color: var(--muted);
  padding: 20px 8px;
}
.detail-email {
  font-size: 15px;
  font-weight: 600;
  word-break: break-all;
  margin-bottom: 8px;
}
.meta {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}
.meta strong { color: var(--text); font-weight: 500; }
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.form-grid {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}
.form-grid label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
.messages {
  display: grid;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}
.msg {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}
.msg .code {
  color: #ffe6a3;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.msg .sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.codes-panel { margin-top: 0; }
.codes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}
.code-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}
.code-card .c {
  font-size: 22px;
  font-weight: 700;
  color: #ffe6a3;
  letter-spacing: 0.1em;
}
.code-card .e, .code-card .s {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  word-break: break-all;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #203029;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 20;
  max-width: 360px;
}

.profile-box {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}
.profile-box h3 {
  margin: 0 0 10px;
  font-size: 14px;
}
.profile-grid { display: grid; gap: 6px; }
.profile-row {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}
.profile-row .k { color: var(--muted); }
.profile-row .v {
  word-break: break-all;
  font-weight: 500;
}
.btn-copy {
  background: rgba(47, 111, 237, 0.18) !important;
  border: 1px solid rgba(47, 111, 237, 0.55) !important;
  color: #9bbcff !important;
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  min-width: 52px;
}
.btn-copy:hover {
  background: rgba(47, 111, 237, 0.28) !important;
  border-color: #9bbcff !important;
}
.btn-copy.copied {
  background: rgba(47, 158, 107, 0.22) !important;
  border-color: rgba(47, 158, 107, 0.65) !important;
  color: #8fe0b8 !important;
}
.profile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.addr-ok { color: #8fe0b8; }
.addr-bad { color: #ff9d9d; }
.sr {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.profile-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}
.profile-modal[hidden] { display: none !important; }
.profile-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 8, 0.72);
  backdrop-filter: blur(3px);
}
.profile-modal-card {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  max-height: min(86vh, 860px);
  overflow: auto;
  background: linear-gradient(180deg, #24302a, #171d1a);
  border: 1px solid rgba(212, 160, 23, 0.4);
  border-radius: 16px;
  padding: 18px 16px 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  animation: pop-in 0.2s ease-out;
}
.profile-modal-card .detail-email {
  padding-right: 28px;
}
.profile-modal-card .profile-box {
  margin-bottom: 0;
}

@keyframes pop-in {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes blink {
  0% { box-shadow: 0 0 0 0 rgba(47, 158, 107, 0.55); }
  70% { box-shadow: 0 0 0 8px rgba(47, 158, 107, 0); }
  100% { box-shadow: 0 0 0 0 rgba(47, 158, 107, 0); }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.top-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
.account-bar {
  display: flex;
  gap: 8px;
  align-items: center;
}
.account-bar #whoami {
  color: var(--muted);
  font-size: 13px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: rgba(23, 29, 26, 0.94);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.login-card h1 { margin: 0 0 4px; font-size: 26px; }
.login-sub { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.login-card label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.login-card input { width: 100%; }
.login-card button { margin-top: 14px; }
.login-error { color: #ff9d9d; margin: 8px 0 0; font-size: 13px; }

.users-card { width: min(760px, 100%); }
.users-card h2 { margin: 0 28px 6px 0; }
.users-hint { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.users-form {
  display: grid;
  grid-template-columns: 1fr 1fr 140px 1fr auto;
  gap: 8px;
  margin-bottom: 14px;
}
.users-table-wrap { max-height: 360px; }

@media (max-width: 960px) {
  .top { flex-direction: column; align-items: stretch; }
  .top-right { align-items: stretch; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .email-cell { max-width: 180px; }
  .users-form { grid-template-columns: 1fr; }
}
