:root {
  --color-text: #262626;
  --color-sub: #737373;
  --color-border: #dbdbdb;
  --color-bg: #fafafa;
  --color-card: #fff;
  --color-surface: #efefef;
  --color-on-accent: #fff;
  --color-accent: #0095f6;
  --color-danger: #ed4956;
  --color-link: #00376b;
  --color-black: #000;
  --font-base: -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  --z-drag: 10;
  --z-sheet: 90;
  --z-modal: 100;
  --z-toast: 200;
}

/* ダークテーマ（Task 2のJSが data-theme を付与する） */
html[data-theme='dark'] {
  --color-text: #f5f5f5;
  --color-sub: #a8a8a8;
  --color-border: #363636;
  --color-bg: #121212;
  --color-card: #1e1e1e;
  --color-surface: #2a2a2a;
  color-scheme: dark;
}

html {
  font-size: 62.5%;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-base);
  font-size: 1.4rem;
  line-height: 1.5;
}

/* 汎用ボタン */
.button {
  display: inline-block;
  padding: 6px 14px;
  background: var(--color-accent);
  border-radius: 8px;
  color: var(--color-on-accent);
  font-size: 1.3rem;
  font-weight: 600;
}

@media (any-hover: hover) {
  .button:hover,
  .button:focus-visible {
    opacity: 0.85;
  }
}

.button--ghost {
  background: var(--color-surface);
  color: var(--color-text);
}

.button--danger {
  background: none;
  color: var(--color-danger);
}

/* トースト */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  z-index: var(--z-toast);
  max-width: 90%;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--color-text) 92%, transparent);
  border-radius: 8px;
  color: var(--color-on-accent);
  transform: translateX(-50%);
}

.toast--error {
  background: var(--color-danger);
}

/* ログイン画面 */
.login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

.login__form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(320px, 100%);
  padding: 32px 24px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 12px;
}

.login__title {
  font-size: 1.6rem;
  text-align: center;
}

.login__input {
  padding: 10px 12px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: var(--color-text);
}

.login__button {
  padding: 10px;
  background: var(--color-accent);
  border-radius: 8px;
  color: var(--color-on-accent);
  font-weight: 600;
}

@media (any-hover: hover) {
  .login__button:hover,
  .login__button:focus-visible {
    opacity: 0.85;
  }
}

.login__error {
  color: var(--color-danger);
  font-size: 1.2rem;
  text-align: center;
}

/* サイトヘッダー */
.site-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
}

.site-header__title {
  margin-right: auto;
  font-size: 1.5rem;
}

.site-header__theme {
  display: flex;
  align-items: center;
  color: var(--color-sub);
}

@media (any-hover: hover) {
  .site-header__theme:hover,
  .site-header__theme:focus-visible {
    color: var(--color-text);
  }
}

.site-header__logout {
  color: var(--color-sub);
  font-size: 1.2rem;
}

@media (any-hover: hover) {
  .site-header__logout:hover,
  .site-header__logout:focus-visible {
    color: var(--color-text);
  }
}

/* アカウント一覧 */
.accounts {
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 24px 16px;
}

.accounts__item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 12px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 12px;
}

.accounts__link {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.accounts__avatar {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  overflow: hidden;
  background: var(--color-surface);
  border-radius: 50%;
}

.accounts__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.accounts__body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.accounts__name {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.accounts__meta {
  color: var(--color-sub);
  font-size: 1.2rem;
}

.accounts__actions {
  display: flex;
  flex-shrink: 0;
  gap: 4px;
}

.accounts__add {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.accounts__add-input {
  flex: 1;
  padding: 8px 12px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: var(--color-text);
}

/* プレビュー画面レイアウト */
.site-header__back {
  flex-shrink: 0;
  font-size: 1.3rem;
}

@media (any-hover: hover) {
  .site-header__back:hover,
  .site-header__back:focus-visible {
    opacity: 0.7;
  }
}

.site-header__widths {
  display: flex;
  gap: 4px;
  margin-right: auto;
}

.site-header__ig {
  display: flex;
  gap: 4px;
}

.site-header__width,
.site-header__ig-theme {
  padding: 4px 8px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  color: var(--color-sub);
  font-size: 1.2rem;
}

@media (any-hover: hover) {
  .site-header__width:hover,
  .site-header__width:focus-visible,
  .site-header__ig-theme:hover,
  .site-header__ig-theme:focus-visible {
    border-color: var(--color-text);
    color: var(--color-text);
  }
}

.site-header__width.is-active,
.site-header__ig-theme.is-active {
  background: var(--color-text);
  border-color: var(--color-text);
  color: var(--color-bg); /* 反転配色（ダークでは明色地に暗文字になる） */
}

.site-header__draft {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--color-sub);
  font-size: 1.2rem;
}

.preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 0 80px;
}

@media (min-width: 768px) {
  .preview {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 24px;
    padding: 24px;
  }
}

.preview__phone {
  width: min(var(--frame-w, 393px), 100%);
  background: var(--ig-bg);
}

@media (min-width: 768px) {
  .preview__phone {
    flex-shrink: 0;
    border: 1px solid var(--color-border);
    border-radius: 24px;
    overflow: hidden;
  }
}

/* IG再現部分のテーマ（ツールテーマとは独立） */
.phone,
.preview__phone,
.post-modal__card {
  --ig-bg: #fff;
  --ig-text: #262626;
  --ig-sub: #737373;
  --ig-border: #dbdbdb;
  --ig-surface: #efefef;
  --ig-link: #00376b;
}

.phone--dark,
.preview__phone--dark,
.post-modal__card--dark {
  --ig-bg: #000;
  --ig-text: #f5f5f5;
  --ig-sub: #a8a8a8;
  --ig-border: #262626;
  --ig-surface: #1a1a1a;
  --ig-link: #b3dbff;
}

/* スマホフレーム内: Instagram再現部分 */
.phone {
  background: var(--ig-bg);
}

.phone__bar {
  padding: 12px 16px 4px;
  color: var(--ig-text);
  font-size: 1.6rem;
  font-weight: 700;
}

.profile {
  padding: 8px 16px;
}

.profile__top {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 10px;
}

.profile__avatar {
  flex-shrink: 0;
  width: 86px;
  height: 86px;
  overflow: hidden;
  background: var(--ig-surface);
  border-radius: 50%;
}

.profile__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile__stats {
  display: flex;
  flex: 1;
  justify-content: space-around;
}

.profile__stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--ig-text);
  font-size: 1.2rem;
}

.profile__stat-num {
  font-size: 1.6rem;
  font-weight: 700;
}

.profile__name {
  color: var(--ig-text);
  font-size: 1.3rem;
  font-weight: 600;
}

.profile__category {
  color: var(--ig-sub);
  font-size: 1.3rem;
}

.profile__bio {
  color: var(--ig-text);
  font-size: 1.3rem;
  white-space: pre-line;
}

.profile__link {
  color: var(--ig-link);
  font-size: 1.3rem;
  font-weight: 600;
}

.profile__buttons {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}

.profile__button {
  flex: 1;
  padding: 7px 0;
  background: var(--ig-surface);
  border-radius: 8px;
  color: var(--ig-text);
  font-size: 1.3rem;
  font-weight: 600;
  text-align: center;
}

/* ハイライト */
.highlights {
  display: flex;
  gap: 14px;
  padding: 8px 16px 12px;
  overflow-x: auto;
}

.highlights__item {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  align-items: center;
  gap: 4px;
  width: 64px;
  cursor: grab;
}

.highlights__circle {
  display: block;
  width: 56px;
  height: 56px;
  overflow: hidden;
  background: var(--ig-surface);
  border: 1px solid var(--ig-border);
  border-radius: 50%;
}

.highlights__circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.highlights__title {
  max-width: 100%;
  overflow: hidden;
  color: var(--ig-text);
  font-size: 1.1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* タブ */
.tabs {
  display: flex;
  border-top: 1px solid var(--ig-border);
}

.tabs__tab {
  flex: 1;
  padding: 10px 0;
  border-bottom: 1px solid transparent;
  color: var(--ig-sub);
  text-align: center;
}

@media (any-hover: hover) {
  .tabs__tab:hover,
  .tabs__tab:focus-visible {
    color: var(--ig-text);
  }
}

.tabs__tab svg {
  display: inline-block;
  vertical-align: middle;
}

.tabs__tab.is-active {
  border-bottom-color: var(--ig-text);
  color: var(--ig-text);
}

/* 投稿グリッド（3:4） */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  touch-action: pan-y;
}

.grid[hidden] {
  display: none;
}

.grid__item {
  position: relative;
  overflow: hidden;
  aspect-ratio: 3 / 4;
  background: var(--ig-surface);
  cursor: pointer;
}

.grid__item img,
.grid__item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.grid__item--draft {
  outline: 2px dashed var(--color-accent);
  outline-offset: -2px;
}

.grid__badge {
  position: absolute;
  top: 6px;
  right: 6px;
  filter: drop-shadow(0 0 2px color-mix(in srgb, var(--color-black) 40%, transparent));
}

.grid__draft-label,
.reels__draft-label {
  position: absolute;
  top: 4px;
  left: 4px;
  padding: 1px 5px;
  background: var(--color-accent);
  border-radius: 4px;
  color: var(--color-on-accent);
  font-size: 1rem;
}

/* リールタブ（9:16） */
.reels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  touch-action: pan-y;
}

.reels[hidden] {
  display: none;
}

.reels__item {
  position: relative;
  overflow: hidden;
  aspect-ratio: 9 / 16;
  background: var(--ig-surface);
  cursor: pointer;
}

.reels__item img,
.reels__item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reels__item--draft {
  outline: 2px dashed var(--color-accent);
  outline-offset: -2px;
}

/* ドラッグ中 */
.is-dragging {
  z-index: var(--z-drag);
  opacity: 0.6;
}

/* 編集パネル（スマホ: ボトムシート / PC: サイドパネル） */
.editor {
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: var(--z-sheet);
  width: 100%;
  max-height: 70vh;
  padding: 16px;
  overflow-y: auto;
  background: var(--color-card);
  border-top: 1px solid var(--color-border);
  transform: translateY(100%);
  transition: transform 0.25s;
}

.editor.is-open {
  transform: translateY(0);
}

.editor-toggle {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: var(--z-sheet);
  padding: 10px 20px;
  background: var(--color-accent);
  border-radius: 24px;
  color: var(--color-on-accent);
  font-weight: 600;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--color-black) 25%, transparent);
}

@media (any-hover: hover) {
  .editor-toggle:hover,
  .editor-toggle:focus-visible {
    opacity: 0.85;
  }
}

@media (min-width: 768px) {
  .editor {
    position: static;
    width: 340px;
    max-height: none;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    transform: none;
  }

  .editor-toggle {
    display: none;
  }
}

/* 編集パネルの中身 */
.editor__section {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
}

.editor__section:last-child {
  margin-bottom: 0;
  border-bottom: none;
}

.editor__heading {
  margin-bottom: 12px;
  font-size: 1.4rem;
}

.editor__field {
  display: block;
  margin-bottom: 10px;
}

.editor__label {
  display: block;
  margin-bottom: 2px;
  color: var(--color-sub);
  font-size: 1.2rem;
}

.editor__input {
  width: 100%;
  padding: 7px 10px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: var(--color-text);
  font-size: 1.3rem;
}

.editor__input--small {
  width: auto;
  flex: 1;
  min-width: 0;
}

.editor__row {
  display: flex;
  gap: 8px;
}

.editor__row .editor__field {
  flex: 1;
}

.editor__file {
  font-size: 1.2rem;
}

.editor__highlights {
  margin-bottom: 10px;
}

.editor__highlight {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.editor__hl-cover {
  flex-shrink: 0;
  cursor: pointer;
}

.editor__hl-add {
  display: flex;
  gap: 6px;
}

/* 投稿詳細モーダル */
.post-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: color-mix(in srgb, var(--color-black) 60%, transparent);
}

.post-modal__card {
  display: flex;
  flex-direction: column;
  width: min(420px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  background: var(--ig-bg);
  border-radius: 12px;
}

.post-modal__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}

.post-modal__avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  overflow: hidden;
  background: var(--ig-surface);
  border-radius: 50%;
}

.post-modal__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.post-modal__username {
  margin-right: auto;
  color: var(--ig-text);
  font-size: 1.3rem;
  font-weight: 600;
}

.post-modal__close {
  padding: 0 6px;
  color: var(--ig-sub);
  font-size: 2rem;
  line-height: 1;
}

.post-modal__media {
  position: relative;
  background: var(--color-black);
}

.post-modal__media img,
.post-modal__media video {
  width: 100%;
  height: auto;
}

.post-modal__empty {
  padding: 40px 0;
  color: var(--color-on-accent);
  text-align: center;
}

.post-modal__nav {
  position: absolute;
  top: 50%;
  width: 28px;
  height: 28px;
  background: color-mix(in srgb, var(--color-on-accent) 90%, transparent);
  border-radius: 50%;
  color: var(--color-black);
  font-size: 1.8rem;
  line-height: 1;
  transform: translateY(-50%);
}

.post-modal__nav:disabled {
  opacity: 0.3;
}

.post-modal__nav--prev {
  left: 8px;
}

.post-modal__nav--next {
  right: 8px;
}

.post-modal__dots {
  position: absolute;
  bottom: 8px;
  left: 50%;
  display: flex;
  gap: 4px;
  transform: translateX(-50%);
}

.post-modal__dot {
  width: 6px;
  height: 6px;
  background: color-mix(in srgb, var(--color-on-accent) 50%, transparent);
  border-radius: 50%;
}

.post-modal__dot.is-active {
  background: var(--color-on-accent);
}

.post-modal__body {
  padding: 12px;
}

.post-modal__caption {
  color: var(--ig-text);
  font-size: 1.3rem;
  white-space: pre-line;
}

.post-modal__textarea {
  width: 100%;
  margin-bottom: 8px;
  padding: 8px 10px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: var(--color-text);
}

.post-modal__toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 12px;
}

.post-modal__add {
  cursor: pointer;
}

/* アイコン切り抜きモーダル */
.crop-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: color-mix(in srgb, var(--color-black) 60%, transparent);
}

.crop-modal__card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  background: var(--color-card);
  border-radius: 12px;
}

.crop-modal__title {
  font-size: 1.4rem;
  font-weight: 600;
}

.crop-modal__viewport {
  position: relative;
  width: 280px;
  height: 280px;
  overflow: hidden;
  background: var(--color-surface);
  border-radius: 8px;
  cursor: grab;
  touch-action: none;
}

.crop-modal__viewport img {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: none;
  user-select: none;
  -webkit-user-drag: none;
}

.crop-modal__mask {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 999px color-mix(in srgb, var(--color-black) 45%, transparent);
  pointer-events: none;
}

.crop-modal__zoom {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-sub);
  font-size: 1.2rem;
}

.crop-modal__zoom input {
  flex: 1;
}

.crop-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
