@import url('https://fonts.googleapis.com/css2?family=M+PLUS+Rounded+1c:wght@400;700;800;900&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  background: linear-gradient(135deg, #ddf0fb 0%, #c5e4f5 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 0 40px;
}

.site-header {
  width: 100%;
  background: linear-gradient(90deg, #2a78c4 0%, #4a9ae0 100%);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}
.site-header .logo-img { height: 36px; width: auto; display: block; }
.page-subtitle { font-size: 13px; color: rgba(255,255,255,0.85); margin-left: auto; }

.card-shell {
  width: 100%;
  max-width: 420px; /* サイズ切り替え時にJSが書き換える */
  background: white;
  border-radius: 20px;
  box-shadow: 0 8px 32px rgba(42,120,196,0.18);
  overflow: hidden;
  margin: 0 16px;
}

/* ===== サイズ切り替えタブ ===== */
.size-tabs {
  display: flex;
  gap: 6px;
  padding: 10px;
  background: #f0f8ff;
  border-bottom: 1px solid #e0ecf5;
}
.size-tabs button {
  flex: 1;
  padding: 10px 8px;
  border: 2px solid #c4def4;
  background: #fff;
  color: #4a8ad4;
  border-radius: 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s;
  line-height: 1.3;
}
.size-tabs button small {
  display: block;
  font-size: 10px;
  font-weight: 400;
  opacity: 0.85;
  margin-top: 2px;
}
.size-tabs button.active {
  background: linear-gradient(90deg, #4a9ae0, #2a78c4);
  border-color: #2a78c4;
  color: #fff;
  box-shadow: 0 3px 10px rgba(42,120,196,0.28);
}

/* ===== 名札本体（縦横比・倍率はJSがサイズ設定から与える） ===== */
#nametag {
  --u: 1; /* 表示幅に応じた文字の倍率（スマホでも比率を保つ） */
  width: 100%;
  aspect-ratio: 1181 / 1748;
  position: relative;
  overflow: hidden;
  background: #e8f4fb;
}
#bgImg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  pointer-events: none;
  user-select: none;
}

/* ===== キャラクター（名刺サイズなど、背景と別レイヤーの場合のみ表示） ===== */
.chara-strip {
  position: absolute;
  bottom: 0;
  z-index: 3;
  display: none;
  pointer-events: none;
}
.chara-strip img { width: 100%; height: auto; display: block; }

/* ===== 丸写真（位置・サイズはJSがconfigから設定） ===== */
.circle-photo {
  position: absolute;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  z-index: 2;
  background-color: #ffffff;
  background-image: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--ph-shadow, none); /* サイズ設定の photoShadow で切り替え */
}
.circle-photo::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: #ffffff;
  z-index: 0;
}
.circle-photo img {
  position: relative;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
  display: none;
  background-color: #ffffff;
  z-index: 1;
}
.circle-photo .ph-hint {
  position: relative;
  z-index: 2;
  background: rgba(42,120,196,0.7);
  color: white;
  /* 小さいプレビュー（名刺サイズのスマホ表示など）でも丸枠からはみ出さないよう縮む */
  font-size: max(8px, calc(11px * var(--u, 1)));
  font-weight: 700;
  padding: max(3px, calc(5px * var(--u, 1))) max(6px, calc(12px * var(--u, 1)));
  border-radius: 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  pointer-events: none;
}

/* ===== QRコード ===== */
.qr-box {
  position: absolute;
  background: white;
  border-radius: 2px;
  padding: 3px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  z-index: 3;
}
.qr-box #qrcode {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-box #qrcode img,
.qr-box #qrcode canvas {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
}
.qr-box .qr-hint {
  font-size: calc(8px * var(--u, 1));
  color: #90a8c0;
  text-align: center;
  font-weight: 700;
  line-height: 1.3;
}

/* ===== 名前・やっていること（数値はJSがサイズ設定から与える） ===== */
.tag-name, .tag-role {
  position: absolute;
  text-align: center;
  color: #1a1a1a;
  line-height: 1.15;
  outline: none;
  z-index: 4;
}
.tag-name { font-weight: 900; }
.tag-role { font-weight: 800; line-height: 1.2; }
.tag-name:empty::before, .tag-role:empty::before {
  content: attr(data-placeholder);
  color: rgba(150,170,200,0.7);
  font-weight: 400;
  font-size: calc(var(--ph-fs, 18) * 1px * var(--u, 1));
  letter-spacing: calc(var(--ph-ls, 2) * 1px * var(--u, 1));
}

/* ===== 操作パネル ===== */
.controls {
  padding: 20px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: white;
}
.size-note {
  text-align: center;
  font-size: 11px;
  color: #5a8ab8;
  padding: 8px;
  background: #f0f8ff;
  border-radius: 8px;
}
.ctrl-row { display: flex; align-items: center; gap: 10px; }
.ctrl-label { font-size: 12px; font-weight:700; color: #4a8ad4; min-width: 80px; }
.up-btn {
  flex: 1;
  padding: 10px 14px;
  background: linear-gradient(90deg, #4a9ae0, #2a78c4);
  color: white; border: none; border-radius: 20px;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 13px; font-weight:700; cursor:pointer;
  box-shadow: 0 3px 10px rgba(42,120,196,0.28);
  transition: all 0.18s;
}
.up-btn:hover { transform:translateY(-1px); box-shadow:0 5px 14px rgba(42,120,196,0.38); }
.in-group { flex:1; display:flex; flex-direction:column; gap:6px; }
.in-field {
  padding: 9px 14px;
  border: 2px solid #c4def4;
  border-radius: 12px;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 14px; font-weight:700; color:#1a4878;
  outline:none; transition: border-color 0.18s; background:white;
  width: 100%;
}
.in-field:focus { border-color: #2a78c4; }
.in-field::placeholder { color:#b0c8e0; font-weight:400; font-size:12px; }

.qr-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}
.ctrl-label-full {
  font-size: 12px;
  font-weight: 700;
  color: #4a8ad4;
}
.qr-input-row {
  display: flex;
  gap: 6px;
  align-items: center;
  width: 100%;
}
.qr-url-input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border: 2px solid #c4def4;
  border-radius: 12px;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 13px;
  color: #1a4878;
  outline: none;
  background: white;
}
.qr-url-input:focus { border-color: #2a78c4; }
.qr-gen-btn {
  padding: 10px 18px;
  background: linear-gradient(90deg, #4a9ae0, #2a78c4);
  color: white; border: none; border-radius: 12px;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 13px; font-weight: 700; cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.hint-txt { text-align:center; font-size:11px; color:#a0b8d0; margin-top:-4px; }

.dl-btn {
  width:100%; padding:14px;
  background: linear-gradient(90deg, #f0a020, #f8c030);
  color:white; border:none; border-radius:24px;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size:16px; font-weight:900; cursor:pointer;
  box-shadow: 0 4px 18px rgba(240,160,32,0.38);
  letter-spacing:2px;
  text-shadow: 1px 1px 0 rgba(140,60,0,0.2);
  transition: all 0.18s;
}
.dl-btn:hover { transform:translateY(-2px); box-shadow:0 6px 22px rgba(240,160,32,0.48); }
.dl-btn:disabled { opacity:0.7; transform:none; }

/* ===== 印刷用シート（複数枚まとめて1枚の用紙に） ===== */
.sheet-row { display:flex; gap:10px; }
.sheet-row:empty { display:none; }
.dl-btn.sub {
  flex:1;
  padding:10px;
  font-size:12px;
  font-weight:700;
  letter-spacing:1px;
  line-height:1.5;
  background: linear-gradient(90deg, #4a9ae0, #2a78c4);
  box-shadow: 0 3px 12px rgba(42,120,196,0.28);
  text-shadow: none;
  border-radius: 16px;
}
.dl-btn.sub:hover { box-shadow: 0 5px 16px rgba(42,120,196,0.38); }

.hidden { display:none; }

.pos-ctrl {
  background: #f0f8ff;
  padding: 10px;
  border-radius: 10px;
  font-size: 11px;
  color: #4a8ad4;
}
.pos-ctrl details summary { cursor: pointer; font-weight: 700; }
.pos-ctrl .pos-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.pos-ctrl label { display: flex; flex-direction: column; gap: 3px; font-size: 10px; }
.pos-ctrl input[type="range"] { width: 100%; }
.pos-ctrl .val { font-weight: 700; color: #2a78c4; }

#statusMsg {
  text-align: center;
  padding: 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  display: none;
}
#statusMsg.success { background: #e8f8ee; color: #2a8848; display: block; }
#statusMsg.error   { background: #fde8e8; color: #c83030; display: block; }

/* ===== 保存モーダル（Android・アプリ内ブラウザ用フォールバック） ===== */
#saveModal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 20px;
}
#saveModal .save-modal-inner {
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  max-width: 340px;
  width: 100%;
  text-align: center;
}
#saveModal .save-modal-inner p {
  font-size: 13px;
  font-weight: 700;
  color: #2a78c4;
  margin-bottom: 10px;
}
#saveModal .save-modal-inner img {
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid #e0ecf5;
}
#saveModal .save-modal-inner button {
  margin-top: 12px;
  padding: 10px 28px;
  border: none;
  border-radius: 20px;
  background: #2a78c4;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
