:root {
  color-scheme: light;
  --page-width: 480px;
  --bg: #f6f6f6;
  --chat-bg: #c1d1de;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --ink: #222222;
  --muted: #777777;
  --subtle: #9a9a9a;
  --line: #e7e7e7;
  --line-strong: #d8d8d8;
  --soft: #f4f4f4;
  --soft-raised: #f7f7f7;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --font-xs: 11px;
  --font-sm: 12px;
  --font-md: 13px;
  --font-lg: 15px;
  --font-title: 22px;
  --control-height: 36px;
  --teal: #222222;
  --teal-dark: #111111;
  --coral: #e35d4f;
  --bubble-yellow: #fee500;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.14);
  --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: var(--font-md);
  line-height: 1.45;
  overscroll-behavior: none;
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, var(--page-width));
  height: 100dvh;
  min-height: 0;
  max-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-inline: 1px solid var(--line);
  overflow: hidden;
}

.top-bar {
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 16px 22px 15px;
  background: var(--chat-bg);
}

.chat-title-row {
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 10px;
}

.message-time {
  margin-bottom: 7px;
  color: #39434a;
  font-size: var(--font-md);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.title-bubble {
  position: relative;
  max-width: 72%;
  min-height: 56px;
  display: flex;
  align-items: center;
  padding: 13px 20px;
  border-radius: 18px;
  background: var(--bubble-yellow);
  color: #000000;
}

.title-bubble::after {
  content: "";
  position: absolute;
  top: 0;
  right: -7px;
  width: 18px;
  height: 18px;
  background: var(--bubble-yellow);
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

.top-bar h1 {
  margin: 0;
  font-size: var(--font-title);
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
}

.icon-button {
  width: var(--control-height);
  height: var(--control-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  line-height: 1;
  font-size: 20px;
}

.icon-button:hover,
.group-tab:hover,
.menu-button:hover {
  background-color: var(--soft);
}

.group-strip {
  display: flex;
  align-items: center;
  min-height: 54px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--soft-raised);
}

.group-list {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  overflow-x: auto;
  scrollbar-width: none;
}

.group-list::-webkit-scrollbar {
  display: none;
}

.group-tab {
  position: relative;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  background: transparent;
  color: #3a3a3a;
  cursor: pointer;
  overflow: visible;
}

.group-tab.is-new-group {
  position: sticky;
  right: 0;
  z-index: 2;
  background: var(--soft-raised);
  color: #333333;
}

.group-tab.is-thumb {
  background: transparent;
}

.group-tab.is-active {
  border-color: var(--line-strong);
  background: #ffffff;
  box-shadow: var(--shadow-soft);
}

.group-default-icon,
.group-new-icon {
  position: relative;
  width: 26px;
  height: 26px;
  display: block;
}

.group-default-icon {
  border: 2px solid #333333;
  border-radius: 50%;
}

.group-default-icon::before,
.group-default-icon::after {
  content: "";
  position: absolute;
}

.group-default-icon::before {
  top: 7px;
  left: 6px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #333333;
  box-shadow: 10px 0 0 #333333;
}

.group-default-icon::after {
  left: 7px;
  bottom: 6px;
  width: 9px;
  height: 5px;
  border-bottom: 2px solid #333333;
  border-radius: 0 0 12px 12px;
}

.group-new-icon::before,
.group-new-icon::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  background: #333333;
  transform: translate(-50%, -50%);
}

.group-new-icon::before {
  width: 26px;
  height: 2px;
}

.group-new-icon::after {
  width: 2px;
  height: 26px;
}

.group-thumb-img,
.group-thumb-placeholder {
  width: 32px;
  height: 32px;
  display: block;
  border-radius: var(--radius-lg);
  opacity: 0.92;
}

.group-thumb-img {
  object-fit: cover;
}

.group-thumb-placeholder {
  background: linear-gradient(135deg, #eeeeee, #ffffff);
  border: 1px dashed #cfcfcf;
}

.palette-area {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 10px 18px;
  background: #ffffff;
  user-select: none;
  -webkit-overflow-scrolling: touch;
}

.drop-overlay {
  position: absolute;
  inset: 8px;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px dashed #9f9f9f;
  border-radius: var(--radius-md);
  background: rgba(248, 248, 248, 0.92);
  color: #111111;
  font-size: var(--font-md);
  font-weight: 700;
  pointer-events: none;
}

.palette-area.is-drop-target .drop-overlay {
  display: flex;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  justify-content: center;
  gap: 8px;
}

.image-tile {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: #ffffff;
  cursor: copy;
  position: relative;
}

.image-tile.is-selected {
  border: 2px solid #888888;
}

.image-tile.is-selected::after {
  content: none;
}

.image-tile:focus-visible,
.group-tab:focus-visible,
.icon-button:focus-visible,
.text-button:focus-visible,
.menu-button:focus-visible {
  outline: 3px solid rgba(0, 0, 0, 0.18);
  outline-offset: 2px;
}

.image-tile img {
  width: calc(100% - 6px);
  height: calc(100% - 6px);
  display: block;
  image-rendering: auto;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.empty-state {
  display: none;
  min-height: 180px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  border: 1px dashed #d0d0d0;
  border-radius: var(--radius-md);
  background: var(--soft-raised);
  color: var(--muted);
  font-size: var(--font-md);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
  font-size: var(--font-md);
  font-weight: 700;
}

.empty-state span {
  font-size: var(--font-sm);
}

.empty-state.is-visible {
  display: flex;
}

.action-strip {
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: var(--font-sm);
  line-height: 1.35;
  text-align: left;
  overflow: hidden;
}

.status-text {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-text.is-success {
  color: inherit;
}

.status-text.is-error {
  color: var(--coral);
}

.attach-button,
.move-selection-button,
.manage-button,
.delete-selection-button {
  min-height: var(--control-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: #ffffff;
  color: #111111;
  cursor: pointer;
  font-size: var(--font-md);
  font-weight: 700;
  padding: 0 12px;
  white-space: nowrap;
}

.attach-button {
  gap: 8px;
}

.attach-button::before {
  content: "+";
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #111111;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

.delete-selection-button {
  border-color: rgba(227, 93, 79, 0.34);
  background: #ffffff;
  color: var(--coral);
}

.move-selection-button {
  border-color: var(--line-strong);
  background: #ffffff;
  color: #111111;
}

.manage-button {
  min-width: 58px;
}

.move-selection-button[hidden],
.delete-selection-button[hidden] {
  display: none;
}

.page-footer {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  padding: 7px 12px;
  border-top: 1px solid var(--line);
  background: var(--soft-raised);
  color: var(--subtle);
  font-size: var(--font-xs);
  font-weight: 600;
  letter-spacing: 0;
}

.footer-link {
  color: inherit;
  text-decoration: none;
}

.footer-link:hover {
  color: var(--ink);
  text-decoration: underline;
}

.crop-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.crop-modal.is-visible {
  display: flex;
}

.context-menu {
  position: fixed;
  z-index: 70;
  display: none;
  min-width: 174px;
  max-width: 240px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.context-menu.is-visible {
  display: block;
}

.manual-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(29, 37, 40, 0.48);
  padding: 16px;
}

.manual-modal.is-visible {
  display: flex;
}

.manual-dialog {
  width: min(360px, 100%);
  max-height: calc(100dvh - 32px);
  border-radius: var(--radius-md);
  background: #ffffff;
  box-shadow: var(--shadow);
  overflow-y: auto;
}

.manual-header {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.manual-header h2 {
  margin: 0;
  font-size: var(--font-lg);
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0;
}

.manual-graphic {
  padding: 18px 14px;
}

.manual-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 8px 0;
}

.manual-image,
.manual-group-thumb {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  background: #222222;
  box-shadow: inset 0 0 0 4px #ffffff, 0 0 0 1px var(--line);
}

.manual-image.alt {
  background: #e35d4f;
}

.manual-image.is-selected {
  outline: 3px solid rgba(0, 0, 0, 0.16);
}

.manual-arrow {
  color: var(--muted);
  font-weight: 700;
}

.manual-new-group {
  height: var(--control-height);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: #ffffff;
  color: #111111;
  font-size: var(--font-md);
  font-weight: 700;
}

.manual-group-thumb {
  width: 36px;
  height: 36px;
}

.manual-caption {
  color: var(--muted);
  font-size: var(--font-sm);
}

.menu-label {
  padding: 7px 9px 5px;
  color: var(--muted);
  font-size: var(--font-sm);
}

.menu-button {
  width: 100%;
  min-height: var(--control-height);
  display: block;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  padding: 7px 9px;
  font-size: var(--font-md);
}

.menu-button.danger {
  color: var(--coral);
}

.menu-separator {
  height: 1px;
  margin: 6px 4px;
  background: var(--line);
}

.crop-modal {
  background: rgba(29, 37, 40, 0.48);
  padding: 16px;
}

.crop-dialog {
  width: min(390px, 100%);
  max-height: calc(100dvh - 32px);
  border-radius: var(--radius-md);
  background: #ffffff;
  box-shadow: var(--shadow);
  overflow-y: auto;
}

.crop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.crop-header h2 {
  margin: 0;
  font-size: var(--font-lg);
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0;
}

.crop-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: var(--font-sm);
}

.crop-canvas {
  display: block;
  max-width: calc(100% - 24px);
  max-height: 48vh;
  margin: 14px auto 10px;
  border-radius: var(--radius-md);
  background: #20282a;
  touch-action: none;
}

.resize-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 12px 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #f7f8f8;
}

.resize-panel > span {
  color: var(--muted);
  font-size: var(--font-sm);
  white-space: nowrap;
}

.size-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(54px, 1fr));
  gap: 4px;
  flex: 1;
}

.size-options label {
  min-width: 0;
}

.size-options input {
  position: fixed;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.size-options span {
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--muted);
  font-size: var(--font-sm);
  font-weight: 700;
  cursor: pointer;
}

.size-options input:checked + span {
  border-color: #111111;
  background: var(--soft);
  color: #000000;
}

.size-options input:focus-visible + span {
  outline: 3px solid rgba(0, 0, 0, 0.18);
  outline-offset: 2px;
}

.crop-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.text-button {
  min-width: 76px;
  min-height: var(--control-height);
  border: 1px solid #111111;
  border-radius: var(--radius-md);
  background: #111111;
  color: #ffffff;
  cursor: pointer;
  font-size: var(--font-md);
  font-weight: 700;
}

.text-button:hover {
  background: #333333;
}

.text-button.quiet {
  border-color: var(--line);
  background: #ffffff;
  color: var(--muted);
  font-weight: 600;
}

.text-button.quiet:hover {
  background: var(--soft);
}

.visually-hidden {
  position: fixed;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 319px) {
  .top-bar {
    min-height: 88px;
    padding: 14px 14px 13px;
  }

  .chat-title-row {
    gap: 8px;
  }

  .message-time {
    font-size: var(--font-sm);
  }

  .title-bubble {
    min-height: 50px;
    padding: 12px 16px;
    border-radius: 16px;
  }

  .top-bar h1 {
    font-size: 20px;
  }

  .action-strip {
    padding-inline: 8px;
  }

  .group-strip {
    padding-inline: 8px;
  }

  .group-list {
    gap: 8px;
  }

  .image-grid {
    gap: 7px;
  }
}
