:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667284;
  --line: #d8e0ea;
  --accent: #2563eb;
  --accent-strong: #1748b8;
  --danger: #b42318;
  --green: #0f766e;
  --shadow: 0 18px 50px rgba(24, 33, 47, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(90deg, rgba(24, 33, 47, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(24, 33, 47, 0.05) 1px, transparent 1px),
    #f4f7fb;
  background-size: 36px 36px;
}

.auth-card {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 26px;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin: 4px 0 10px;
  font-size: 28px;
  line-height: 1.25;
}

.auth-lead {
  margin: 0 0 18px;
  color: var(--muted);
}

.auth-tabs,
.mobile-nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 16px;
}

.auth-tab,
.mobile-tab {
  min-height: 44px;
  border: 0;
  background: #f8fafc;
  color: var(--muted);
  font-weight: 800;
}

.auth-tab.is-active,
.mobile-tab.is-active {
  background: var(--accent);
  color: #fff;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: 24px;
  line-height: 1.2;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted);
  font-weight: 800;
}

.primary-button,
.ghost-button,
.danger-button,
.drag-handle {
  min-height: 40px;
  border-radius: 7px;
  padding: 0 13px;
  border: 1px solid transparent;
  font-weight: 900;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover,
.primary-button:focus {
  background: var(--accent-strong);
}

.ghost-button {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.compact-button {
  min-height: 32px;
  padding: 0 10px;
}

.danger-button {
  min-height: 32px;
  color: var(--danger);
  background: #fff5f4;
  border-color: #ffd0cc;
}

.full-button {
  width: 100%;
}

.form-message {
  margin: 12px 0 0;
  color: var(--danger);
  font-weight: 800;
}

.mobile-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  margin: 0;
}

.mobile-tab {
  min-width: 0;
  font-size: 13px;
  white-space: nowrap;
}

.studio-layout {
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(360px, 1fr);
  min-height: calc(100vh - 110px);
  min-width: 0;
}

.builder-panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  min-width: 0;
  overflow: auto;
}

.builder-section {
  display: none;
  padding: 18px;
}

.builder-section.is-active {
  display: block;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 0 0 4px;
  font-size: 20px;
}

.section-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.field {
  display: grid;
  gap: 7px;
  margin: 0 0 15px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label {
  color: #334155;
  font-size: 13px;
  font-weight: 900;
}

input,
select,
textarea {
  width: 100%;
  min-height: 43px;
  border: 1px solid #c9d3df;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(37, 99, 235, 0.18);
  border-color: var(--accent);
}

.field small {
  color: var(--muted);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.toggle-row input {
  width: 18px;
  min-height: 18px;
}

.profile-fields.is-hidden {
  display: none;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.template-button,
.page-card {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  padding: 12px;
  text-align: left;
}

.template-button strong,
.page-card strong {
  display: block;
  margin-bottom: 4px;
}

.template-button span,
.page-card span {
  color: var(--muted);
  font-size: 12px;
}

.template-button:hover,
.template-button:focus,
.page-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.page-list {
  display: grid;
  gap: 10px;
}

.page-card {
  display: grid;
  gap: 6px;
}

.page-card__actions {
  display: flex;
  gap: 8px;
}

.item-list {
  display: grid;
  gap: 14px;
}

.item-editor {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfdff;
  padding: 13px;
}

.item-editor.is-dragging {
  opacity: 0.58;
  outline: 2px dashed var(--accent);
}

.item-editor header {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 9px;
}

.drag-handle {
  min-width: 42px;
  padding: 0;
  background: #eef4ff;
  color: var(--accent);
  border-color: #c7d8ff;
  touch-action: none;
}

.item-editor-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-editor-body {
  margin-top: 12px;
}

.item-editor:not(.is-expanded) .item-editor-body {
  display: none;
}

.publish-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 8px 0 16px;
}

.publish-box,
.estimate-box,
.stat-card {
  border: 1px solid #b7d7d2;
  border-radius: 8px;
  background: #f0fdfa;
  padding: 14px;
}

.publish-box:empty {
  display: none;
}

.publish-box a {
  color: var(--accent);
  font-weight: 900;
  word-break: break-all;
}

.estimate-box {
  display: grid;
  gap: 6px;
  margin: 4px 0 18px;
}

.estimate-box span,
.stat-card span {
  color: var(--green);
  font-weight: 900;
}

.estimate-box strong,
.stat-card strong {
  display: block;
  font-size: 30px;
  line-height: 1.1;
}

.estimate-box small,
.stat-card small {
  color: #45645f;
}

.stats-grid {
  display: grid;
  gap: 12px;
}

.stat-card {
  background: #fff;
  border-color: var(--line);
}

.stat-list {
  display: grid;
  gap: 8px;
}

.stat-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.stat-row:last-child {
  border-bottom: 0;
}

.preview-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(24, 33, 47, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(24, 33, 47, 0.05) 1px, transparent 1px),
    #f4f7fb;
  background-size: 36px 36px;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.preview-toolbar > div {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #22c55e;
}

.phone-frame {
  display: grid;
  place-items: start center;
  overflow: auto;
  padding: 26px;
}

.creator-page {
  width: min(430px, 100%);
  min-height: 760px;
  border: 9px solid #111827;
  border-radius: 30px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #fff;
}

.rank-page.theme-editorial {
  --page-bg: #f8fafc;
  --page-ink: #172033;
  --page-muted: #667284;
  --page-accent: #2563eb;
  --page-cta: #e03a2f;
}

.rank-page.theme-bright {
  --page-bg: #fff7ed;
  --page-ink: #1f2937;
  --page-muted: #6b4e35;
  --page-accent: #f97316;
  --page-cta: #db2777;
}

.rank-page.theme-minimal {
  --page-bg: #ffffff;
  --page-ink: #111827;
  --page-muted: #6b7280;
  --page-accent: #0f766e;
  --page-cta: #111827;
}

.rank-page.theme-luxury {
  --page-bg: #101820;
  --page-ink: #f7f0df;
  --page-muted: #d5c6a8;
  --page-accent: #d4af37;
  --page-cta: #f7f0df;
}

.rank-page {
  min-height: 100%;
  background: var(--page-bg);
  color: var(--page-ink);
}

.rank-hero {
  padding: 24px 20px 18px;
}

.rank-hero__profile {
  display: flex;
  gap: 13px;
  align-items: center;
  margin-bottom: 18px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: var(--page-accent);
  color: #fff;
  font-size: 24px;
  font-weight: 900;
}

.theme-luxury .avatar,
.theme-bright .avatar,
.theme-luxury .rank-badge,
.theme-bright .rank-badge {
  color: #111827;
}

.rank-hero h2,
.rank-hero p {
  margin: 0;
}

.rank-hero h2 {
  font-size: 25px;
  line-height: 1.2;
  word-break: break-word;
}

.rank-hero__profile strong {
  display: block;
  font-size: 16px;
}

.rank-hero__profile span,
.rank-hero p {
  color: var(--page-muted);
}

.disclosure {
  margin-top: 12px;
  padding: 9px 11px;
  border: 1px solid rgba(102, 114, 132, 0.28);
  border-radius: 8px;
  color: var(--page-muted);
  font-size: 12px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0 20px 18px;
}

.summary-strip span {
  display: grid;
  gap: 3px;
  min-height: 58px;
  border-radius: 8px;
  padding: 9px;
  background: rgba(37, 99, 235, 0.11);
  color: var(--page-muted);
  font-size: 11px;
}

.summary-strip strong {
  color: var(--page-ink);
  font-size: 15px;
}

.rank-items {
  display: grid;
  gap: 12px;
  padding: 0 14px 18px;
}

.rank-card {
  border: 1px solid rgba(102, 114, 132, 0.25);
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
}

.theme-luxury .rank-card {
  background: #17212b;
}

.rank-card__media {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #e5e7eb;
  overflow: hidden;
}

.rank-card__media img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.rank-badge {
  position: absolute;
  left: 12px;
  top: 12px;
  display: inline-flex;
  min-width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--page-accent);
  color: #fff;
  font-weight: 900;
}

.rank-card__body {
  padding: 14px;
}

.rank-card__body h3 {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: flex-start;
  margin: 0 0 8px;
  font-size: 18px;
  line-height: 1.25;
}

.item-tag {
  flex: 0 0 auto;
  max-width: 120px;
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(37, 99, 235, 0.12);
  color: var(--page-accent);
  font-size: 11px;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-card__body p {
  margin: 0 0 10px;
  color: var(--page-muted);
  line-height: 1.55;
}

.item-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  color: var(--page-ink);
  font-size: 13px;
  font-weight: 900;
}

.coupon {
  color: var(--page-accent);
}

.rank-cta {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--page-cta);
  color: #fff;
  text-decoration: none;
  font-weight: 900;
}

.theme-luxury .rank-cta {
  color: #101820;
}

.rank-footer {
  padding: 0 20px 28px;
  color: var(--page-muted);
  font-size: 12px;
  text-align: center;
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .studio-layout {
    grid-template-columns: 1fr;
  }

  .builder-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .preview-panel {
    min-height: 720px;
  }
}

@media (max-width: 640px) {
  .auth-card {
    padding: 20px;
  }

  .auth-card h1 {
    font-size: 24px;
  }

  .topbar {
    padding: 16px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .builder-section {
    padding: 16px;
  }

  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .field-grid,
  .template-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .phone-frame {
    padding: 16px;
  }

  .creator-page {
    border-width: 6px;
    border-radius: 24px;
  }

  .summary-strip {
    grid-template-columns: 1fr;
  }

  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
  }
}

/* ========================================
   ステータスバッジ（公開中 / 非公開 / 下書き）
   ======================================== */

.page-card__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 4px 0 8px;
}

.page-card__date {
  color: var(--muted);
  font-size: 12px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
  white-space: nowrap;
}

.status-badge::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

/* 公開中（緑） */
.status-badge.is-published {
  background: rgba(34, 197, 94, 0.12);
  color: #15803d;
}
.status-badge.is-published::before {
  background: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

/* 非公開（オレンジ） */
.status-badge.is-unpublished {
  background: rgba(249, 115, 22, 0.12);
  color: #c2410c;
}
.status-badge.is-unpublished::before {
  background: #f97316;
}

/* 下書き（グレー） */
.status-badge.is-draft {
  background: rgba(107, 114, 128, 0.12);
  color: #4b5563;
}
.status-badge.is-draft::before {
  background: #9ca3af;
}

/* ========================================
   公開URL コピーボタン
   ======================================== */
.publish-status {
  margin-bottom: 12px;
}
.publish-url-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.publish-url-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  font-size: 13px;
  color: var(--ink);
  font-family: monospace;
  min-width: 0;
}
.copy-button {
  padding: 8px 14px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.copy-button:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}
.copy-button.is-copied {
  background: #22c55e;
  border-color: #22c55e;
}
.open-button {
  padding: 8px 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: all 0.15s;
}
.open-button:hover {
  border-color: var(--ink);
}

/* ========================================
   ステータスバッジをクリック可能ボタンに
   ======================================== */
button.status-badge {
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
button.status-badge:hover {
  filter: brightness(0.95);
  transform: translateY(-1px);
}

/* ステータス変更メニュー */
.status-menu {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 4px;
  min-width: 160px;
  animation: statusMenuFadeIn 0.15s ease-out;
}
@keyframes statusMenuFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.status-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: transparent;
  text-align: left;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
  transition: background 0.1s;
}
.status-menu-item:hover {
  background: #f5f5f7;
}
.status-menu-item.is-current {
  background: rgba(37, 99, 235, 0.06);
  font-weight: 600;
}
.status-menu-item .check {
  margin-left: auto;
  color: var(--accent);
  font-weight: 700;
}

/* ========================================
   マイページモーダル
   ======================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  animation: modalSlideUp 0.25s ease-out;
}

@keyframes modalSlideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 28px;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.15s;
}

.modal-close:hover {
  background: #f1f5f9;
  color: var(--ink);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.profile-section {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.profile-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
}

.profile-section h3 {
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.02em;
}

.section-hint,
.field-hint {
  font-size: 12px;
  color: var(--muted);
  margin: -8px 0 14px;
  display: block;
}

.field-hint {
  margin-top: 4px;
}

.sns-field {
  margin-bottom: 12px;
}

.sns-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.sns-input-wrap {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
  transition: border-color 0.15s;
}

.sns-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.sns-prefix {
  padding: 8px 12px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  border-right: 1px solid var(--line);
}

.sns-input-wrap input {
  flex: 1;
  border: none;
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
  background: transparent;
  min-width: 0;
}

.modal-actions {
  display: flex;
  gap: 12px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  margin-top: 24px;
}

.modal-actions .primary-button {
  flex: 1;
}

.profile-message {
  margin: 12px 0 0;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  display: none;
}

.profile-message:not(:empty) {
  display: block;
}

.profile-message.is-success {
  background: rgba(34, 197, 94, 0.12);
  color: #15803d;
}

.profile-message.is-error {
  background: rgba(239, 68, 68, 0.12);
  color: #b91c1c;
}

/* スマホ対応 */
@media (max-width: 600px) {
  .modal-content {
    max-height: 100vh;
    border-radius: 0;
  }
  .modal-body {
    padding: 16px;
  }
}
