:root {
      --bg: #f5f7fb;
      --panel: #ffffff;
      --panel-soft: #f3f7ff;
      --input-bg: #f9fbff;
      --comment-bg: #f7faff;
      --main: #4f8cff;
      --main-dark: #3a75ea;
      --line: #dfe8f7;
      --text: #223146;
      --muted: #73839d;
      --danger: #e15d5d;
      --text-on-main: #ffffff;
      --text-on-danger: #ffffff;
      --shadow: 0 10px 24px rgba(31, 65, 120, 0.12);
    }

    * { box-sizing: border-box; }

    html, body {
      margin: 0;
      padding: 0;
      -webkit-font-smoothing: antialiased;
      -webkit-tap-highlight-color: transparent;
      touch-action: manipulation;
    }

    body {
      font-family: "Noto Sans JP", "Hiragino Maru Gothic Pro", "Yu Gothic Medium", "Segoe UI", sans-serif;
      background: linear-gradient(180deg, #edf3ff 0%, #f5f7fb 100%);
      color: var(--text);
      font-size: clamp(14px, 2vw, 16px);
      line-height: 1.7;
      font-weight: 400;
      letter-spacing: 0.02em;
    }

    h1, h2, h3, h4, h5, h6 {
      font-family: "Noto Sans JP", "Hiragino Maru Gothic Pro", "Yu Gothic Medium", "Segoe UI", sans-serif;
      font-weight: 500;
      letter-spacing: 0.03em;
      line-height: 1.4;
    }

    h1 {
      font-size: clamp(1.5rem, 3vw, 2rem);
      font-weight: 600;
    }

    h2 {
      font-size: clamp(1.3rem, 2.5vw, 1.6rem);
      font-weight: 550;
    }

    h3 {
      font-size: clamp(1.1rem, 2vw, 1.3rem);
      font-weight: 500;
    }

    .container {
      max-width: 760px;
      margin: 0 auto;
      padding: clamp(12px, 3vw, 24px) clamp(12px, 3vw, 16px) 60px;
    }

    @supports (padding: max(0px)) {
      .container {
        padding-left: max(clamp(12px, 3vw, 16px), env(safe-area-inset-left));
        padding-right: max(clamp(12px, 3vw, 16px), env(safe-area-inset-right));
      }
    }

    .card {
      background: var(--panel);
      border: 1px solid var(--line);
      border-radius: 18px;
      box-shadow: var(--shadow);
      padding: clamp(14px, 4vw, 18px);
      margin-bottom: clamp(12px, 3vw, 18px);
      transition: box-shadow 0.2s ease;
    }

    h1 {
      margin: 0 0 18px;
      font-size: clamp(1.6rem, 4vw, 2.5rem);
      text-align: center;
      color: var(--main-dark);
    }

    .screen {
      display: none;
    }

    .screen.active {
      display: block;
    }

    .screen.maintenance-hidden {
      display: none;
    }

    .form-row {
      display: flex;
      gap: clamp(8px, 2vw, 10px);
      flex-wrap: wrap;
    }

    .thread-create-row {
      display: flex;
      gap: clamp(8px, 2vw, 10px);
      align-items: flex-start;
      flex-wrap: wrap;
    }

    .thread-create-row form {
      flex: 1;
      min-width: 200px;
    }

    .thread-list-button {
      white-space: nowrap;
      flex: 0 0 auto;
      min-width: 120px;
    }

    dialog {
      width: min(680px, calc(100% - clamp(16px, 4vw, 32px)));
      max-height: 85vh;
      padding: 0;
      border: 1px solid var(--line);
      border-radius: 18px;
      box-shadow: var(--shadow);
      color: var(--text);
      animation: slideUp 0.3s ease;
    }

    @keyframes slideUp {
      from {
        opacity: 0;
        transform: translateY(20px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }

    dialog::backdrop {
      background: rgba(20, 35, 60, 0.45);
    }

    .thread-dialog-content {
      padding: clamp(14px, 4vw, 18px);
    }

    .auth-dialog {
      width: min(420px, calc(100% - clamp(20px, 5vw, 32px)));
      border: 1px solid var(--line);
      border-radius: 18px;
      box-shadow: var(--shadow);
      background: var(--panel);
      color: var(--text);
      padding: 0;
    }

    .auth-dialog::backdrop {
      background: rgba(20, 35, 60, 0.45);
    }

    .auth-dialog-form {
      display: grid;
      gap: 12px;
    }

    .auth-field {
      display: grid;
      gap: 6px;
      margin-bottom: 0;
      font-size: 0.85rem;
      font-weight: 700;
      color: var(--text);
    }

    .auth-field input {
      margin-bottom: 0;
    }

    .auth-dialog-divider {
      border-top: 1px solid var(--line);
      padding-top: 14px;
      text-align: center;
    }

    .auth-dialog-divider p {
      margin: 0 0 10px;
      font-weight: 700;
      font-size: 0.85rem;
      color: var(--muted);
    }

    .auth-dialog-actions {
      display: flex;
      gap: 10px;
      flex-wrap: wrap;
      margin-top: 2px;
    }

    .auth-dialog-actions button {
      flex: 1 1 140px;
    }

    .thread-dialog-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: clamp(8px, 2vw, 12px);
      margin-bottom: clamp(10px, 2vw, 12px);
    }

    .thread-dialog-header h2 {
      margin: 0;
      font-size: clamp(1.1rem, 3vw, 1.3rem);
    }

    .close-dialog-button {
      padding: clamp(8px, 2vw, 10px) clamp(10px, 2.5vw, 14px);
      min-height: 44px;
      min-width: 44px;
    }

    .dialog-thread-list {
      max-height: 50vh;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
    }

    @media (max-width: 600px) {
      .thread-create-row {
        display: block;
      }

      .thread-list-button {
        width: 100%;
      }
    }

    input, textarea, button {
      font: inherit;
      -webkit-appearance: none;
      appearance: none;
    }

    input[type="checkbox"],
    input[type="radio"] {
      -webkit-appearance: auto;
      appearance: auto;
      width: 18px;
      height: 18px;
      margin: 0;
      accent-color: var(--main);
    }

    input, textarea {
      width: 100%;
      border: 1px solid var(--line);
      background: var(--input-bg);
      border-radius: 12px;
      padding: clamp(10px, 2.5vw, 14px);
      margin-bottom: clamp(8px, 2vw, 12px);
      color: var(--text);
      font-size: clamp(14px, 2vw, 16px);
      transition: border-color 0.2s ease, background-color 0.2s ease;
    }

    input:focus, textarea:focus {
      border-color: var(--main);
      background-color: var(--panel);
      outline: none;
    }

    textarea {
      min-height: clamp(80px, 25vw, 120px);
      resize: vertical;
    }

    button {
      border: none;
      border-radius: 12px;
      padding: clamp(10px, 2.5vw, 14px) clamp(14px, 3vw, 18px);
      cursor: pointer;
      transition: all 0.2s ease;
      font-weight: 700;
      font-size: clamp(14px, 2vw, 16px);
      min-height: 44px;
      min-width: 44px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      touch-action: manipulation;
      user-select: none;
    }

    button:active {
      transform: scale(0.98);
    }

    .primary {
      background: var(--main);
      color: var(--text-on-main);
    }

    .primary:hover { 
      background: var(--main-dark);
    }

    .primary:active {
      background: #2a5bd1;
    }

    .secondary {
      background: var(--panel-soft);
      color: var(--text);
    }

    .secondary:hover {
      background: var(--line);
    }

    .secondary:active {
      background: var(--line);
    }

    .danger {
      background: var(--danger);
      color: var(--text-on-danger);
    }

    .danger:hover {
      background: #d94747;
    }

    .danger:active {
      background: #c93636;
    }

    .thread-item, .post-item {
      border: 1px solid var(--line);
      border-radius: 16px;
      padding: clamp(12px, 3vw, 16px);
      margin-bottom: clamp(8px, 2vw, 10px);
      background: var(--panel);
      transition: all 0.2s ease;
      box-shadow: 0 4px 12px rgba(31, 65, 120, 0.04);
    }

    .thread-item {
      display: grid;
      gap: clamp(6px, 1.5vw, 8px);
      cursor: pointer;
      -webkit-user-select: none;
      user-select: none;
    }

    .thread-item:active {
      background: var(--panel-soft);
      box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    }

    .post-item:active {
      background: var(--panel-soft);
    }

    .thread-head {
      display: flex;
      justify-content: space-between;
      gap: clamp(8px, 2vw, 10px);
      align-items: center;
      flex-wrap: wrap;
    }

    .thread-title {
      font-weight: 700;
      font-size: clamp(1rem, 3vw, 1.1rem);
      flex: 1;
      word-break: break-word;
    }

    .muted {
      color: var(--muted);
      font-size: clamp(0.75rem, 1.5vw, 0.9rem);
      line-height: 1.4;
    }

    .status {
      margin-top: 8px;
      color: var(--muted);
      font-size: 0.85rem;
      min-height: 18px;
    }

    .notice-bar {
      width: 100%;
      max-width: 760px;
      margin: 0 auto 12px;
      padding: 12px 16px;
      border-radius: 12px;
      font-weight: 700;
      display: none;
      box-shadow: var(--shadow);
    }

    .notice-bar.active {
      display: block;
    }

    .notice-bar.maintenance {
      background: #fff1f1;
      color: #a33434;
      border: 1px solid #f2b5b5;
    }

    .notice-bar.update {
      background: #fff8dc;
      color: #7a5b00;
      border: 1px solid #f3d87c;
    }

    .notice-bar.info {
      background: #edf6ff;
      color: #205da5;
      border: 1px solid #b8d7ff;
    }

    .mail-area {
      display: grid;
      gap: 10px;
    }

    .mail-header {
      margin: 0;
      font-size: clamp(1.1rem, 3vw, 1.5rem);
      color: var(--main-dark);
    }

    .info-text {
      margin: 0;
      color: var(--muted);
      font-size: 0.85rem;
      line-height: 1.5;
    }

    .mail-field {
      display: grid;
      gap: 6px;
      margin: 0;
      font-weight: 700;
      color: var(--text);
    }

    .mail-area input,
    .mail-area textarea {
      margin-bottom: 0;
    }

    .mail-btn {
      width: 100%;
      max-width: 260px;
      margin-top: 4px;
    }

    .mail-btn:disabled {
      opacity: 0.7;
      cursor: wait;
    }

    .theme-settings-panel {
      margin-top: 12px;
      padding-top: 12px;
      border-top: 1px solid var(--line);
    }

    .theme-settings-row {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      align-items: center;
    }

    .theme-preset-row {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin-top: 8px;
    }

    .theme-preset-button {
      background: var(--panel-soft);
      color: var(--text);
      border: 1px solid var(--line);
      padding: 8px 12px;
      min-height: 36px;
      font-size: 0.8rem;
      font-weight: 600;
      opacity: 0.96;
    }

    .theme-color-group {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      background: var(--panel-soft);
      border: 1px solid var(--line);
      border-radius: 10px;
      padding: 6px 8px;
      font-size: 0.75rem;
      color: var(--text);
      font-weight: 600;
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
    }

    .theme-color-group span {
      color: var(--text);
      opacity: 0.92;
    }

    .theme-color-group input[type="color"] {
      width: 40px;
      height: 28px;
      min-width: 40px;
      border: none;
      background: none;
      padding: 0;
      margin: 0;
      border-radius: 8px;
      overflow: hidden;
    }

    .admin-panel {
      display: none;
    }

    .admin-panel.visible {
      display: block;
    }

    .admin-panel.collapsed .admin-tabs,
    .admin-panel.collapsed .admin-tab-content {
      display: none;
    }

    .admin-panel-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 10px;
    }

    .admin-toggle-button {
      padding: 6px 10px;
      min-height: 36px;
      min-width: 36px;
      background: transparent;
      color: var(--main);
      border: 1px solid var(--line);
      border-radius: 8px;
      cursor: pointer;
      font-size: 1.2rem;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.2s ease;
    }

    .admin-toggle-button:hover {
      background: #edf4ff;
      border-color: var(--main);
    }

    .admin-toggle-button:active {
      transform: scale(0.95);
    }

    .admin-tabs {
      display: flex;
      gap: clamp(8px, 2vw, 10px);
      margin-bottom: clamp(12px, 3vw, 16px);
      border-bottom: 2px solid var(--line);
    }

    .admin-tab-button {
      padding: clamp(8px, 2vw, 10px) clamp(10px, 2.5vw, 14px);
      background: none;
      border: none;
      border-bottom: 3px solid transparent;
      color: var(--muted);
      font-weight: 700;
      cursor: pointer;
      transition: all 0.2s ease;
      font-size: clamp(13px, 2vw, 15px);
    }

    .admin-tab-button:hover {
      color: var(--main);
    }

    .admin-tab-button.active {
      color: var(--main);
      border-bottom-color: var(--main);
    }

    .admin-tab-content {
      display: none;
    }

    .admin-tab-content.active {
      display: block;
    }

    .admin-label-badge {
      display: inline-block;
      background: #ffe0e0;
      color: var(--danger);
      padding: clamp(3px, 1vw, 5px) clamp(8px, 2vw, 10px);
      border-radius: 8px;
      font-size: clamp(0.65rem, 1.2vw, 0.8rem);
      font-weight: 700;
      margin-left: clamp(4px, 1vw, 6px);
    }

    .switch-row {
      display: flex;
      align-items: center;
      gap: 10px;
      margin-bottom: 12px;
      font-weight: 700;
    }

    .switch-row input {
      width: auto;
      margin: 0;
    }

    .category-row {
      display: grid;
      gap: 8px;
      margin-bottom: 14px;
    }

    .category-field {
      display: grid;
      gap: 6px;
      font-weight: 700;
      color: var(--text);
    }

    .category-select,
    .category-custom-input {
      width: 100%;
      margin: 0;
      border: 1px solid var(--line);
      background: linear-gradient(180deg, var(--panel) 0%, var(--panel-soft) 100%);
      border-radius: 12px;
      padding: clamp(10px, 2.5vw, 14px);
      color: var(--text);
      font-size: clamp(14px, 2vw, 16px);
      font-weight: 600;
      box-shadow: inset 0 1px 2px rgba(31, 65, 120, 0.04);
      transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
      appearance: auto;
      -webkit-appearance: menulist;
      color-scheme: light dark;
    }

    .category-select option,
    .category-select optgroup {
      color: var(--text);
      background: var(--panel);
    }

    .category-select:focus,
    .category-custom-input:focus {
      border-color: var(--main);
      box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.12);
      outline: none;
    }

    .category-custom-row {
      display: none;
    }

    .category-custom-row.visible {
      display: block;
    }

    .thread-category-badge {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      border-radius: 999px;
      padding: 4px 10px;
      font-size: 0.74rem;
      font-weight: 700;
      white-space: nowrap;
      vertical-align: middle;
      margin-right: 8px;
      border: 1px solid transparent;
    }

    .thread-category-badge[data-category="雑談"] {
      background: rgba(34, 173, 95, 0.12);
      color: #1c7d4c;
      border-color: rgba(34, 173, 95, 0.2);
    }

    .thread-category-badge[data-category="質問"] {
      background: rgba(79, 140, 255, 0.12);
      color: #335fc9;
      border-color: rgba(79, 140, 255, 0.22);
    }

    .thread-category-badge[data-category="情報"] {
      background: rgba(255, 181, 55, 0.12);
      color: #a66e00;
      border-color: rgba(255, 181, 55, 0.24);
    }

    .thread-category-badge[data-category="相談"] {
      background: rgba(184, 93, 191, 0.12);
      color: #8a3d9b;
      border-color: rgba(184, 93, 191, 0.24);
    }

    .thread-category-badge[data-category="募集"] {
      background: rgba(232, 91, 91, 0.12);
      color: #c54841;
      border-color: rgba(232, 91, 91, 0.24);
    }

    .thread-category-badge[data-category="ゲーム"] {
      background: rgba(125, 92, 214, 0.12);
      color: #6f49c7;
      border-color: rgba(125, 92, 214, 0.24);
    }

    .thread-category-badge[data-category="その他"] {
      background: rgba(120, 131, 148, 0.12);
      color: #4d5a6d;
      border-color: rgba(120, 131, 148, 0.2);
    }

    .thread-category-badge[data-category^="その他:"] {
      background: rgba(120, 131, 148, 0.12);
      color: #4d5a6d;
      border-color: rgba(120, 131, 148, 0.2);
    }

    .icon-settings-panel {
      display: none;
      margin-top: 12px;
      padding-top: 12px;
      border-top: 1px solid var(--line);
      gap: 10px;
    }

    .icon-settings-panel.visible {
      display: block;
    }

    .icon-settings-row {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      align-items: center;
    }

    .icon-upload-button {
      padding: 8px 12px;
      border-radius: 10px;
      border: 1px solid var(--line);
      background: #f5f8ff;
      color: var(--main-dark);
      font-size: 0.82rem;
      font-weight: 700;
      cursor: pointer;
      transition: all 0.2s ease;
    }

    .icon-upload-button:hover {
      background: #edf4ff;
      border-color: #cfe0ff;
    }

    .icon-preview {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 42px;
      height: 42px;
      border-radius: 50%;
      background: linear-gradient(135deg, #dfeaff, #f5f8ff);
      border: 2px solid var(--line);
      overflow: hidden;
      font-size: 1.1rem;
      font-weight: 700;
      color: var(--text);
      flex-shrink: 0;
    }

    .icon-preview img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      border-radius: 50%;
      display: block;
    }

    .post-author-row {
      display: flex;
      align-items: center;
      gap: 8px;
      min-height: 24px;
    }

    .post-author-avatar {
      width: 28px;
      height: 28px;
      border-radius: 50%;
      border: 1px solid var(--line);
      display: inline-flex;
      align-items: center;
      justify-content: center;
      overflow: hidden;
      background: linear-gradient(135deg, #dfeaff, #f5f8ff);
      font-size: 0.8rem;
      font-weight: 700;
      color: var(--text);
      flex-shrink: 0;
    }

    .post-author-avatar img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
      border-radius: 50%;
    }

    .meta {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: clamp(8px, 2vw, 10px);
      flex-wrap: wrap;
      font-size: clamp(0.85rem, 1.5vw, 0.95rem);
    }

    .post-number {
      color: var(--main-dark);
      font-weight: 700;
      font-size: inherit;
    }

    .admin-label {
      color: var(--danger);
      font-size: clamp(0.65rem, 1.2vw, 0.8rem);
      font-weight: 700;
      margin-left: clamp(4px, 1vw, 6px);
    }

    .comment-box {
      background: var(--comment-bg);
      border-left: 4px solid var(--main);
      padding: clamp(10px, 2.5vw, 14px);
      border-radius: 12px;
      white-space: pre-wrap;
      word-break: break-word;
      line-height: 1.7;
      font-size: clamp(14px, 2vw, 16px);
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.3);
    }

    .quote-link {
      display: inline-block;
      margin: 0 2px;
      color: #d43838;
      font-weight: 800;
      text-decoration: none;
      cursor: pointer;
      transition: opacity 0.15s ease;
    }

    .quote-link:hover,
    .quote-link:focus-visible {
      opacity: 0.8;
      text-decoration: underline;
    }

    .quote-link-missing {
      color: #7f8896;
      opacity: 0.9;
      cursor: default;
    }

    .url-link {
      color: var(--main);
      text-decoration: underline;
      word-break: break-all;
    }

    .url-link:hover {
      color: var(--main-dark);
      text-decoration: none;
    }

    .reply-button {
      background: #fff0f0;
      border: 1px solid #ffd0d0;
      color: #c73e3e;
      border-radius: 999px;
      padding: 4px 8px;
      min-height: 30px;
      font-weight: 800;
      font-size: 0.78rem;
      cursor: pointer;
      transition: all 0.15s ease;
    }

    .reply-button:hover,
    .reply-button:focus-visible {
      background: #ffe7e7;
      transform: translateY(-1px);
    }

    .post-highlight {
      animation: quote-flash 1.5s ease;
      border: 1px solid #ffcdcd;
      box-shadow: 0 0 0 3px rgba(212, 56, 56, 0.12);
    }

    @keyframes quote-flash {
      0% { background: rgba(255, 230, 230, 0.8); }
      40% { background: rgba(255, 242, 242, 1); }
      100% { background: transparent; }
    }

    .comment-image {
      display: block;
      max-width: 100%;
      max-height: 340px;
      margin-top: clamp(10px, 2vw, 14px);
      border-radius: 12px;
      border: 1px solid var(--line);
      object-fit: cover;
      touch-action: manipulation;
      cursor: pointer;
    }

    .comment-image-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
      gap: 8px;
      margin-top: clamp(10px, 2vw, 14px);
    }

    .comment-image-grid-item {
      width: 100%;
      aspect-ratio: 1;
      border-radius: 12px;
      overflow: hidden;
      border: 1px solid var(--line);
      background: rgba(0, 0, 0, 0.04);
      cursor: pointer;
      touch-action: manipulation;
    }

    .comment-image-grid-item img {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .drop-zone {
      border: 2px dashed var(--line);
      background: #f9fbff;
      border-radius: 12px;
      padding: clamp(12px, 3vw, 16px);
      margin-bottom: clamp(10px, 2vw, 12px);
      color: var(--muted);
      cursor: pointer;
      transition: all 0.2s ease;
      text-align: center;
      font-size: clamp(14px, 2vw, 16px);
      touch-action: manipulation;
      user-select: none;
      -webkit-user-select: none;
    }

    .drop-zone:active {
      border-color: var(--main);
      background: #edf4ff;
      color: var(--main-dark);
    }

    .drop-zone.dragover {
      border-color: var(--main);
      background: #edf4ff;
      color: var(--main-dark);
      transform: scale(1.02);
    }

    .hidden-file-input {
      display: none;
    }

    .is-hidden { display: none; }
    .custom-icon-input { max-width: 120px; margin: 0; }
    .custom-icon-color { width: 52px; height: 42px; padding: 4px; margin: 0; min-width: 52px; }
    .full-width-button { width: 100%; }
    .no-margin { margin: 0; }
    .admin-section-heading { margin: 0 0 12px; color: var(--main-dark); }
    .announcement-row { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
    .announcement-label { display: flex; align-items: center; gap: 8px; margin: 0; cursor: pointer; }
    .announcement-checkbox { width: 18px; height: 18px; margin: 0; cursor: pointer; flex-shrink: 0; }
    .admin-submit-row .flex-button, .form-row .flex-button { flex: 1; }
    .survey-create-section { border-top: 2px solid var(--line); padding-top: 16px; margin-top: 16px; }
    .survey-description { min-height: 60px; }
    .survey-options-container { margin-bottom: 12px; }
    .survey-options-label { font-weight: 700; display: block; margin-bottom: 8px; }
    .survey-option-add-button { width: 100%; margin-bottom: 10px; }
    .survey-heading { margin: 0 0 12px; color: var(--main-dark); }
    .survey-list { display: grid; gap: 10px; }
    .survey-dialog-content { padding: 0; }
    .current-thread-heading { margin: 16px 0 8px; }

    .preview-box {
      display: none;
      margin-top: clamp(8px, 2vw, 10px);
      animation: fadeIn 0.3s ease;
    }

    @keyframes fadeIn {
      from { opacity: 0; }
      to { opacity: 1; }
    }

    .preview-box.has-image {
      display: block;
    }

    .image-preview-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
      gap: 8px;
      margin-bottom: clamp(8px, 2vw, 10px);
    }

    .image-preview-thumb {
      width: 100%;
      aspect-ratio: 1;
      object-fit: cover;
      border-radius: 10px;
      border: 1px solid var(--line);
      background: #eef4ff;
      display: block;
    }

    .preview-image {
      display: block;
      max-width: 100%;
      max-height: 240px;
      border-radius: 12px;
      border: 1px solid var(--line);
      object-fit: cover;
      margin: 0 auto clamp(8px, 2vw, 10px);
      touch-action: manipulation;
    }

    .image-viewer-modal {
      position: fixed;
      inset: 0;
      display: none;
      align-items: center;
      justify-content: center;
      background: rgba(15, 22, 35, 0.8);
      padding: 24px;
      z-index: 2000;
    }

    .image-viewer-modal.visible {
      display: flex;
    }

    .image-viewer-content {
      position: relative;
      max-width: min(92vw, 980px);
      max-height: 90vh;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .image-viewer-image {
      display: block;
      max-width: min(92vw, 980px);
      max-height: 82vh;
      border-radius: 16px;
      border: 1px solid rgba(255, 255, 255, 0.25);
      background: rgba(255, 255, 255, 0.15);
      object-fit: contain;
      box-shadow: 0 18px 36px rgba(0, 0, 0, 0.25);
    }

    .image-viewer-close {
      position: absolute;
      top: -12px;
      right: -12px;
      width: 38px;
      height: 38px;
      border-radius: 999px;
      border: none;
      background: rgba(255, 255, 255, 0.9);
      color: var(--text);
      font-size: 1.3rem;
      cursor: pointer;
    }

    .delete-button {
      background: transparent;
      color: var(--danger);
      border: 1px solid var(--danger);
      padding: clamp(6px, 1.5vw, 8px) clamp(10px, 2vw, 12px);
      border-radius: 10px;
      font-size: clamp(0.75rem, 1.5vw, 0.9rem);
      font-weight: 700;
      min-height: 40px;
      transition: all 0.2s ease;
      display: inline-flex;
      align-items: center;
      gap: 4px;
    }

    .delete-button:hover {
      background: rgba(225, 93, 93, 0.1);
      transform: translateY(-1px);
      box-shadow: 0 2px 8px rgba(225, 93, 93, 0.2);
    }

    .delete-button:active {
      background: rgba(225, 93, 93, 0.2);
      transform: translateY(0);
    }

    .auth-box {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: clamp(10px, 2vw, 12px);
      flex-wrap: wrap;
      font-size: clamp(0.9rem, 2vw, 1rem);
    }

    .auth-actions {
      display: flex;
      gap: clamp(6px, 1.5vw, 8px);
      flex-wrap: wrap;
    }

    .top-controls.hidden {
      display: none;
    }

    @media (max-width: 768px) {
      h1 {
        margin: 0 0 clamp(12px, 3vw, 18px);
      }

      .thread-create-row {
        flex-direction: column;
      }

      .thread-create-row form {
        min-width: auto;
      }

      .thread-list-button {
        width: 100%;
        min-width: auto;
      }

      .auth-box {
        flex-direction: column;
        align-items: stretch;
      }

      .auth-actions {
        justify-content: stretch;
      }

      .auth-actions button {
        flex: 1;
      }
    }

    @media (max-width: 600px) {
      .thread-head, .meta {
        flex-direction: column;
        align-items: flex-start;
      }

      .container {
        padding-bottom: 80px;
      }

      dialog {
        max-height: 90vh;
      }

      .form-row button {
        flex: 1;
        min-width: auto;
      }
    }

    @media (max-width: 360px) {
      .container {
        padding: 10px 8px 80px 8px;
      }

      .card {
        padding: 12px;
        margin-bottom: 10px;
      }

      button {
        padding: 10px 12px;
        min-height: 42px;
      }
    }
    /* dialog内のコンテンツをスクロール可能にする例 */
dialog {
  max-height: 85vh;
  overflow-y: auto;
}
